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

58 lines
1.9 KiB
TypeScript

import "@testing-library/jest-dom/vitest";
import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import DiagramGlyph, {
DIAGRAM_GLYPH_OPTIONS,
} from "../../app/components/asset/DiagramGlyph";
describe("DiagramGlyph", () => {
it("renders every glyph at 48 and 24", () => {
const { rerender } = render(
<DiagramGlyph glyph="group" size={48} />,
);
expect(document.querySelector("svg")).toHaveAttribute("width", "48");
expect(document.querySelector("svg")).toHaveAttribute("height", "48");
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
rerender(<DiagramGlyph glyph="group" size={24} />);
expect(document.querySelector("svg")).toHaveAttribute("width", "24");
expect(document.querySelector("svg")).toHaveAttribute("height", "24");
for (const glyph of DIAGRAM_GLYPH_OPTIONS) {
rerender(<DiagramGlyph glyph={glyph} />);
expect(document.querySelector("svg")).toBeInTheDocument();
}
});
it("names a diagram glyph and keeps a decorative glyph unlabeled", () => {
const { rerender } = render(
<DiagramGlyph
glyph="rotation"
title="Rotation"
description="Roles move on a set schedule."
/>,
);
expect(
screen.getByRole("img", {
name: "Rotation. Roles move on a set schedule.",
}),
).toBeInTheDocument();
rerender(<DiagramGlyph glyph="rotation" />);
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
});
it("recolors with one text class", () => {
render(
<DiagramGlyph
glyph="consensus"
className="text-[var(--color-content-default-brand-primary)]"
/>,
);
expect(document.querySelector("svg")).toHaveClass(
"text-[var(--color-content-default-brand-primary)]",
);
});
});