Files
Reactive-Resume/packages/ui/src/components/alert.test.tsx
T
Amruth Pillai 6a01207b6b test: add unit and component tests across the monorepo
Adds ~1000 tests to bring the previously-untested packages and apps
under coverage:

- packages/utils — string, color, date, file, level, locale, sanitize,
  field, html, network-icons, rate-limit, url, url-security, monorepo,
  resume/patch, resume/docx/link-utils, style helpers (~97% on the
  testable utility files)
- packages/ui — 28 component test files plus the use-controlled-state,
  use-mobile, use-confirm, use-prompt hooks (95% statements)
- packages/pdf — shared template helpers (filtering, columns, picture,
  metrics, section-links, page-size, rich-text-html, section-title)
- packages/schema — resumeDataSchema, page, templates, default
- packages/fonts — expanded coverage on font helpers
- packages/ai — resume sanitize and extraction template
- packages/api — resume-access-policy
- apps/web — error-message, locale, theme, pwa, dialogs/store, and
  the resume/move-item / section-actions / make-section-item helpers

Adds jsdom polyfills (ResizeObserver, IntersectionObserver,
scrollIntoView, matchMedia) and an explicit React Testing Library
cleanup hook to vitest.setup.ts so portal- and overlay-based components
work without per-test setup.
2026-05-10 20:00:07 +02:00

76 lines
2.3 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { Alert, AlertAction, AlertDescription, AlertTitle } from "./alert";
describe("Alert", () => {
it("renders children with role='alert'", () => {
render(<Alert>Heads up!</Alert>);
expect(screen.getByRole("alert")).toHaveTextContent("Heads up!");
});
it("applies data-slot='alert' for slotting", () => {
render(<Alert>x</Alert>);
expect(screen.getByRole("alert")).toHaveAttribute("data-slot", "alert");
});
it("merges custom className", () => {
render(<Alert className="my-class">x</Alert>);
expect(screen.getByRole("alert")).toHaveClass("my-class");
});
it("supports destructive variant", () => {
render(<Alert variant="destructive">x</Alert>);
// We just verify the component renders without error
expect(screen.getByRole("alert")).toBeInTheDocument();
});
});
describe("AlertTitle", () => {
it("renders children", () => {
render(<AlertTitle>Title</AlertTitle>);
expect(screen.getByText("Title")).toBeInTheDocument();
});
it("applies data-slot='alert-title'", () => {
render(<AlertTitle>x</AlertTitle>);
expect(screen.getByText("x")).toHaveAttribute("data-slot", "alert-title");
});
});
describe("AlertDescription", () => {
it("renders children", () => {
render(<AlertDescription>Description text</AlertDescription>);
expect(screen.getByText("Description text")).toBeInTheDocument();
});
it("applies data-slot='alert-description'", () => {
render(<AlertDescription>x</AlertDescription>);
expect(screen.getByText("x")).toHaveAttribute("data-slot", "alert-description");
});
});
describe("AlertAction", () => {
it("renders children", () => {
render(<AlertAction>Action</AlertAction>);
expect(screen.getByText("Action")).toBeInTheDocument();
});
it("applies data-slot='alert-action'", () => {
render(<AlertAction>x</AlertAction>);
expect(screen.getByText("x")).toHaveAttribute("data-slot", "alert-action");
});
});
describe("Alert composition", () => {
it("composes all subcomponents", () => {
render(
<Alert>
<AlertTitle>Title</AlertTitle>
<AlertDescription>Body</AlertDescription>
<AlertAction>OK</AlertAction>
</Alert>,
);
expect(screen.getByRole("alert")).toHaveTextContent(/TitleBodyOK/);
});
});