test(e2e,playwright): Challenges (#51773)

pull/51882/head
Kyle 2023-10-09 07:42:24 -05:00 committed by GitHub
parent 174865974b
commit 7d95ce71dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 0 deletions

51
e2e/challenges.test.ts Normal file
View File

@ -0,0 +1,51 @@
import { test, expect, Page } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
let page: Page;
const pathsToTest = [{ input: '/challenges', expected: '/learn' }];
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
await page.close();
});
test.describe('Legacy Challenge Path Redirection Tests', () => {
const testLearnPageTitle = async () => {
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);
};
const testLearnPageHeader = async () => {
const header = page.getByTestId('learn-heading');
await expect(header).toBeVisible();
await expect(header).toContainText(translations.learn.heading);
};
const runLearnTests = async () => {
await testLearnPageTitle();
await testLearnPageHeader();
};
for (const { input, expected } of pathsToTest) {
test(`should redirect from ${input} to ${expected}, if it fails runs a DOM test`, async () => {
try {
await page.goto(input);
const currentPath = new URL(page.url()).pathname;
expect(currentPath).toBe(expected);
// Due to inconsistent URL behavior in WebKit & Mobile Safari.
// The URL may not correctly reflect the page.
// Fallback to running a DOM test and validate page content.
// Ensures we are on the expected page despite URL.
} catch (error) {
console.log(
`Failed to redirect from ${input} to ${expected}. Running DOM tests.`
);
await runLearnTests();
}
});
}
});