Add interactive component catalog and browser regression tests

This commit is contained in:
2026-11-20 00:57:23 +01:00
parent 443cbbc23c
commit 6206c687ad
82 changed files with 799 additions and 166 deletions
+141
View File
@@ -0,0 +1,141 @@
import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";
const openExample = async (page) => {
await page.goto("/examples/index.html");
await page.addStyleTag({ content: "html { scroll-behavior: auto !important; }" });
await page.evaluate(() => document.fonts.ready);
};
const formatViolations = (violations) => violations.map(({ help, helpUrl, id, impact, nodes }) => ({
help,
helpUrl,
id,
impact,
targets: nodes.map((node) => node.target),
}));
test.beforeEach(async ({ page }) => {
await openExample(page);
});
const visualCases = [
{ id: "buttons", name: "buttons" },
{ id: "forms", name: "form controls" },
{ id: "surfaces", name: "surfaces and badges" },
{ id: "feedback", name: "feedback" },
{ id: "menus", name: "menus and tooltips", prepare: async (page) => {
if (await page.locator("#example-menu").isHidden()) await page.locator("#menu-trigger").click();
} },
{ id: "navigation", name: "navigation" },
{ id: "disclosure", name: "tabs and accordion" },
{ id: "data", name: "data and status" },
{ id: "modal", name: "modal", target: "#example-dialog .frost-modal__content", prepare: async (page) => {
if (!await page.locator("#example-dialog").evaluate((dialog) => dialog.open)) await page.locator("#modal-trigger").click();
} },
];
for (const visualCase of visualCases) {
test(`${visualCase.name} matches its component baselines`, async ({ page }) => {
await page.addStyleTag({ content: ".frost-skip-link { display: none !important; }" });
for (const theme of ["light", "dark"]) {
await page.locator("html").evaluate((element, selectedTheme) => {
element.dataset.theme = selectedTheme;
}, theme);
await visualCase.prepare?.(page);
const target = page.locator(visualCase.target ?? `#${visualCase.id}`);
await expect(target).toHaveScreenshot(`component-${visualCase.id}-${theme}.png`);
}
});
}
for (const theme of ["light", "dark"]) {
test(`has no detectable WCAG A or AA violations in the ${theme} theme`, async ({ page }) => {
await page.locator("html").evaluate((element, selectedTheme) => {
element.dataset.theme = selectedTheme;
}, theme);
const { violations } = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"])
.analyze();
expect(formatViolations(violations), "Axe accessibility violations").toEqual([]);
});
}
test("dropdown exposes state and closes with Escape", async ({ page }) => {
const trigger = page.getByRole("button", { name: "Menü öffnen" });
const menu = page.locator("#example-menu");
await trigger.click();
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await expect(menu).toBeVisible();
await page.keyboard.press("Escape");
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await expect(menu).toBeHidden();
await expect(trigger).toBeFocused();
});
test("tabs support click and arrow-key navigation", async ({ page }) => {
const overview = page.getByRole("tab", { name: "Übersicht" });
const details = page.getByRole("tab", { name: "Details" });
await details.click();
await expect(details).toHaveAttribute("aria-selected", "true");
await expect(page.locator("#tab-panel-two")).toBeVisible();
await expect(page.locator("#tab-panel-one")).toBeHidden();
await page.keyboard.press("ArrowLeft");
await expect(overview).toBeFocused();
await expect(overview).toHaveAttribute("aria-selected", "true");
await expect(page.locator("#tab-panel-one")).toBeVisible();
});
test("accordion keeps its control and panel state synchronized", async ({ page }) => {
const trigger = page.getByRole("button", { name: "Was macht Frost?" });
const panel = page.locator("#accordion-panel");
await trigger.click();
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await expect(panel).toBeVisible();
await trigger.click();
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await expect(panel).toBeHidden();
});
test("catalog search filters components and navigation", async ({ page }) => {
const search = page.locator("#component-search");
await search.fill("modal");
await expect(page.locator("#modal")).toBeVisible();
await expect(page.locator("#buttons")).toBeHidden();
await expect(page.locator("#visible-count")).toHaveText("1 von 9 Gruppen");
await search.fill("unbekannt");
await expect(page.locator("#catalog-empty")).toBeVisible();
});
test("copy buttons expose the live HTML snippet", async ({ page }) => {
const component = page.locator("#buttons");
const code = component.locator("[data-snippet-code]");
const copy = component.locator("[data-copy-html]");
await expect(code).toContainText("frost-button--primary");
await copy.click();
await expect(copy).toHaveText("Kopiert");
await expect(page.locator("#copy-status")).toContainText("Buttons: HTML kopiert");
});
test("modal restores focus to its trigger after closing", async ({ page }) => {
const trigger = page.locator("#modal-trigger");
const dialog = page.locator("#example-dialog");
await trigger.click();
await expect(dialog).toBeVisible();
await dialog.getByRole("button", { name: "Modal schließen" }).click();
await expect(dialog).toBeHidden();
await expect(trigger).toBeFocused();
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+46
View File
@@ -0,0 +1,46 @@
import { createReadStream } from "node:fs";
import { stat } from "node:fs/promises";
import { createServer } from "node:http";
import { extname, resolve, sep } from "node:path";
import { fileURLToPath } from "node:url";
const root = resolve(fileURLToPath(new URL("../..", import.meta.url)));
const host = "127.0.0.1";
const port = Number.parseInt(process.env.FROST_TEST_PORT ?? "4173", 10);
const contentTypes = new Map([
[".css", "text/css; charset=utf-8"],
[".html", "text/html; charset=utf-8"],
[".js", "text/javascript; charset=utf-8"],
[".mjs", "text/javascript; charset=utf-8"],
[".png", "image/png"],
[".svg", "image/svg+xml"],
]);
const server = createServer(async (request, response) => {
try {
const url = new URL(request.url ?? "/", `http://${host}:${port}`);
const pathname = decodeURIComponent(url.pathname === "/" ? "/examples/index.html" : url.pathname);
const file = resolve(root, `.${pathname}`);
if (file !== root && !file.startsWith(`${root}${sep}`)) {
response.writeHead(403).end("Forbidden");
return;
}
const metadata = await stat(file);
if (!metadata.isFile()) throw new Error("Not a file");
response.writeHead(200, {
"Cache-Control": "no-store",
"Content-Type": contentTypes.get(extname(file)) ?? "application/octet-stream",
});
createReadStream(file).pipe(response);
} catch {
response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }).end("Not found");
}
});
server.listen(port, host, () => {
console.log(`Frost example server listening on http://${host}:${port}`);
});