Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
};
Loading