Skip to content

Commit

Permalink
Refactoring of snackbar checks in Playwright e2e tests (#10218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepearson authored Jan 24, 2025
1 parent e69616a commit c08a83c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-10210-fix-saving-woopayments-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Refactoring of snackbar checks in Playwright e2e tests
45 changes: 29 additions & 16 deletions tests/e2e-pw/utils/merchant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,30 @@ const ensureSupportPhoneIsFilled = async ( page: Page ) => {
}
};

const expectSnackbarWithText = async (
page: Page,
expectedText: string,
timeout = 10000
) => {
await expect(
page.locator( '.components-snackbar__content', {
hasText: expectedText,
} )
).toBeVisible( {
timeout: timeout,
} );
};

export const saveWooPaymentsSettings = async ( page: Page ) => {
await ensureSupportPhoneIsFilled( page );

await page.getByRole( 'button', { name: 'Save changes' } ).click();
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
timeout: 10000,
} );
await expectSnackbarWithText( page, 'Settings saved.' );
};

export const saveMultiCurrencySettings = async ( page: Page ) => {
await page.getByRole( 'button', { name: 'Save changes' } ).click();
await expectSnackbarWithText( page, 'Currency settings updated.' );
};

export const isMulticurrencyEnabled = async ( page: Page ) => {
Expand Down Expand Up @@ -122,9 +139,7 @@ export const addMulticurrencyWidget = async ( page: Page ) => {
page.getByRole( 'button', { name: 'Update' } )
).toBeEnabled();
await page.getByRole( 'button', { name: 'Update' } ).click();
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
timeout: 10000,
} );
await expectSnackbarWithText( page, 'Widgets saved.' );
}
};

Expand Down Expand Up @@ -171,7 +186,9 @@ export const disableAllEnabledCurrencies = async ( page: Page ) => {
.first()
.click();

const snackbar = await page.getByLabel( 'Dismiss this notice' );
const snackbar = await page.locator( '.components-snackbar__content', {
hasText: 'Enabled currencies updated.',
} );

await expect( snackbar ).toBeVisible( { timeout: 10000 } );
await snackbar.click();
Expand All @@ -197,9 +214,7 @@ export const addCurrency = async ( page: Page, currencyCode: string ) => {
}

await page.getByRole( 'button', { name: 'Update selected' } ).click();
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
timeout: 10000,
} );
await expectSnackbarWithText( page, 'Enabled currencies updated.' );
await expect(
page.locator( `li.enabled-currency.${ currencyCode.toLowerCase() }` )
).toBeVisible();
Expand All @@ -219,9 +234,7 @@ export const removeCurrency = async ( page: Page, currencyCode: string ) => {
`li.enabled-currency.${ currencyCode.toLowerCase() } .enabled-currency__action.delete`
)
.click();
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
timeout: 10000,
} );
await expectSnackbarWithText( page, 'Enabled currencies updated.' );
await expect(
page.locator( `li.enabled-currency.${ currencyCode.toLowerCase() }` )
).toBeHidden();
Expand All @@ -247,7 +260,7 @@ export const setCurrencyRate = async (
.locator( '#single-currency-settings__manual_rate_radio' )
.click();
await page.getByTestId( 'manual_rate_input' ).fill( rate );
await saveWooPaymentsSettings( page );
await saveMultiCurrencySettings( page );
};

export const setCurrencyPriceRounding = async (
Expand All @@ -257,7 +270,7 @@ export const setCurrencyPriceRounding = async (
) => {
await editCurrency( page, currencyCode );
await page.getByTestId( 'price_rounding' ).selectOption( rounding );
await saveWooPaymentsSettings( page );
await saveMultiCurrencySettings( page );
};

export const setCurrencyCharmPricing = async (
Expand All @@ -267,7 +280,7 @@ export const setCurrencyCharmPricing = async (
) => {
await editCurrency( page, currencyCode );
await page.getByTestId( 'price_charm' ).selectOption( charmPricing );
await saveWooPaymentsSettings( page );
await saveMultiCurrencySettings( page );
};

export const enablePaymentMethods = async (
Expand Down

0 comments on commit c08a83c

Please sign in to comment.