From 7d95ce71ddd442aefaaba9bd54dcfcaa47e4365a Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 9 Oct 2023 07:42:24 -0500 Subject: [PATCH] test(e2e,playwright): Challenges (#51773) --- e2e/challenges.test.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 e2e/challenges.test.ts diff --git a/e2e/challenges.test.ts b/e2e/challenges.test.ts new file mode 100644 index 00000000000..3cce4eb23bd --- /dev/null +++ b/e2e/challenges.test.ts @@ -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(); + } + }); + } +});