Files
tidefront/apps/web/e2e/32-design-modus.spec.ts
T
db9979 6178ac979a Design „Seekarte 2.0“ mit hellem und dunklem Modus
- Zentrale Tokens (theme.css, hell/dunkel) und Abbildung aller Farbklassen per @theme inline;
  Zeichnungen, Diagramme und Kurstafel auf Tokens statt fester Hexwerte
- Modus: Systemeinstellung als Standard, Einstellungen → Spiel → Darstellung (Wie System/Hell/Dunkel),
  ohne Flackern (Inline-Skript in index.html), theme-color passend
- Dunkle Kopfleiste mit Füllstandsbalken (orange ab 85 %), Rang-Chip, Desktop mit Kopfleiste über volle Breite
- Lage (Rangzeile, Alarmkarte, Fraunces-Titel, Umrissknopf), Gebäudeblatt (Jetzt/Stufe n, Kostenbalken, feste Bauleiste)
- Schriften selbst ausgeliefert (+ Fraunces 700); Kartenfarben als lib/theme-map.ts (noch nicht verdrahtet)
- Tests: Kontrast-Test der Tokens, E2E Moduswechsel und Bildschirmfotos hell/dunkel bei 390/1440 px
2026-11-28 23:30:09 +01:00

104 lines
5.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Seekarte 2.0 – Hell/Dunkel: Standard folgt der Systemeinstellung (prefers-color-scheme), Einstellungen → Spiel →
// „Darstellung“ wählt fest Hell/Dunkel/Wie System (localStorage „tf-theme“), Modus steht vor dem ersten Bild fest
// (kein Flackern: <html data-theme> ist gesetzt, bevor <body> existiert, und wechselt danach nicht), theme-color passt.
import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures.ts";
const HEAD = { light: "#14243a", dark: "#0a111d" };
const BG = { light: "rgb(244, 239, 228)", dark: "rgb(14, 23, 38)" };
/** Merkt den Modus beim Einhängen von <body> und zählt spätere Wechsel von data-theme (Flackern). */
async function watchFirstPaint(page: Page) {
await page.addInitScript(() => {
const w = window as unknown as { __tfTheme: { atBody: string | null; changes: number } };
w.__tfTheme = { atBody: null, changes: 0 };
new MutationObserver((list, obs) => {
for (const m of list) for (const n of Array.from(m.addedNodes)) {
if (n.nodeName === "BODY") {
w.__tfTheme.atBody = document.documentElement.getAttribute("data-theme");
new MutationObserver(() => { w.__tfTheme.changes++; }).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
obs.disconnect();
}
}
}).observe(document, { childList: true, subtree: true });
});
}
async function firstPaint(page: Page) {
return page.evaluate(() => (window as unknown as { __tfTheme: { atBody: string | null; changes: number } }).__tfTheme);
}
async function expectMode(page: Page, mode: "light" | "dark") {
await expect(page.locator("html")).toHaveAttribute("data-theme", mode);
await expect(page.locator('meta[name="theme-color"]')).toHaveAttribute("content", HEAD[mode]);
expect(await page.evaluate(() => getComputedStyle(document.body).backgroundColor)).toBe(BG[mode]);
}
test.describe("System dunkel", () => {
test.use({ colorScheme: "dark" });
test("Standard folgt dem System, ohne Flackern; Wahl „Hell“ gilt sofort und nach Neuladen", async ({ page, player }) => {
void player;
await watchFirstPaint(page);
await page.goto("/");
await expect(page.getByTestId("lage-tab")).toBeVisible();
await expectMode(page, "dark");
expect(await firstPaint(page)).toEqual({ atBody: "dark", changes: 0 });
// Einstellungen → Spiel → Darstellung: „Wie System“ ist gewählt.
await page.getByRole("button", { name: "Menü", exact: true }).click();
await page.getByRole("dialog").getByRole("button", { name: /^Einstellungen/ }).click();
const choice = page.getByRole("radiogroup", { name: "Darstellung" });
await expect(choice.getByRole("radio", { name: "Wie System" })).toHaveAttribute("aria-checked", "true");
await choice.getByRole("radio", { name: "Hell" }).click();
await expectMode(page, "light");
expect(await page.evaluate(() => localStorage.getItem("tf-theme"))).toBe("light");
// Neuladen: gleich hell – schon beim Einhängen von <body>, trotz dunklem System.
await page.reload();
await expect(page.getByRole("heading", { name: "Einstellungen", level: 1 })).toBeVisible();
await expectMode(page, "light");
expect(await firstPaint(page)).toEqual({ atBody: "light", changes: 0 });
// Zurück auf „Wie System“: wieder dunkel, Eintrag entfernt.
await page.getByRole("radiogroup", { name: "Darstellung" }).getByRole("radio", { name: "Wie System" }).click();
await expectMode(page, "dark");
expect(await page.evaluate(() => localStorage.getItem("tf-theme"))).toBeNull();
});
});
test.describe("System hell", () => {
test.use({ colorScheme: "light" });
test("Standard hell; „Dunkel“ fest gewählt; Systemwechsel greift nur bei „Wie System“", async ({ page, player }) => {
void player;
await watchFirstPaint(page);
await page.goto("/");
await expect(page.getByTestId("lage-tab")).toBeVisible();
await expectMode(page, "light");
expect(await firstPaint(page)).toEqual({ atBody: "light", changes: 0 });
// Systemwechsel während der Sitzung (Wie System): folgt sofort.
await page.emulateMedia({ colorScheme: "dark" });
await expectMode(page, "dark");
await page.emulateMedia({ colorScheme: "light" });
await expectMode(page, "light");
// Fest „Dunkel“: bleibt dunkel, auch wenn das System hell ist; Kopfleiste hat in beiden Modi ihren dunklen Streifen.
await page.getByRole("button", { name: "Menü", exact: true }).click();
await page.getByRole("dialog").getByRole("button", { name: /^Einstellungen/ }).click();
await page.getByRole("radiogroup", { name: "Darstellung" }).getByRole("radio", { name: "Dunkel" }).click();
await expectMode(page, "dark");
await page.emulateMedia({ colorScheme: "light" });
await expectMode(page, "dark");
expect(await page.evaluate(() => getComputedStyle(document.querySelector("header")!).backgroundColor)).toBe("rgb(10, 17, 29)");
// Anmeldeseite (ohne Spielstand) folgt der Wahl ebenso.
await page.context().clearCookies();
await page.goto("/");
await expect(page.getByRole("button", { name: /Anmelden/ }).first()).toBeVisible();
await expectMode(page, "dark");
expect(await firstPaint(page)).toEqual({ atBody: "dark", changes: 0 });
});
});