|
| 1 | +import { faker } from "@faker-js/faker"; |
| 2 | +import { composeStories } from "@storybook/react"; |
| 3 | +import { render, screen } from "@testing-library/react"; |
| 4 | +import { expect, test } from "vitest"; |
| 5 | +import { fontSizes, fontWeights } from "../../tokens/typography"; |
| 6 | +import * as stories from "./Heading.stories"; |
| 7 | + |
| 8 | +const { Basic, Contrasts } = composeStories(stories); |
| 9 | + |
| 10 | +test("renders the heading with the correct text content", () => { |
| 11 | + render(<Basic>제목</Basic>); |
| 12 | + |
| 13 | + expect(screen.getByRole("heading")).toHaveTextContent("제목"); |
| 14 | +}); |
| 15 | + |
| 16 | +test.each([1, 2, 3, 4, 5, 6] as const)( |
| 17 | + "renders the correct HTML heading element for level %i", |
| 18 | + (level) => { |
| 19 | + render(<Basic level={level} />); |
| 20 | + |
| 21 | + expect(screen.getByRole("heading", { level })).toBeInTheDocument(); |
| 22 | + } |
| 23 | +); |
| 24 | + |
| 25 | +test("applies the correct font weight class based on the weight prop", () => { |
| 26 | + const weight = faker.helpers.arrayElement( |
| 27 | + Object.keys(fontWeights) |
| 28 | + ) as keyof typeof fontWeights; |
| 29 | + |
| 30 | + render(<Basic weight={weight} />); |
| 31 | + |
| 32 | + expect(screen.getByRole("heading")).toHaveClass(`fw_${weight}`); |
| 33 | +}); |
| 34 | + |
| 35 | +test("applies the correct font size class based on the size prop", () => { |
| 36 | + const size = faker.helpers.arrayElement( |
| 37 | + Object.keys(fontSizes) |
| 38 | + ) as keyof typeof fontSizes; |
| 39 | + |
| 40 | + render(<Basic size={size} />); |
| 41 | + |
| 42 | + expect(screen.getByRole("heading")).toHaveClass(`fs_${size}`); |
| 43 | +}); |
| 44 | + |
| 45 | +test("applies the correct color for low and high contrast", () => { |
| 46 | + render(<Contrasts />); |
| 47 | + |
| 48 | + expect(screen.getByRole("heading", { name: "낮은 명암비" })).toHaveClass( |
| 49 | + "c_text.muted" |
| 50 | + ); |
| 51 | + |
| 52 | + expect(screen.getByRole("heading", { name: "높은 명암비" })).toHaveClass( |
| 53 | + "c_text" |
| 54 | + ); |
| 55 | +}); |
0 commit comments