|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | + |
| 4 | +import { Callout, type Contents } from "./index"; |
| 5 | + |
| 6 | +describe("Callout", () => { |
| 7 | + it("should render title and icon", () => { |
| 8 | + render(<Callout title="Test Title" iconId="info" className="test-class" />); |
| 9 | + |
| 10 | + expect(screen.getByText("Test Title")).toBeInTheDocument(); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should render flat string contents as list items", () => { |
| 14 | + const contents: Contents[] = ["Item 1", "Item 2", "Item 3"]; |
| 15 | + |
| 16 | + render(<Callout title="Title" iconId="info" className="test" contents={contents} />); |
| 17 | + |
| 18 | + expect(screen.getByText("Item 1")).toBeInTheDocument(); |
| 19 | + expect(screen.getByText("Item 2")).toBeInTheDocument(); |
| 20 | + expect(screen.getByText("Item 3")).toBeInTheDocument(); |
| 21 | + |
| 22 | + const listItems = document.querySelectorAll("li"); |
| 23 | + expect(listItems).toHaveLength(3); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should render nested Contents objects with recursive lists", () => { |
| 27 | + const contents: Contents[] = [ |
| 28 | + { |
| 29 | + msg: "Parent", |
| 30 | + children: ["Child 1", "Child 2"], |
| 31 | + }, |
| 32 | + ]; |
| 33 | + |
| 34 | + render(<Callout title="Title" iconId="info" className="test" contents={contents} />); |
| 35 | + |
| 36 | + expect(screen.getByText("Parent")).toBeInTheDocument(); |
| 37 | + expect(screen.getByText("Child 1")).toBeInTheDocument(); |
| 38 | + expect(screen.getByText("Child 2")).toBeInTheDocument(); |
| 39 | + |
| 40 | + const nestedList = document.querySelectorAll("ul ul"); |
| 41 | + expect(nestedList).toHaveLength(1); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should render with no contents and no list", () => { |
| 45 | + const { container } = render(<Callout title="Title" iconId="info" className="test" />); |
| 46 | + |
| 47 | + expect(container.querySelector(".callout-contents")).not.toBeInTheDocument(); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should apply className to root element", () => { |
| 51 | + const { container } = render(<Callout title="Title" iconId="info" className="my-class" />); |
| 52 | + |
| 53 | + expect(container.querySelector(".todoist-callout.my-class")).toBeInTheDocument(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments