diff --git a/changelog/fix-improve-woopay-test-coverage b/changelog/fix-improve-woopay-test-coverage new file mode 100644 index 00000000000..001374c440a --- /dev/null +++ b/changelog/fix-improve-woopay-test-coverage @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Minor improvements to automated tests around WooPay + + diff --git a/client/components/woopay/save-user/test/checkout-page-save-user.test.js b/client/components/woopay/save-user/test/checkout-page-save-user.test.js index 9986e3868eb..a09b4249053 100644 --- a/client/components/woopay/save-user/test/checkout-page-save-user.test.js +++ b/client/components/woopay/save-user/test/checkout-page-save-user.test.js @@ -160,6 +160,11 @@ describe( 'CheckoutPageSaveUser', () => { 'Securely save my information for 1-click checkout' ) ).not.toBeChecked(); + expect( + screen.queryAllByLabelText( + 'Securely save my information for 1-click checkout' + ) + ).toHaveLength( 1 ); } ); it( 'should not render checkbox for saving WooPay user when user is already registered', () => { @@ -184,7 +189,7 @@ describe( 'CheckoutPageSaveUser', () => { ).not.toBeInTheDocument(); } ); - it( 'should render checkbox for saving WooPay user when selected payment method is not card', () => { + it( 'should not render checkbox for saving WooPay user when selected payment method is not card', () => { useSelectedPaymentMethod.mockImplementation( () => ( { isWCPayChosen: false, } ) ); @@ -235,6 +240,7 @@ describe( 'CheckoutPageSaveUser', () => { expect( label ).toBeChecked(); expect( screen.queryByTestId( 'save-user-form' ) ).toBeInTheDocument(); + expect( screen.getAllByTestId( 'save-user-form' ) ).toHaveLength( 1 ); } ); it( 'should not call `request` on classic checkout when checkbox is clicked', () => { diff --git a/client/settings/express-checkout/woopay-item.tsx b/client/settings/express-checkout/woopay-item.tsx index 910cd930dff..4232901b0ef 100644 --- a/client/settings/express-checkout/woopay-item.tsx +++ b/client/settings/express-checkout/woopay-item.tsx @@ -79,6 +79,7 @@ const WooPayExpressCheckoutItem = (): React.ReactElement => { ) } checked={ isWooPayEnabled } onChange={ updateIsWooPayEnabled } + data-testid="woopay-toggle" /> ) } diff --git a/tests/e2e-pw/specs/merchant/woopay-setup.spec.ts b/tests/e2e-pw/specs/merchant/woopay-setup.spec.ts new file mode 100644 index 00000000000..c36cdb135d0 --- /dev/null +++ b/tests/e2e-pw/specs/merchant/woopay-setup.spec.ts @@ -0,0 +1,33 @@ +/** + * External dependencies + */ +import { test, Page } from '@playwright/test'; +/** + * Internal dependencies + */ +import { getMerchant } from '../../utils/helpers'; +import { activateWooPay, deactivateWooPay } from '../../utils/merchant'; + +test.describe( 'WooPay setup', () => { + let merchantPage: Page; + let wasWooPayEnabled: boolean; + + test.beforeAll( async ( { browser } ) => { + merchantPage = ( await getMerchant( browser ) ).merchantPage; + wasWooPayEnabled = await activateWooPay( merchantPage ); + } ); + + test.afterAll( async () => { + if ( ! wasWooPayEnabled ) { + await deactivateWooPay( merchantPage ); + } + } ); + + test( 'can disable the WooPay feature', async () => { + await deactivateWooPay( merchantPage ); + } ); + + test( 'can enable the WooPay feature', async () => { + await activateWooPay( merchantPage ); + } ); +} ); diff --git a/tests/e2e-pw/utils/merchant.ts b/tests/e2e-pw/utils/merchant.ts index 2cbefa58615..d5908956359 100644 --- a/tests/e2e-pw/utils/merchant.ts +++ b/tests/e2e-pw/utils/merchant.ts @@ -250,3 +250,31 @@ export const disablePaymentMethods = async ( await saveWooPaymentsSettings( page ); }; + +export const isWooPayEnabled = async ( page: Page ) => { + await navigation.goToWooPaymentsSettings( page ); + + const checkboxTestId = 'woopay-toggle'; + const isEnabled = await page.getByTestId( checkboxTestId ).isChecked(); + + return isEnabled; +}; + +export const activateWooPay = async ( page: Page ) => { + await navigation.goToWooPaymentsSettings( page ); + + const checkboxTestId = 'woopay-toggle'; + const wasInitiallyEnabled = await isWooPayEnabled( page ); + + if ( ! wasInitiallyEnabled ) { + await page.getByTestId( checkboxTestId ).check(); + await saveWooPaymentsSettings( page ); + } + return wasInitiallyEnabled; +}; + +export const deactivateWooPay = async ( page: Page ) => { + await navigation.goToWooPaymentsSettings( page ); + await page.getByTestId( 'woopay-toggle' ).uncheck(); + await saveWooPaymentsSettings( page ); +};