Files
Fretux 50fe5ec2e9
CI / Test and package (push) Successful in 1m29s
Release and RC / Verify and publish (push) Failing after 6m12s
Prepare Frost 1.0.0 release candidate
2026-11-21 14:48:53 +01:00

253 lines
11 KiB
JavaScript

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: "contrast-guide", name: "forced-colors guidance", target: ".catalog-contrast-guide" },
{ 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, browserName }) => {
test.skip(browserName !== "chromium", "Pixel baselines are intentionally pinned to Chromium; other engines run behavioral and accessibility coverage.");
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`);
}
});
test(`${visualCase.name} matches its forced-colors baseline`, async ({ page, browserName }) => {
test.skip(browserName !== "chromium", "Forced-colors pixel baselines are intentionally pinned to Chromium.");
await page.emulateMedia({ colorScheme: "light", forcedColors: "active" });
await page.addStyleTag({ content: ".frost-skip-link { display: none !important; }" });
await visualCase.prepare?.(page);
const target = page.locator(visualCase.target ?? `#${visualCase.id}`);
await expect(target).toHaveScreenshot(`component-${visualCase.id}-forced-colors.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();
});
test("forced colors preserves system mappings and non-color state cues", async ({ page }) => {
await page.emulateMedia({ colorScheme: "light", forcedColors: "active" });
const supportsForcedColors = await page.evaluate(() => matchMedia("(forced-colors: active)").matches && CSS.supports("forced-color-adjust: none"));
test.skip(!supportsForcedColors, "This browser engine does not expose forced-color-adjust with forced-colors emulation.");
const primary = page.locator("#buttons .frost-button--primary").first();
const disabled = page.locator("#buttons .frost-button:disabled");
const invalid = page.locator("#forms [aria-invalid='true']");
const selectedTab = page.locator("#disclosure [role='tab'][aria-selected='true']");
await primary.focus();
await expect(primary).toBeFocused();
const states = await page.evaluate(() => {
const style = (selector) => getComputedStyle(document.querySelector(selector));
const primaryStyle = style("#buttons .frost-button--primary");
const disabledStyle = style("#buttons .frost-button:disabled");
const invalidStyle = style("#forms [aria-invalid='true']");
const selectedStyle = style("#disclosure [role='tab'][aria-selected='true']");
const interactiveCardStyle = style("#surfaces .frost-card--interactive");
return {
primary: {
forcedColorAdjust: primaryStyle.forcedColorAdjust,
outlineStyle: primaryStyle.outlineStyle,
outlineWidth: Number.parseFloat(primaryStyle.outlineWidth),
},
disabled: { opacity: disabledStyle.opacity },
invalid: { borderStyle: invalidStyle.borderStyle, borderWidth: Number.parseFloat(invalidStyle.borderWidth) },
selected: { borderStyle: selectedStyle.borderBottomStyle, borderWidth: Number.parseFloat(selectedStyle.borderBottomWidth) },
card: { boxShadow: interactiveCardStyle.boxShadow },
};
});
expect(states.primary.forcedColorAdjust).toBe("none");
expect(states.primary.outlineStyle).toBe("solid");
expect(states.primary.outlineWidth).toBeGreaterThanOrEqual(3);
expect(states.disabled.opacity).toBe("1");
expect(states.invalid.borderStyle).toBe("dashed");
expect(states.invalid.borderWidth).toBeGreaterThanOrEqual(2);
expect(states.selected.borderStyle).toBe("solid");
expect(states.selected.borderWidth).toBeGreaterThanOrEqual(3);
expect(states.card.boxShadow).toBe("none");
await expect(disabled).toBeDisabled();
await expect(invalid).toHaveAttribute("aria-invalid", "true");
await expect(selectedTab).toHaveAttribute("aria-selected", "true");
});
test("increased contrast strengthens component boundaries and states", async ({ page }) => {
await page.emulateMedia({ colorScheme: "light", contrast: "more", forcedColors: "none" });
const supportsIncreasedContrast = await page.evaluate(() => matchMedia("(prefers-contrast: more)").matches
&& Number.parseFloat(getComputedStyle(document.querySelector("#buttons .frost-button--primary")).borderWidth) >= 2);
test.skip(!supportsIncreasedContrast, "This browser engine does not expose prefers-contrast emulation.");
const states = await page.evaluate(() => {
const style = (selector) => getComputedStyle(document.querySelector(selector));
const buttonStyle = style("#buttons .frost-button--primary");
const disabledStyle = style("#buttons .frost-button:disabled");
const invalidStyle = style("#forms [aria-invalid='true']");
const cardStyle = style("#surfaces .frost-card");
const selectedStyle = style("#disclosure [role='tab'][aria-selected='true']");
return {
buttonBorderWidth: Number.parseFloat(buttonStyle.borderWidth),
disabled: { borderStyle: disabledStyle.borderStyle, opacity: disabledStyle.opacity },
invalidBorderStyle: invalidStyle.borderStyle,
cardBorderWidth: Number.parseFloat(cardStyle.borderWidth),
selectedBorderWidth: Number.parseFloat(selectedStyle.borderBottomWidth),
};
});
expect(states.buttonBorderWidth).toBeGreaterThanOrEqual(2);
expect(states.disabled).toEqual({ borderStyle: "dotted", opacity: "1" });
expect(states.invalidBorderStyle).toBe("dashed");
expect(states.cardBorderWidth).toBeGreaterThanOrEqual(2);
expect(states.selectedBorderWidth).toBeGreaterThanOrEqual(3);
});
test("renders the framework smoke fixture", async ({ page, browserName }) => {
const rendering = await page.evaluate(() => {
const button = getComputedStyle(document.querySelector("#buttons .frost-button--primary"));
const card = getComputedStyle(document.querySelector("#surfaces .frost-card"));
const dialog = getComputedStyle(document.querySelector("#example-dialog"));
return {
buttonDisplay: button.display,
buttonMinHeight: Number.parseFloat(button.minHeight),
cardDisplay: card.display,
cardBorderStyle: card.borderStyle,
closedDialogDisplay: dialog.display,
};
});
expect(rendering, `${browserName} framework rendering`).toEqual({
buttonDisplay: "flex",
buttonMinHeight: 40,
cardDisplay: "block",
cardBorderStyle: "solid",
closedDialogDisplay: "none",
});
});