Skip to content

Commit d8a0fa7

Browse files
committed
test: typography 테스트 케이스 추가
1 parent 5e31047 commit d8a0fa7

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/shared/ui/__tests__/typography.test.tsx

+33-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,44 @@ import { describe, expect, it } from 'vitest';
55
import { Title } from '~/shared/ui/typography';
66

77
describe('typography component', () => {
8-
it('should render title', () => {
9-
render(<Title size="h1">Hello World</Title>);
10-
const titleElement = screen.getByText('Hello World');
11-
expect(titleElement).toBeInTheDocument();
8+
it('should render a h1 element by default', () => {
9+
render(<Title>Hello World</Title>);
10+
const heading = screen.getByRole('heading');
11+
expect(heading.tagName).toBe('H1');
1212
});
13-
it('should render h2 element', () => {
13+
it('should apply the correct variant classes', () => {
14+
render(<Title variant="primary">Hello World</Title>);
15+
const heading = screen.getByRole('heading');
16+
expect(heading).toHaveClass('text-primary');
17+
});
18+
it('should apply the correct size classes', () => {
19+
render(<Title size="h2">Hello World</Title>);
20+
const heading = screen.getByRole('heading');
21+
expect(heading).toHaveClass('tracking-tight font-semibold text-3xl md:text-4xl');
22+
});
23+
it('should render as a child component with a custom tag', () => {
1424
render(
1525
<Title asChild size="h2">
1626
<h2>Hello World</h2>
1727
</Title>,
1828
);
19-
const titleElement = screen.getByText('Hello World');
20-
expect(titleElement.tagName).toBe('H2');
29+
const heading = screen.getByRole('heading');
30+
expect(heading.tagName).toBe('H2');
31+
});
32+
it('should apply additional class names', () => {
33+
render(
34+
<Title variant="primary" size="h1" className="text-center text-secondary">
35+
Hello World
36+
</Title>,
37+
);
38+
const heading = screen.getByRole('heading');
39+
expect(heading).toHaveClass(
40+
'tracking-tight font-extrabold text-4xl md:text-5xl text-center text-secondary',
41+
);
42+
});
43+
it('should forward a ref to the DOM element', () => {
44+
const ref = createRef<HTMLHeadingElement>();
45+
render(<Title ref={ref}>Hello World</Title>);
46+
expect(ref.current).toBeInstanceOf(HTMLHeadingElement);
2147
});
2248
});

src/shared/ui/typography.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const titleVariants = cva(null, {
1111
primary: 'text-primary',
1212
},
1313
size: {
14-
h1: 'leading-tight tracking-tight font-extrabold text-4xl md:text-5xl',
15-
h2: 'leading-tight tracking-tight font-semibold text-3xl md:text-4xl',
14+
h1: 'tracking-tight font-extrabold text-4xl md:text-5xl',
15+
h2: 'tracking-tight font-semibold text-3xl md:text-4xl',
1616
h3: 'tracking-tight font-semibold text-2xl md:text-3xl',
1717
h4: 'font-semibold text-xl md:text-2xl',
1818
},

0 commit comments

Comments
 (0)