mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(test): create helper to look for alerts (#55483)
This commit is contained in:
committed by
GitHub
parent
a1b40fecb9
commit
af1ce853dd
@@ -1,5 +1,7 @@
|
|||||||
import { test, expect, Page } from '@playwright/test';
|
import { test, expect, Page } from '@playwright/test';
|
||||||
|
|
||||||
import translations from '../client/i18n/locales/english/translations.json';
|
import translations from '../client/i18n/locales/english/translations.json';
|
||||||
|
import { alertToBeVisible } from './utils/alerts';
|
||||||
|
|
||||||
test.use({ storageState: 'playwright/.auth/certified-user.json' });
|
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 page.goto('/certification/certifieduser/invalid-certification');
|
||||||
await expect(page).toHaveURL('/');
|
await expect(page).toHaveURL('/');
|
||||||
await expect(page.getByRole('alert')).toHaveText(
|
await alertToBeVisible(page, translations.flash['certificate-missing']);
|
||||||
/The certification you tried to view does not exist/
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
test.describe('for authenticated user', () => {
|
test.describe('for authenticated user', () => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { promisify } from 'util';
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
import translations from '../client/i18n/locales/english/translations.json';
|
import translations from '../client/i18n/locales/english/translations.json';
|
||||||
|
import { alertToBeVisible } from './utils/alerts';
|
||||||
|
|
||||||
const execP = promisify(exec);
|
const execP = promisify(exec);
|
||||||
|
|
||||||
@@ -111,11 +112,7 @@ test.describe('Delete Modal component', () => {
|
|||||||
).not.toBeVisible();
|
).not.toBeVisible();
|
||||||
|
|
||||||
await expect(page).toHaveURL(/.*\/learn\/?/);
|
await expect(page).toHaveURL(/.*\/learn\/?/);
|
||||||
await expect(
|
await alertToBeVisible(page, translations.flash['account-deleted']);
|
||||||
page
|
|
||||||
.getByRole('alert')
|
|
||||||
.filter({ hasText: 'Your account has been successfully deleted' })
|
|
||||||
).toBeVisible();
|
|
||||||
// The user is signed out after their account is deleted
|
// The user is signed out after their account is deleted
|
||||||
await expect(page.getByRole('link', { name: 'Sign in' })).toHaveCount(2);
|
await expect(page.getByRole('link', { name: 'Sign in' })).toHaveCount(2);
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-5
@@ -3,6 +3,7 @@ import { test, expect, type Page } from '@playwright/test';
|
|||||||
import translations from '../client/i18n/locales/english/translations.json';
|
import translations from '../client/i18n/locales/english/translations.json';
|
||||||
import { authedRequest } from './utils/request';
|
import { authedRequest } from './utils/request';
|
||||||
import { getEditors } from './utils/editor';
|
import { getEditors } from './utils/editor';
|
||||||
|
import { alertToBeVisible } from './utils/alerts';
|
||||||
|
|
||||||
const links = {
|
const links = {
|
||||||
basicJS1:
|
basicJS1:
|
||||||
@@ -67,11 +68,7 @@ test.beforeEach(async ({ page }) => {
|
|||||||
.getByRole('button', { name: translations.buttons.on, exact: true })
|
.getByRole('button', { name: translations.buttons.on, exact: true })
|
||||||
.click();
|
.click();
|
||||||
// wait for the client to register the change:
|
// wait for the client to register the change:
|
||||||
await expect(
|
await alertToBeVisible(page, translations.flash['keyboard-shortcut-updated']);
|
||||||
page
|
|
||||||
.getByRole('alert')
|
|
||||||
.filter({ hasText: translations.flash['keyboard-shortcut-updated'] })
|
|
||||||
).toBeVisible();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.afterEach(
|
test.afterEach(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
|
|||||||
|
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import translations from '../client/i18n/locales/english/translations.json';
|
import translations from '../client/i18n/locales/english/translations.json';
|
||||||
|
import { alertToBeVisible } from './utils/alerts';
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
@@ -67,11 +68,7 @@ test.describe('Link MS user component (signed-in user)', () => {
|
|||||||
await expect(unlinkButton).toBeVisible();
|
await expect(unlinkButton).toBeVisible();
|
||||||
await unlinkButton.click();
|
await unlinkButton.click();
|
||||||
|
|
||||||
await expect(
|
await alertToBeVisible(page, translations.flash.ms.transcript.unlinked);
|
||||||
page
|
|
||||||
.getByRole('alert')
|
|
||||||
.filter({ hasText: translations.flash.ms.transcript.unlinked })
|
|
||||||
).toBeVisible();
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole('heading', {
|
page.getByRole('heading', {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
import translations from '../client/i18n/locales/english/translations.json';
|
||||||
import stripeJson from './fixtures/donation/stripe.json';
|
import stripeJson from './fixtures/donation/stripe.json';
|
||||||
|
import { alertToBeVisible } from './utils/alerts';
|
||||||
|
|
||||||
test.describe('third-party donation tests', () => {
|
test.describe('third-party donation tests', () => {
|
||||||
test.use({ storageState: 'playwright/.auth/certified-user.json' });
|
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')).toBeVisible();
|
||||||
|
|
||||||
await expect(page.getByRole('alert')).toContainText(
|
await alertToBeVisible(page, translations.donate['free-tech']);
|
||||||
'Your donations will support free technology education for people all over the world.'
|
await alertToBeVisible(page, translations.donate['visit-supporters']);
|
||||||
);
|
|
||||||
await expect(page.getByRole('alert')).toContainText(
|
|
||||||
'Visit supporters page to learn about your supporter benefits.'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { test, expect } from '@playwright/test';
|
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.use({ storageState: 'playwright/.auth/development-user.json' });
|
||||||
|
|
||||||
test.beforeEach(() => {
|
test.beforeEach(() => {
|
||||||
@@ -36,9 +40,7 @@ test.describe('After creating token', () => {
|
|||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
await page.getByRole('button', { name: 'Delete my user token' }).click();
|
await page.getByRole('button', { name: 'Delete my user token' }).click();
|
||||||
|
|
||||||
await expect(page.getByRole('alert')).toContainText(
|
await alertToBeVisible(page, translations.flash['token-deleted']);
|
||||||
/Your user token has been deleted./
|
|
||||||
);
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText('User Token', { exact: true })
|
page.getByText('User Token', { exact: true })
|
||||||
).not.toBeVisible();
|
).not.toBeVisible();
|
||||||
|
|||||||
@@ -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();
|
||||||
Reference in New Issue
Block a user