123 lines
4.9 KiB
JavaScript
Raw Normal View History

2026-04-11 00:02:26 -03:00
import { expect, test } from "../../../frontend/node_modules/@playwright/test/index.mjs";
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
const originalFetch = window.fetch.bind(window);
2026-06-29 13:23:07 -03:00
const jsonResponse = (body, status = 200) =>
new Response(JSON.stringify(body), {
2026-06-29 13:23:07 -03:00
status,
headers: { "content-type": "application/json" },
});
window.fetch = (resource, options) => {
const requestUrl = typeof resource === "string" ? resource : resource?.url || "";
const url = new URL(requestUrl, window.location.origin);
if (url.pathname === "/api/auth/config") {
2026-06-29 13:23:07 -03:00
return Promise.resolve(jsonResponse({ enabled: true, reset_url: "https://sso.example.dev/reset" }));
}
if (url.pathname === "/api/lab/status") {
2026-06-29 13:23:07 -03:00
if (window.__LAB_STATUS_FAIL__) {
return Promise.resolve(jsonResponse({ error: "status 503" }, 503));
}
return Promise.resolve(
jsonResponse({
connected: true,
2026-06-29 13:23:07 -03:00
atlas: { up: true, known: true },
active_service: { known: true, label: "Nextcloud", url: "https://cloud.bstein.dev", window: "15m" },
dedicated_hosts: {
known: true,
up: true,
up_count: 2,
total: 2,
hosts: [
{ label: "Database node", known: true, up: true },
{ label: "Jumphost", known: true, up: true },
],
},
checked_at: 1000,
}),
);
}
return originalFetch(resource, options);
};
});
2026-04-11 00:02:26 -03:00
await page.route("**/api/auth/config", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
2026-06-29 13:23:07 -03:00
body: JSON.stringify({ enabled: true, reset_url: "https://sso.example.dev/reset" }),
2026-04-11 00:02:26 -03:00
});
});
await page.route("**/api/lab/status", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
connected: true,
2026-06-29 13:23:07 -03:00
atlas: { up: true, known: true },
active_service: { known: true, label: "Nextcloud", url: "https://cloud.bstein.dev", window: "15m" },
dedicated_hosts: {
known: true,
up: true,
up_count: 2,
total: 2,
hosts: [
{ label: "Database node", known: true, up: true },
{ label: "Jumphost", known: true, up: true },
],
},
checked_at: 1000,
2026-04-11 00:02:26 -03:00
}),
});
});
});
2026-06-29 13:23:07 -03:00
test("shows Brad's professional homepage and opens the platform diagram overlay", async ({ page }) => {
2026-04-11 00:02:26 -03:00
await page.goto("/", { waitUntil: "domcontentloaded" });
2026-06-29 13:23:07 -03:00
await expect(page.getByRole("heading", { name: "Brad Stein" })).toBeVisible();
await expect(page.getByRole("heading", { name: "DevOps Automation Engineer / Senior SDET" })).toBeVisible();
await expect(page.getByRole("link", { name: "Discuss a Project" })).toBeVisible();
await expect(page.getByRole("link", { name: "View Résumé" })).toBeVisible();
await expect(page.getByRole("link", { name: "Explore the Live Platform" })).toBeVisible();
await expect(page.getByRole("button", { name: "Login" })).toBeVisible();
await expect(page.getByRole("link", { name: "Register" })).toBeVisible();
await expect(page.getByRole("heading", { name: "From 0 to 100" })).toBeVisible();
await expect(page.getByRole("link", { name: "Nextcloud", exact: true })).toBeVisible();
await expect(page.getByText("2 of 2 responding")).toBeVisible();
await page.getByRole("link", { name: "Explore the Live Platform" }).click();
await expect(page.getByRole("heading", { name: "Titan Lab: Live Platform" })).toBeVisible();
await expect(page.getByRole("link", { name: "IaC source" })).toBeVisible();
2026-04-11 00:02:26 -03:00
await expect(page.getByText("Live data connected")).toBeVisible();
await expect(page.locator(".service-grid .service").filter({ hasText: "Nextcloud" }).first()).toBeVisible();
2026-06-29 13:23:07 -03:00
await page.locator("details.source-diagrams summary").click();
const firstCard = page.locator("details.source-diagrams .mermaid-card").first();
await expect(firstCard).toBeVisible();
await firstCard.locator(".diagram").click();
2026-04-11 00:02:26 -03:00
await expect(page.locator(".overlay")).toBeVisible();
await page.keyboard.press("Escape");
await expect(page.locator(".overlay")).toHaveCount(0);
});
2026-06-29 13:23:07 -03:00
test("keeps the homepage usable when public status fails", async ({ page }) => {
await page.addInitScript(() => {
window.__LAB_STATUS_FAIL__ = true;
});
await page.route("**/api/lab/status", async (route) => {
await route.fulfill({
status: 503,
contentType: "application/json",
body: JSON.stringify({ error: "status 503" }),
});
});
await page.goto("/", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("heading", { name: "Brad Stein" })).toBeVisible();
await expect(page.getByText("Live status is temporarily unavailable").first()).toBeVisible();
await expect(page.getByText("status 503")).toHaveCount(0);
});