Files
community-rule/tests/components/PatternGlyph.test.tsx
T

56 lines
1.8 KiB
TypeScript

import "@testing-library/jest-dom/vitest";
import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import PatternGlyph, {
PATTERN_GLYPH_OPTIONS,
} from "../../app/components/asset/PatternGlyph";
describe("PatternGlyph", () => {
it("renders every glyph at 48 and 24", () => {
const { rerender } = render(
<PatternGlyph glyph="lazy-consensus" size={48} />,
);
expect(document.querySelector("svg")).toHaveAttribute("width", "48");
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
rerender(<PatternGlyph glyph="lazy-consensus" size={24} />);
expect(document.querySelector("svg")).toHaveAttribute("width", "24");
for (const glyph of PATTERN_GLYPH_OPTIONS) {
rerender(<PatternGlyph glyph={glyph} />);
expect(document.querySelector("svg")).toBeInTheDocument();
}
});
it("names a diagram glyph and keeps a decorative glyph unlabeled", () => {
const { rerender } = render(
<PatternGlyph
glyph="conflict-council"
title="Conflict council"
description="Named members hear what the first steps could not settle."
/>,
);
expect(
screen.getByRole("img", {
name: "Conflict council. Named members hear what the first steps could not settle.",
}),
).toBeInTheDocument();
rerender(<PatternGlyph glyph="conflict-council" />);
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
});
it("recolors with one text class", () => {
render(
<PatternGlyph
glyph="full-consensus"
className="text-[var(--color-content-default-brand-primary)]"
/>,
);
expect(document.querySelector("svg")).toHaveClass(
"text-[var(--color-content-default-brand-primary)]",
);
});
});