@@ -5,18 +5,44 @@ import { describe, expect, it } from 'vitest';
5
5
import { Title } from '~/shared/ui/typography' ;
6
6
7
7
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' ) ;
12
12
} ) ;
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' , ( ) => {
14
24
render (
15
25
< Title asChild size = "h2" >
16
26
< h2 > Hello World</ h2 >
17
27
</ Title > ,
18
28
) ;
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 ) ;
21
47
} ) ;
22
48
} ) ;
0 commit comments