Files
flights_web/tests/e2e/navigation.spec.ts
T

85 lines
3.2 KiB
TypeScript

import { test, expect } from "./fixtures/console-gate";
import {
routeAppSettingsFixture,
routeDictionaryFixtures,
routePopularRequestsFixture,
} from "./helpers/api-fixtures";
async function routeNavigationStartFixtures(page: import("@playwright/test").Page): Promise<void> {
await routeAppSettingsFixture(page);
await routeDictionaryFixtures(page);
await routePopularRequestsFixture(page);
}
test.describe("Cross-feature navigation", () => {
test("locale switching: /ru/onlineboard -> /en/onlineboard shows English content", async ({
page,
consoleMessages,
}) => {
await routeNavigationStartFixtures(page);
// Start on Russian online board
await page.goto("/ru/onlineboard");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator('[data-testid="online-board-start"]')).toBeVisible(
{ timeout: 10000 },
);
// Navigate to English version. The router normalises `/en` to the
// BCP-47 form `/en-en/onlineboard`, so assert a loose `/en` URL
// prefix rather than the exact short form.
await page.goto("/en/onlineboard");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator('[data-testid="online-board-start"]')).toBeVisible(
{ timeout: 10000 },
);
expect(page.url()).toMatch(/\/en(-[a-z]+)?\/onlineboard/);
});
test("error page: /error/404 renders 404 content", async ({ page, consoleMessages }) => {
await routeNavigationStartFixtures(page);
// Navigate to a working page first, then client-side navigate to the error
// page. Direct URL navigation to /error/404 renders blank because the
// error route is outside [lang]/layout.tsx and SSR produces empty output.
await page.goto("/ru/onlineboard");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator('[data-testid="online-board-start"]')).toBeVisible(
{ timeout: 10000 },
);
await page.evaluate(() => window.location.assign("/error/404"));
await page.waitForLoadState("domcontentloaded");
// The error page shows the error code
await expect(page.locator(".error-page__code")).toHaveText("404", { timeout: 10000 });
});
test("error page: /error/500 renders server error content", async ({
page,
consoleMessages,
}) => {
await routeNavigationStartFixtures(page);
// Navigate to a working page first, then client-side navigate to the error
// page (same reason as the 404 test above).
await page.goto("/ru/onlineboard");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator('[data-testid="online-board-start"]')).toBeVisible(
{ timeout: 10000 },
);
await page.evaluate(() => window.location.assign("/error/500"));
await page.waitForLoadState("domcontentloaded");
await expect(page.locator(".error-page__code")).toHaveText("500", { timeout: 10000 });
});
test("unknown route: /ru/nonexistent does not crash", async ({ page, consoleMessages }) => {
const response = await page.goto("/ru/nonexistent");
await page.waitForLoadState("domcontentloaded");
// The page should render something (the app should handle unknown routes
// gracefully, possibly showing a 404 or redirecting)
await expect(page.locator("body")).not.toBeEmpty();
});
});