Files
tidefront/apps/web/e2e/32-design-bilder.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

109 lines
5.4 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: alle Hauptbildschirme in hell und dunkel bei 390 und 1440 px – ohne Überbreite, ohne Konsolenfehler,
// Textkontrast ≥ 4,5:1 (große Schrift 3:1, e2e/contrast.ts). Bildschirmfotos unter /tmp/tf-design/
// (<breite>-<modus>-<bildschirm>.png) zum Ansehen. Der Modus kommt aus der Systemeinstellung (colorScheme).
import { mkdirSync } from "node:fs";
import type { Page } from "@playwright/test";
import { expect, expectNoHorizontalOverflow, openHafen, test } from "./fixtures.ts";
import { contrastIssues } from "./contrast.ts";
import { setBuildings, setResources, setUnits } from "./game.ts";
const DIR = "/tmp/tf-design";
const BUILT = { kraftwerk: 3, stahlwerk: 4, raffinerie: 2, versorgungshof: 3, kommandozentrale: 4, kaserne: 2, werft: 2, lagerkomplex: 2, chipfabrik: 1 };
async function shot(page: Page, prefix: string, name: string, opts: { contrastRoot?: string } = {}): Promise<void> {
await page.waitForLoadState("networkidle").catch(() => {});
await page.waitForTimeout(350);
mkdirSync(DIR, { recursive: true });
// Chromium meldet gelegentlich „Unable to capture screenshot“ (Bild noch nicht gezeichnet) – kurz erneut versuchen.
for (let i = 0; ; i++) {
try {
await page.screenshot({ path: `${DIR}/${prefix}-${name}.png`, timeout: 30_000 });
break;
} catch (e) {
if (i >= 10 || !String(e).includes("Unable to capture")) throw e;
await page.mouse.move(5, 5 + i); // neues Bild anstoßen
await page.waitForTimeout(1000);
}
}
await expectNoHorizontalOverflow(page, `${prefix} ${name}`);
const issues = await contrastIssues(page, opts.contrastRoot);
expect.soft(issues, `${prefix} ${name}: Textkontrast`).toEqual([]);
}
async function menu(page: Page, item: RegExp) {
await page.getByRole("button", { name: "Menü", exact: true }).click();
await page.getByRole("dialog").getByRole("button", { name: item }).click();
}
async function closeSheet(page: Page) {
await page.getByRole("dialog").getByRole("button", { name: "Schließen" }).last().click();
await expect(page.getByRole("dialog")).toHaveCount(0);
}
for (const scheme of ["light", "dark"] as const) {
for (const width of [390, 1440]) {
const desktop = width >= 1024;
const prefix = `${width}-${scheme === "light" ? "hell" : "dunkel"}`;
test.describe(`${prefix}`, () => {
test.use({ viewport: { width, height: desktop ? 900 : 844 }, colorScheme: scheme, ...(desktop ? { isMobile: false, hasTouch: false, deviceScaleFactor: 1 } : {}) });
// Zuerst (vor der Karte): danach meldet Chromium für frische Seiten zeitweise „Unable to capture screenshot“.
test(`Anmeldung ${prefix}`, async ({ page }) => {
await page.goto("/");
await expect(page.getByRole("button", { name: /Anmelden/ }).first()).toBeVisible();
await shot(page, prefix, "00-anmeldung");
});
test(`Hauptbildschirme ${prefix}`, async ({ page, player, seed }) => {
test.setTimeout(150_000);
await seed.sql`update player set is_admin = true where id = ${player.id}`;
await setBuildings(seed.sql, player.baseId, BUILT);
await setResources(seed.sql, player.baseId, { stahl: 2681, treibstoff: 3285, elektronik: 1749, proviant: 9000 });
await setUnits(seed.sql, player.baseId, { korvette: 6, marine: 20 });
await page.goto("/");
await expect(page.getByTestId("lage-tab")).toBeVisible();
await expect(page.locator("html")).toHaveAttribute("data-theme", scheme);
await shot(page, prefix, "01-lage");
await openHafen(page);
await expect(page.getByRole("heading", { name: "Bauhof" })).toBeVisible();
await shot(page, prefix, "02-hafen");
await page.getByRole("button", { name: /^Raffinerie/ }).first().click();
await expect(page.getByTestId("building-actions")).toBeVisible();
await shot(page, prefix, "03-gebaeudeblatt");
await closeSheet(page);
const nav = page.getByRole("navigation", { name: "Hauptnavigation" });
if (!desktop) {
await nav.getByRole("button", { name: /^Karte/ }).click();
await page.waitForTimeout(1200);
await shot(page, prefix, "04-karte", { contrastRoot: "header" });
}
await nav.getByRole("button", { name: /^Truppen/ }).click();
await expect(page.getByRole("tab", { name: /^Einsatz/ })).toBeVisible();
await shot(page, prefix, "05-truppen");
await nav.getByRole("button", { name: /^Meldungen/ }).click();
await shot(page, prefix, "06-meldungen");
await page.getByRole("tab", { name: /^Saison/ }).click();
await shot(page, prefix, "07-saison");
await nav.getByRole("button", { name: /^Börse/ }).click();
await shot(page, prefix, "08-boerse");
await menu(page, /^Handbuch/);
await expect(page.getByRole("heading", { name: "Handbuch", level: 1 })).toBeVisible();
await shot(page, prefix, "09-handbuch");
await menu(page, /^Einstellungen/);
await expect(page.getByRole("heading", { name: "Einstellungen", level: 1 })).toBeVisible();
await shot(page, prefix, "10-einstellungen");
await menu(page, /^Verwaltung/);
await shot(page, prefix, "11-verwaltung");
await page.getByRole("button", { name: "Menü", exact: true }).click();
await expect(page.getByRole("dialog")).toBeVisible();
await shot(page, prefix, "12-menue");
await closeSheet(page);
});
});
}
}