Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,38 @@
import { afterAll, describe, expect, vi } from "vitest";
import { createElement, type ReactElement, type ReactNode } from "react";
// Capture the elements that the template hands to the (mocked) axe helper so
// the suite stays fast and deterministic: this file only exercises the
// component-name resolution, not real axe-core.
const captured: ReactElement[] = [];
vi.mock("../../test-setup/axe.js", () => ({
expectNoAxeViolations: vi.fn(async (ui: ReactElement) => {
captured.push(ui);
}),
}));
import { generateA11yTest } from "./a11y-template.js";
// A component that is callable but exposes neither a `displayName` nor a
// (defined) `name`, forcing the resolver's final `?? "Component"` fallback —
// the one branch the existing suite (which uses an empty-string name) never
// reaches, because `"" ?? x` short-circuits to the empty string.
const Anonymous = Object.defineProperty(
(props: { readonly children?: ReactNode }) => createElement("p", null, props.children),
"name",
{ value: undefined },
);
describe("generateA11yTest with an anonymous component", () => {
generateA11yTest(Anonymous, { children: "anon" });
afterAll(() => {
// The template must still register exactly one axe assertion bound to the
// anonymous component, i.e. the missing name does not break generation.
expect(Anonymous.name).toBeUndefined();
expect(captured).toHaveLength(1);
expect(captured[0]?.type).toBe(Anonymous);
expect(captured[0]?.props).toMatchObject({ children: "anon" });
});
});
@@ -10,7 +10,7 @@
* keyboard-navigation behaviour.
*
* The helper intentionally lives in the public test-utils tree so that
* consumer packages (apps/web, apps/storybook) can re-use the same template
* consumer packages such as apps/web can re-use the same template
* without copying boilerplate.
*/
import type { ComponentType, ComponentProps, ReactNode } from "react";
@@ -0,0 +1,73 @@
import { afterEach, describe, expect, test } from "vitest";
import { createElement } from "react";
import { expectNoAxeViolations, runAxe } from "../../test-setup/axe.js";
// axe-core wants its context node connected to the document, so mount fixtures
// into <body> and tear them down between cases to avoid cross-test bleed.
const mounted: HTMLElement[] = [];
function mount(html: string): HTMLElement {
const host = document.createElement("div");
host.innerHTML = html;
document.body.appendChild(host);
mounted.push(host);
return host;
}
afterEach(() => {
for (const host of mounted.splice(0)) host.remove();
});
const IMAGE_WITHOUT_ALT = '<img src="https://example.com/logo.png">';
describe("runAxe", () => {
test("reports no violations for accessible markup under the default WCAG preset", async () => {
const result = await runAxe(mount('<button type="button">Save</button>'));
expect(result.violations).toHaveLength(0);
});
test("flags an image missing its alt attribute (image-alt, WCAG level A)", async () => {
const result = await runAxe(mount(IMAGE_WITHOUT_ALT));
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(true);
});
test("honours a per-rule override that disables a default rule", async () => {
const result = await runAxe(mount(IMAGE_WITHOUT_ALT), {
rules: { "image-alt": { enabled: false } },
});
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(false);
});
test("honours a custom tag set that excludes the failing rule", async () => {
// `image-alt` is a WCAG-2.0 level-A rule; restricting the run to AAA tags
// means it is never evaluated, so the missing-alt image now passes.
const result = await runAxe(mount(IMAGE_WITHOUT_ALT), { tags: ["wcag2aaa"] });
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(false);
});
});
describe("expectNoAxeViolations", () => {
test("resolves without throwing when the rendered element is accessible", async () => {
await expect(
expectNoAxeViolations(createElement("button", { type: "button" }, "Save")),
).resolves.toBeUndefined();
});
test("throws a formatted error and attaches the raw axe result as the cause", async () => {
const badImage = createElement("img", { src: "https://example.com/logo.png" });
await expect(expectNoAxeViolations(badImage)).rejects.toThrow(/violation\(s\)/);
let thrown: unknown;
try {
await expectNoAxeViolations(badImage);
} catch (error) {
thrown = error;
}
expect(thrown).toBeInstanceOf(Error);
expect((thrown as Error).message).toContain("image-alt");
const cause = (thrown as { cause?: { violations?: ReadonlyArray<{ id: string }> } }).cause;
expect(cause?.violations?.some((violation) => violation.id === "image-alt")).toBe(true);
});
});