Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements to WooPay test coverage #9671

Merged
merged 10 commits into from
Nov 13, 2024
35 changes: 35 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,35 @@
/**
* External dependencies
*/
import { test, expect, Page } from '@playwright/test';

Check warning on line 4 in tests/e2e-pw/specs/merchant/woopay-setup.spec.ts

View workflow job for this annotation

GitHub Actions / JS linting

'expect' is defined but never used
/**
* Internal dependencies
*/
import { getMerchant, getShopper } from '../../utils/helpers';
import { activateWooPay, deactivateWooPay } from '../../utils/merchant';

test.describe( 'WooPay setup', () => {
let merchantPage: Page;
let shopperPage: Page;
let wasWooPayEnabled: boolean;

test.beforeAll( async ( { browser } ) => {
shopperPage = ( await getShopper( browser ) ).shopperPage;

Check warning on line 17 in tests/e2e-pw/specs/merchant/woopay-setup.spec.ts

View workflow job for this annotation

GitHub Actions / JS linting

'shopperPage' is assigned a value but never used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Removed in 9e8355e

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