Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { Inbox } from "lucide-react";
|
|
import { VisitorCard, VisitorState } from "./VisitorCard";
|
|
|
|
const event = { companyName: "INS", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC" };
|
|
|
|
describe("VisitorCard", () => {
|
|
it("shows the event header in one card with one h1", () => {
|
|
render(<VisitorCard event={event}><p>body</p></VisitorCard>);
|
|
expect(screen.getByRole("main")).toBeTruthy();
|
|
expect(screen.getByText("INS").className).toContain("uppercase");
|
|
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("Expo 2026");
|
|
expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
|
expect(screen.getByText("KLCC")).toBeTruthy();
|
|
expect(screen.getByText("body")).toBeTruthy();
|
|
expect(screen.getByText(/Powered by/)).toBeTruthy();
|
|
});
|
|
it("title overrides the h1", () => {
|
|
render(<VisitorCard event={event} title="You're invited to Expo 2026" />);
|
|
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("You're invited to Expo 2026");
|
|
});
|
|
it("renders without event data", () => {
|
|
render(<VisitorCard><p>x</p></VisitorCard>);
|
|
expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("VisitorState", () => {
|
|
it("renders heading, text, action and role", () => {
|
|
render(<VisitorState icon={Inbox} heading="Gone" text="Not active" role="alert" tone="error" action={<button>Go</button>} />);
|
|
expect(screen.getByRole("alert")).toBeTruthy();
|
|
expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Gone");
|
|
expect(screen.getByText("Not active")).toBeTruthy();
|
|
expect(screen.getByRole("button", { name: "Go" })).toBeTruthy();
|
|
});
|
|
});
|