|
| 1 | +import { afterEach, describe, expect, it } from "vitest"; |
| 2 | +import { cleanup, render, screen } from "@testing-library/react"; |
| 3 | +import { Alert, AlertTitle, AlertDescription } from "./alert"; |
| 4 | + |
| 5 | +afterEach(() => { |
| 6 | + cleanup(); |
| 7 | +}); |
| 8 | + |
| 9 | +describe("Alert", () => { |
| 10 | + describe("snapshots", () => { |
| 11 | + it("default variant", () => { |
| 12 | + const { container } = render( |
| 13 | + <Alert> |
| 14 | + <AlertTitle>Title</AlertTitle> |
| 15 | + <AlertDescription>Description</AlertDescription> |
| 16 | + </Alert>, |
| 17 | + ); |
| 18 | + expect(container.innerHTML).toMatchSnapshot(); |
| 19 | + }); |
| 20 | + |
| 21 | + it("success variant", () => { |
| 22 | + const { container } = render( |
| 23 | + <Alert variant="success"> |
| 24 | + <AlertTitle>Success</AlertTitle> |
| 25 | + <AlertDescription>Operation completed</AlertDescription> |
| 26 | + </Alert>, |
| 27 | + ); |
| 28 | + expect(container.innerHTML).toMatchSnapshot(); |
| 29 | + }); |
| 30 | + |
| 31 | + it("error variant", () => { |
| 32 | + const { container } = render( |
| 33 | + <Alert variant="error"> |
| 34 | + <AlertTitle>Error</AlertTitle> |
| 35 | + <AlertDescription>Something went wrong</AlertDescription> |
| 36 | + </Alert>, |
| 37 | + ); |
| 38 | + expect(container.innerHTML).toMatchSnapshot(); |
| 39 | + }); |
| 40 | + |
| 41 | + it("neutral variant", () => { |
| 42 | + const { container } = render( |
| 43 | + <Alert variant="neutral"> |
| 44 | + <AlertTitle>Info</AlertTitle> |
| 45 | + <AlertDescription>Note this</AlertDescription> |
| 46 | + </Alert>, |
| 47 | + ); |
| 48 | + expect(container.innerHTML).toMatchSnapshot(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it("renders with role=alert", () => { |
| 53 | + render(<Alert>Content</Alert>); |
| 54 | + expect(screen.getByRole("alert")).toBeDefined(); |
| 55 | + }); |
| 56 | + |
| 57 | + it("renders title and description", () => { |
| 58 | + render( |
| 59 | + <Alert> |
| 60 | + <AlertTitle>Test Title</AlertTitle> |
| 61 | + <AlertDescription>Test Description</AlertDescription> |
| 62 | + </Alert>, |
| 63 | + ); |
| 64 | + expect(screen.getByText("Test Title")).toBeDefined(); |
| 65 | + expect(screen.getByText("Test Description")).toBeDefined(); |
| 66 | + }); |
| 67 | + |
| 68 | + it("accepts custom className", () => { |
| 69 | + render(<Alert className="astw:mt-4">Content</Alert>); |
| 70 | + const alert = screen.getByRole("alert"); |
| 71 | + expect(alert.className).toContain("astw:mt-4"); |
| 72 | + }); |
| 73 | +}); |
0 commit comments