Skip to content

Commit c08a83c

Browse files
authored
Refactoring of snackbar checks in Playwright e2e tests (#10218)
1 parent e69616a commit c08a83c

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: dev
3+
4+
Refactoring of snackbar checks in Playwright e2e tests

tests/e2e-pw/utils/merchant.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,30 @@ const ensureSupportPhoneIsFilled = async ( page: Page ) => {
5353
}
5454
};
5555

56+
const expectSnackbarWithText = async (
57+
page: Page,
58+
expectedText: string,
59+
timeout = 10000
60+
) => {
61+
await expect(
62+
page.locator( '.components-snackbar__content', {
63+
hasText: expectedText,
64+
} )
65+
).toBeVisible( {
66+
timeout: timeout,
67+
} );
68+
};
69+
5670
export const saveWooPaymentsSettings = async ( page: Page ) => {
5771
await ensureSupportPhoneIsFilled( page );
5872

5973
await page.getByRole( 'button', { name: 'Save changes' } ).click();
60-
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
61-
timeout: 10000,
62-
} );
74+
await expectSnackbarWithText( page, 'Settings saved.' );
75+
};
76+
77+
export const saveMultiCurrencySettings = async ( page: Page ) => {
78+
await page.getByRole( 'button', { name: 'Save changes' } ).click();
79+
await expectSnackbarWithText( page, 'Currency settings updated.' );
6380
};
6481

6582
export const isMulticurrencyEnabled = async ( page: Page ) => {
@@ -122,9 +139,7 @@ export const addMulticurrencyWidget = async ( page: Page ) => {
122139
page.getByRole( 'button', { name: 'Update' } )
123140
).toBeEnabled();
124141
await page.getByRole( 'button', { name: 'Update' } ).click();
125-
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
126-
timeout: 10000,
127-
} );
142+
await expectSnackbarWithText( page, 'Widgets saved.' );
128143
}
129144
};
130145

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

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

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

199216
await page.getByRole( 'button', { name: 'Update selected' } ).click();
200-
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
201-
timeout: 10000,
202-
} );
217+
await expectSnackbarWithText( page, 'Enabled currencies updated.' );
203218
await expect(
204219
page.locator( `li.enabled-currency.${ currencyCode.toLowerCase() }` )
205220
).toBeVisible();
@@ -219,9 +234,7 @@ export const removeCurrency = async ( page: Page, currencyCode: string ) => {
219234
`li.enabled-currency.${ currencyCode.toLowerCase() } .enabled-currency__action.delete`
220235
)
221236
.click();
222-
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
223-
timeout: 10000,
224-
} );
237+
await expectSnackbarWithText( page, 'Enabled currencies updated.' );
225238
await expect(
226239
page.locator( `li.enabled-currency.${ currencyCode.toLowerCase() }` )
227240
).toBeHidden();
@@ -247,7 +260,7 @@ export const setCurrencyRate = async (
247260
.locator( '#single-currency-settings__manual_rate_radio' )
248261
.click();
249262
await page.getByTestId( 'manual_rate_input' ).fill( rate );
250-
await saveWooPaymentsSettings( page );
263+
await saveMultiCurrencySettings( page );
251264
};
252265

253266
export const setCurrencyPriceRounding = async (
@@ -257,7 +270,7 @@ export const setCurrencyPriceRounding = async (
257270
) => {
258271
await editCurrency( page, currencyCode );
259272
await page.getByTestId( 'price_rounding' ).selectOption( rounding );
260-
await saveWooPaymentsSettings( page );
273+
await saveMultiCurrencySettings( page );
261274
};
262275

263276
export const setCurrencyCharmPricing = async (
@@ -267,7 +280,7 @@ export const setCurrencyCharmPricing = async (
267280
) => {
268281
await editCurrency( page, currencyCode );
269282
await page.getByTestId( 'price_charm' ).selectOption( charmPricing );
270-
await saveWooPaymentsSettings( page );
283+
await saveMultiCurrencySettings( page );
271284
};
272285

273286
export const enablePaymentMethods = async (

0 commit comments

Comments
 (0)