Files
flights_web/tests/e2e/standalone-shell.spec.ts

118 lines
4.5 KiB
TypeScript

import type { Page } from "@playwright/test";
import { test, expect } from "./fixtures/console-gate";
function hasTransientShellLoadError(consoleMessages: string[]): boolean {
return consoleMessages.some(
(message) =>
message.includes("afl-frontend-lib.") &&
(message.includes("504 (Gateway Timeout)") ||
message.includes("Loading chunk")),
);
}
async function loadStandaloneShell(page: Page, consoleMessages: string[]): Promise<void> {
let lastError: unknown;
for (let attempt = 0; attempt < 2; attempt += 1) {
consoleMessages.length = 0;
await page.goto("/ru-ru/smoke");
await page.waitForLoadState("domcontentloaded");
try {
await expect(page.getByTestId("standalone-header")).toContainText("Сервисы и услуги", {
timeout: 15_000,
});
await expect(page.locator('afl-component.footer[data-component="Footer"]')).toContainText(
"Контакты",
{ timeout: 15_000 },
);
if (!hasTransientShellLoadError(consoleMessages)) return;
} catch (err) {
lastError = err;
if (!hasTransientShellLoadError(consoleMessages)) throw err;
}
}
if (lastError) throw lastError;
}
test.describe("TIRREDESIGN-30 — standalone header and footer", () => {
test("Russian standalone pages render Angular-style Aeroflot shell placeholders", async ({
page,
consoleMessages,
}) => {
await loadStandaloneShell(page, consoleMessages);
const header = page.getByTestId("standalone-header");
await expect(header.locator('afl-component.header[data-component="Header"]')).toHaveCount(1);
await expect(header).toContainText("Сервисы и услуги", { timeout: 15_000 });
await expect(header).toContainText("Личный кабинет", { timeout: 15_000 });
await expect(header.locator("a", { hasText: "Сервисы и услуги" }).first()).toHaveAttribute(
"href",
"https://www.aeroflot.ru/ru-ru/online_services",
);
await expect(header.locator("a", { hasText: "Купить билет" }).first()).toHaveAttribute(
"href",
"https://www.aeroflot.ru/ru/booking",
);
await expect(header.locator("a", { hasText: "Вступить в программу" }).first()).toHaveAttribute(
"href",
"https://www.aeroflot.ru/personal/login?_preferredLanguage=ru",
);
await expect(
header.locator("a", {
hasText: "Вход в личный кабинет Программы Корпоративной Лояльности",
}).first(),
).toHaveAttribute("href", "https://www.aeroflot.ru/pkl/app/ru/login");
await expect(page.locator("h1")).toHaveText("Страница проверки");
const footer = page.locator('afl-component.footer[data-component="Footer"]');
await expect(footer).toHaveCount(1);
await expect(footer).toContainText("Контакты", { timeout: 15_000 });
await expect(footer).toContainText("8 (800) 444-55-55", { timeout: 15_000 });
await expect(footer.locator("a", { hasText: "Обратная связь" }).first()).toHaveAttribute(
"href",
"https://www.aeroflot.ru/ru-ru/help",
);
const sameOriginShellLinks = await page
.locator('afl-component.header a[href], afl-component.footer a[href]')
.evaluateAll((anchors) =>
anchors
.map((anchor) => ({
href: anchor.getAttribute("href") ?? "",
text: anchor.textContent?.replace(/\s+/g, " ").trim() ?? "",
}))
.filter((link) => {
try {
return new URL(link.href, window.location.href).origin === window.location.origin;
} catch {
return false;
}
}),
);
expect(sameOriginShellLinks).toEqual([]);
await expect(
page.locator('.banner--top afl-component[data-component="BannersOffers"].initialized'),
).toHaveCount(1);
await expect(
page.locator('.banner--bottom afl-component[data-component="BannersOffers"].initialized'),
).toHaveCount(1);
});
test("local dev hydrates placeholders through same-origin Aeroflot loader proxy", async ({
page,
consoleMessages,
}) => {
await page.goto("/ru-ru/smoke");
await page.waitForLoadState("domcontentloaded");
await expect(
page.locator('meta[name="aeroflot-shell-loader"][content="proxy"]'),
).toHaveCount(1);
await expect(
page.locator('script[src="/frontend/static/js/afl-frontend-loader.bundle.js"]'),
).toHaveCount(1);
});
});