diff --git a/e2e/certification.spec.ts b/e2e/certification.spec.ts index 44985d7b1e1..5abf3883644 100644 --- a/e2e/certification.spec.ts +++ b/e2e/certification.spec.ts @@ -1,5 +1,7 @@ import { test, expect, Page } from '@playwright/test'; + import translations from '../client/i18n/locales/english/translations.json'; +import { alertToBeVisible } from './utils/alerts'; test.use({ storageState: 'playwright/.auth/certified-user.json' }); @@ -142,9 +144,7 @@ test.describe('Invalid certification page', () => { { await page.goto('/certification/certifieduser/invalid-certification'); await expect(page).toHaveURL('/'); - await expect(page.getByRole('alert')).toHaveText( - /The certification you tried to view does not exist/ - ); + await alertToBeVisible(page, translations.flash['certificate-missing']); } }; test.describe('for authenticated user', () => { diff --git a/e2e/delete-modal.spec.ts b/e2e/delete-modal.spec.ts index a8f7cf59325..bfd8f92234c 100644 --- a/e2e/delete-modal.spec.ts +++ b/e2e/delete-modal.spec.ts @@ -4,6 +4,7 @@ import { promisify } from 'util'; import { test, expect } from '@playwright/test'; import translations from '../client/i18n/locales/english/translations.json'; +import { alertToBeVisible } from './utils/alerts'; const execP = promisify(exec); @@ -111,11 +112,7 @@ test.describe('Delete Modal component', () => { ).not.toBeVisible(); await expect(page).toHaveURL(/.*\/learn\/?/); - await expect( - page - .getByRole('alert') - .filter({ hasText: 'Your account has been successfully deleted' }) - ).toBeVisible(); + await alertToBeVisible(page, translations.flash['account-deleted']); // The user is signed out after their account is deleted await expect(page.getByRole('link', { name: 'Sign in' })).toHaveCount(2); }); diff --git a/e2e/hotkeys.spec.ts b/e2e/hotkeys.spec.ts index 081c554e1e0..596fb6155df 100644 --- a/e2e/hotkeys.spec.ts +++ b/e2e/hotkeys.spec.ts @@ -3,6 +3,7 @@ import { test, expect, type Page } from '@playwright/test'; import translations from '../client/i18n/locales/english/translations.json'; import { authedRequest } from './utils/request'; import { getEditors } from './utils/editor'; +import { alertToBeVisible } from './utils/alerts'; const links = { basicJS1: @@ -67,11 +68,7 @@ test.beforeEach(async ({ page }) => { .getByRole('button', { name: translations.buttons.on, exact: true }) .click(); // wait for the client to register the change: - await expect( - page - .getByRole('alert') - .filter({ hasText: translations.flash['keyboard-shortcut-updated'] }) - ).toBeVisible(); + await alertToBeVisible(page, translations.flash['keyboard-shortcut-updated']); }); test.afterEach( diff --git a/e2e/link-ms-user.spec.ts b/e2e/link-ms-user.spec.ts index 10c7c385354..a3584404245 100644 --- a/e2e/link-ms-user.spec.ts +++ b/e2e/link-ms-user.spec.ts @@ -2,6 +2,7 @@ import { execSync } from 'child_process'; import { test, expect } from '@playwright/test'; import translations from '../client/i18n/locales/english/translations.json'; +import { alertToBeVisible } from './utils/alerts'; test.beforeEach(async ({ page }) => { await page.goto( @@ -67,11 +68,7 @@ test.describe('Link MS user component (signed-in user)', () => { await expect(unlinkButton).toBeVisible(); await unlinkButton.click(); - await expect( - page - .getByRole('alert') - .filter({ hasText: translations.flash.ms.transcript.unlinked }) - ).toBeVisible(); + await alertToBeVisible(page, translations.flash.ms.transcript.unlinked); await expect( page.getByRole('heading', { diff --git a/e2e/third-party-donation.spec.ts b/e2e/third-party-donation.spec.ts index 7167a92fd61..37479813972 100644 --- a/e2e/third-party-donation.spec.ts +++ b/e2e/third-party-donation.spec.ts @@ -1,6 +1,8 @@ import { test, expect } from '@playwright/test'; +import translations from '../client/i18n/locales/english/translations.json'; import stripeJson from './fixtures/donation/stripe.json'; +import { alertToBeVisible } from './utils/alerts'; test.describe('third-party donation tests', () => { test.use({ storageState: 'playwright/.auth/certified-user.json' }); @@ -65,11 +67,7 @@ test.describe('third-party donation tests', () => { await expect(page.getByRole('alert')).toBeVisible(); - await expect(page.getByRole('alert')).toContainText( - 'Your donations will support free technology education for people all over the world.' - ); - await expect(page.getByRole('alert')).toContainText( - 'Visit supporters page to learn about your supporter benefits.' - ); + await alertToBeVisible(page, translations.donate['free-tech']); + await alertToBeVisible(page, translations.donate['visit-supporters']); }); }); diff --git a/e2e/user-token.spec.ts b/e2e/user-token.spec.ts index e13d1d0d6df..2246d079906 100644 --- a/e2e/user-token.spec.ts +++ b/e2e/user-token.spec.ts @@ -1,5 +1,9 @@ import { execSync } from 'child_process'; import { test, expect } from '@playwright/test'; + +import translations from '../client/i18n/locales/english/translations.json'; +import { alertToBeVisible } from './utils/alerts'; + test.use({ storageState: 'playwright/.auth/development-user.json' }); test.beforeEach(() => { @@ -36,9 +40,7 @@ test.describe('After creating token', () => { ).toBeVisible(); await page.getByRole('button', { name: 'Delete my user token' }).click(); - await expect(page.getByRole('alert')).toContainText( - /Your user token has been deleted./ - ); + await alertToBeVisible(page, translations.flash['token-deleted']); await expect( page.getByText('User Token', { exact: true }) ).not.toBeVisible(); diff --git a/e2e/utils/alerts.ts b/e2e/utils/alerts.ts new file mode 100644 index 00000000000..4ca8650fa49 --- /dev/null +++ b/e2e/utils/alerts.ts @@ -0,0 +1,4 @@ +import { expect, type Page } from '@playwright/test'; + +export const alertToBeVisible = async (page: Page, text: string) => + await expect(page.getByRole('alert').filter({ hasText: text })).toBeVisible();