From e1b548d73be41242745e3088f8b8140b7b3db92d Mon Sep 17 00:00:00 2001 From: julianajlk Date: Tue, 9 Apr 2024 09:21:00 -0400 Subject: [PATCH] test: Add more tests --- src/payment/AlertCodeMessages.test.jsx | 26 +++++++++++++++++++ .../AlertCodeMessages.test.jsx.snap | 12 +++++++++ .../CardHolderInformation.test.jsx | 2 +- src/payment/data/redux.test.js | 21 +++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/payment/AlertCodeMessages.test.jsx b/src/payment/AlertCodeMessages.test.jsx index 37fbe2ebf..43758389e 100644 --- a/src/payment/AlertCodeMessages.test.jsx +++ b/src/payment/AlertCodeMessages.test.jsx @@ -8,6 +8,8 @@ import { SingleEnrollmentCodeWarning, EnrollmentCodeQuantityUpdated, TransactionDeclined, + DynamicPaymentMethodsNotCompatibleError, + BasketChangedError, } from './AlertCodeMessages'; const mockStore = configureMockStore(); @@ -51,3 +53,27 @@ describe('TransactionDeclined', () => { expect(tree).toMatchSnapshot(); }); }); + +describe('DynamicPaymentMethodsNotCompatibleError', () => { + it('should render with values', () => { + const component = ( + + + + ); + const { container: tree } = render(component); + expect(tree).toMatchSnapshot(); + }); +}); + +describe('BasketChangedError', () => { + it('should render with values', () => { + const component = ( + + + + ); + const { container: tree } = render(component); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/src/payment/__snapshots__/AlertCodeMessages.test.jsx.snap b/src/payment/__snapshots__/AlertCodeMessages.test.jsx.snap index 09d6ffd77..39ca5ab23 100644 --- a/src/payment/__snapshots__/AlertCodeMessages.test.jsx.snap +++ b/src/payment/__snapshots__/AlertCodeMessages.test.jsx.snap @@ -1,5 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`BasketChangedError should render with values 1`] = ` +
+ Your cart has changed since navigating to this page. Please reload the page and verify the product you are purchasing. +
+`; + +exports[`DynamicPaymentMethodsNotCompatibleError should render with values 1`] = ` +
+ The payment method you have selected is not available in your country. Please select another payment method. +
+`; + exports[`EnrollmentCodeQuantityUpdated should render with values 1`] = `
diff --git a/src/payment/checkout/payment-form/CardHolderInformation.test.jsx b/src/payment/checkout/payment-form/CardHolderInformation.test.jsx index 07481b214..2677badf3 100644 --- a/src/payment/checkout/payment-form/CardHolderInformation.test.jsx +++ b/src/payment/checkout/payment-form/CardHolderInformation.test.jsx @@ -74,7 +74,7 @@ describe('', () => { fireEvent.change(screen.getByLabelText('Country (required)'), { target: { value: 'US' } }); expect(getCountryStatesMap).toHaveBeenCalledWith('US'); - expect(isPostalCodeRequired).toHaveBeenCalledWith('US'); + expect(isPostalCodeRequired).toHaveBeenCalledWith('US', false); // DPM enabled added to the call }); }); describe('purchasedForOrganization field', () => { diff --git a/src/payment/data/redux.test.js b/src/payment/data/redux.test.js index d1168905b..356ed36d5 100644 --- a/src/payment/data/redux.test.js +++ b/src/payment/data/redux.test.js @@ -137,6 +137,27 @@ describe('redux tests', () => { isRedirect: true, // this is also now true. }); }); + + it('is a Stripe dynamic payment methods redirect', () => { + global.history.pushState({}, '', '?payment_intent=pi_123dummy'); + store = createStore(combineReducers({ + payment: reducer, + })); + + const result = paymentSelector(store.getState()); + expect(result).toEqual({ + loading: true, + loaded: false, + submitting: false, + redirect: false, // This is a different kind of redirect, so still false. + products: [], + isCouponRedeemRedirect: false, + isBasketProcessing: false, + isEmpty: false, + isPaymentRedirect: true, // this is now true + isRedirect: false, + }); + }); }); });