Skip to content

Commit

Permalink
chore: added test case to check if skus are stored in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
zubair-ce07 committed Apr 17, 2024
1 parent e7517bd commit 3c796a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/payment/checkout/Checkout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ describe('<Checkout />', () => {
expect(store.getActions().pop()).toEqual(submitPayment({ method: 'paypal' }));
});

it('should call submitPayment and store skus in localStorage when handleSubmitPayPal is called', async () => {
const paypalButton = await screen.findByTestId('PayPalButton');
fireEvent.click(paypalButton);

expect(store.getActions().pop()).toEqual(submitPayment({ method: 'paypal' }));
// Check if skus are stored in localStorage
const storedSkus = JSON.parse(localStorage.getItem('skus'));
expect(storedSkus.length).toBeGreaterThan(0);
});

// Apple Pay temporarily disabled per REV-927 - https://github.com/openedx/frontend-app-payment/pull/256

it('submits and tracks the payment form', () => {
Expand Down
17 changes: 17 additions & 0 deletions src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ mergeConfig({
APPLE_PAY_MERCHANT_CAPABILITIES: process.env.APPLE_PAY_MERCHANT_CAPABILITIES && process.env.APPLE_PAY_MERCHANT_CAPABILITIES.split(','),
WAFFLE_FLAGS: {},
});

const localStorageMock = jest.fn(() => {
let store = {};
return {
getItem: (key) => (store[key] || null),
setItem: (key, value) => {
store[key] = value.toString();
},
clear: () => {
store = {};
},
removeItem: (key) => {
delete store[key];
},
};
})();
Object.defineProperty(window, 'localStorage', { value: localStorageMock });

0 comments on commit 3c796a4

Please sign in to comment.