From 3c796a4e4f23cbbb2b80cda3db84eaa966e844b5 Mon Sep 17 00:00:00 2001 From: zubair-ce07 Date: Wed, 17 Apr 2024 21:44:18 +1000 Subject: [PATCH] chore: added test case to check if skus are stored in localstorage --- src/payment/checkout/Checkout.test.jsx | 10 ++++++++++ src/setupTest.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/payment/checkout/Checkout.test.jsx b/src/payment/checkout/Checkout.test.jsx index f153eda09..27d67dc77 100644 --- a/src/payment/checkout/Checkout.test.jsx +++ b/src/payment/checkout/Checkout.test.jsx @@ -103,6 +103,16 @@ describe('', () => { 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', () => { diff --git a/src/setupTest.js b/src/setupTest.js index 3a65fb810..5c61ce7dc 100755 --- a/src/setupTest.js +++ b/src/setupTest.js @@ -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 });