Skip to content

Commit

Permalink
Minor improvements to WooPay test coverage (#9671)
Browse files Browse the repository at this point in the history
  • Loading branch information
malithsen authored Nov 13, 2024
1 parent 733734b commit dbcc4ba
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/fix-improve-woopay-test-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Minor improvements to automated tests around WooPay


Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
} ) );
Expand Down Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions client/settings/express-checkout/woopay-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const WooPayExpressCheckoutItem = (): React.ReactElement => {
) }
checked={ isWooPayEnabled }
onChange={ updateIsWooPayEnabled }
data-testid="woopay-toggle"
/>
) }
</div>
Expand Down
33 changes: 33 additions & 0 deletions tests/e2e-pw/specs/merchant/woopay-setup.spec.ts
Original file line number Diff line number Diff line change
@@ -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 );
} );
} );
28 changes: 28 additions & 0 deletions tests/e2e-pw/utils/merchant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};

0 comments on commit dbcc4ba

Please sign in to comment.