|
| 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 "./Text.stories"; |
| 7 | + |
| 8 | +const { Basic, Tones, Contrasts } = composeStories(stories); |
| 9 | + |
| 10 | +test("renders the heading with the correct text content", () => { |
| 11 | + render(<Basic>ํ
์คํธ</Basic>); |
| 12 | + |
| 13 | + expect(screen.getByText("ํ
์คํธ")); |
| 14 | +}); |
| 15 | + |
| 16 | +test("applies the correct font weight class based on the weight prop", () => { |
| 17 | + const weight = faker.helpers.arrayElement( |
| 18 | + Object.keys(fontWeights) |
| 19 | + ) as keyof typeof fontWeights; |
| 20 | + |
| 21 | + render(<Basic weight={weight} />); |
| 22 | + |
| 23 | + expect(screen.getByText("๋ณธ๋ฌธ")).toHaveClass(`fw_${weight}`); |
| 24 | +}); |
| 25 | + |
| 26 | +test("applies the correct font size class based on the size prop", () => { |
| 27 | + const size = faker.helpers.arrayElement( |
| 28 | + Object.keys(fontSizes) |
| 29 | + ) as keyof typeof fontSizes; |
| 30 | + |
| 31 | + render(<Basic size={size} />); |
| 32 | + |
| 33 | + expect(screen.getByText("๋ณธ๋ฌธ")).toHaveClass(`fs_${size}`); |
| 34 | +}); |
| 35 | + |
| 36 | +test("applies the correct color based on the tone", () => { |
| 37 | + render(<Tones />); |
| 38 | + |
| 39 | + expect(screen.getByText("์ค๋ฆฝ ์์กฐ")).toHaveClass("c_text"); |
| 40 | + |
| 41 | + expect(screen.getByText("๊ฐ์กฐ ์์กฐ")).toHaveClass("c_text.accent"); |
| 42 | + |
| 43 | + expect(screen.getByText("์ํ ์์กฐ")).toHaveClass("c_text.danger"); |
| 44 | + |
| 45 | + expect(screen.getByText("๊ฒฝ๊ณ ์์กฐ")).toHaveClass("c_text.warning"); |
| 46 | +}); |
| 47 | + |
| 48 | +test("applies the correct color for low and high contrast", () => { |
| 49 | + render(<Contrasts />); |
| 50 | + |
| 51 | + expect(screen.getByText("๋ฎ์ ๋ช
์๋น")).toHaveClass("c_text.muted"); |
| 52 | + |
| 53 | + expect(screen.getByText("๋์ ๋ช
์๋น")).toHaveClass("c_text"); |
| 54 | +}); |
0 commit comments