|
| 1 | +// @vitest-environment jsdom |
| 2 | +import { describe, it, expect } from "vitest" |
| 3 | +import { render, screen } from "@testing-library/react" |
| 4 | +import { AnimatedText } from "@/components/ui/animated-text" |
| 5 | + |
| 6 | +describe("AnimatedText", () => { |
| 7 | + it("splits text into individual word spans", () => { |
| 8 | + const { container } = render(<AnimatedText text="Hello World" />) |
| 9 | + const spans = container.querySelectorAll("span") |
| 10 | + expect(spans.length).toBe(2) |
| 11 | + expect(spans[0]).toHaveTextContent("Hello") |
| 12 | + expect(spans[1]).toHaveTextContent("World") |
| 13 | + }) |
| 14 | + |
| 15 | + it("renders as h1 by default", () => { |
| 16 | + const { container } = render(<AnimatedText text="Title" />) |
| 17 | + const h1 = container.querySelector("h1") |
| 18 | + expect(h1).toBeInTheDocument() |
| 19 | + expect(h1).toHaveTextContent("Title") |
| 20 | + }) |
| 21 | + |
| 22 | + it("renders as specified tag via as prop", () => { |
| 23 | + const { container } = render(<AnimatedText text="Subtitle" as="h2" />) |
| 24 | + const h2 = container.querySelector("h2") |
| 25 | + expect(h2).toBeInTheDocument() |
| 26 | + expect(h2).toHaveTextContent("Subtitle") |
| 27 | + }) |
| 28 | + |
| 29 | + it("applies className to outer tag", () => { |
| 30 | + const { container } = render(<AnimatedText text="Styled" className="text-lg font-bold" />) |
| 31 | + const h1 = container.querySelector("h1") |
| 32 | + expect(h1).toHaveClass("text-lg") |
| 33 | + expect(h1).toHaveClass("font-bold") |
| 34 | + }) |
| 35 | + |
| 36 | + it("filters empty words from multiple spaces", () => { |
| 37 | + const { container } = render(<AnimatedText text=" A B " />) |
| 38 | + const spans = container.querySelectorAll("span") |
| 39 | + expect(spans.length).toBe(2) |
| 40 | + expect(spans[0]).toHaveTextContent("A") |
| 41 | + expect(spans[1]).toHaveTextContent("B") |
| 42 | + }) |
| 43 | +}) |
0 commit comments