1
1
import React from 'react' ;
2
- import { describe , it , expect } from 'vitest' ;
2
+
3
+ import { describe , it , expect , vi } from 'vitest' ;
3
4
import { render , screen } from '@testing-library/react' ;
5
+
4
6
import '@testing-library/jest-dom' ;
5
7
6
- import { ExpandIcon } from '../../src/components/icons' ;
8
+ import { ExpandIcon } from '../../src/components/icons/ExpandIcon ' ;
7
9
import type { ThemeProps } from '../../src/types/theme' ;
8
10
9
- describe ( 'ExpandIcon' , ( ) => {
10
- const mockTheme : ThemeProps = {
11
- expandIcon : {
12
- color : '#000000' ,
13
- } ,
14
- } ;
11
+ const mockTheme : ThemeProps = {
12
+ colors : {
13
+ primaryColor : '#5D5FEF' ,
14
+ textColor : '#262626' ,
15
+ borderColor : '#E5E5E5' ,
16
+ } ,
17
+ expandIcon : {
18
+ color : '#000000' ,
19
+ } ,
20
+ } ;
15
21
16
- it ( 'renders expanded icon when isExpanded is true' , ( ) => {
22
+ describe ( 'ExpandIcon' , ( ) => {
23
+ it ( 'applies correct transform for expanded state' , ( ) => {
17
24
render ( < ExpandIcon isExpanded theme = { mockTheme } mode = "expand" /> ) ;
18
- const icon = screen . getByRole ( 'img' , { hidden : true } ) ;
19
- expect ( icon ) . toBeInTheDocument ( ) ;
20
- expect ( icon . closest ( '.expand-icon' ) ) . toHaveClass ( 'expand-icon' ) ;
25
+
26
+ const expandIcon = document . querySelector ( '.expand-icon' ) ;
27
+ expect ( expandIcon ) . toHaveStyle ( { transform : 'rotate(90deg)' } ) ;
21
28
} ) ;
22
29
23
- it ( 'renders collapsed icon when isExpanded is false ' , ( ) => {
30
+ it ( 'applies correct transform for collapsed state ' , ( ) => {
24
31
render ( < ExpandIcon isExpanded = { false } theme = { mockTheme } mode = "expand" /> ) ;
32
+
33
+ const expandIcon = document . querySelector ( '.expand-icon' ) ;
34
+ expect ( expandIcon ) . toHaveStyle ( { transform : 'rotate(0deg)' } ) ;
35
+ } ) ;
36
+
37
+ it ( 'renders SVG element' , ( ) => {
38
+ render ( < ExpandIcon isExpanded theme = { mockTheme } mode = "expand" /> ) ;
39
+
40
+ const svg = document . querySelector ( 'svg' ) ;
41
+ expect ( svg ) . toBeInTheDocument ( ) ;
42
+ expect ( svg ) . toHaveAttribute ( 'viewBox' , '0 0 24 24' ) ;
43
+ } ) ;
25
44
26
- const icon = screen . getByRole ( 'img' , { hidden : true } ) ;
27
- expect ( icon ) . toBeInTheDocument ( ) ;
28
- expect ( icon . closest ( '.expand-icon' ) ) . toHaveClass ( 'expand-icon' ) ;
45
+ it ( 'renders expand icon with SVG' , ( ) => {
46
+ render ( < ExpandIcon isExpanded theme = { mockTheme } mode = "expand" /> ) ;
47
+
48
+ const svg = document . querySelector ( 'svg' ) ;
49
+ expect ( svg ) . toBeInTheDocument ( ) ;
50
+ expect ( svg ) . toHaveAttribute ( 'width' , '24' ) ;
51
+ expect ( svg ) . toHaveAttribute ( 'height' , '24' ) ;
52
+ } ) ;
53
+
54
+ it ( 'renders collapsed icon with SVG' , ( ) => {
55
+ render ( < ExpandIcon isExpanded = { false } theme = { mockTheme } mode = "expand" /> ) ;
56
+
57
+ const svg = document . querySelector ( 'svg' ) ;
58
+ expect ( svg ) . toBeInTheDocument ( ) ;
59
+ expect ( svg ) . toHaveAttribute ( 'width' , '24' ) ;
60
+ expect ( svg ) . toHaveAttribute ( 'height' , '24' ) ;
29
61
} ) ;
30
62
31
63
it ( 'applies custom theme color when provided' , ( ) => {
32
64
const customTheme : ThemeProps = {
65
+ ...mockTheme ,
33
66
expandIcon : {
34
67
color : '#FF0000' ,
35
68
} ,
36
69
} ;
37
70
38
71
render ( < ExpandIcon isExpanded theme = { customTheme } mode = "expand" /> ) ;
39
-
40
- const icon = screen . getByRole ( 'img' , { hidden : true } ) ;
41
- expect ( icon ) . toBeInTheDocument ( ) ;
72
+
73
+ const svg = document . querySelector ( 'svg' ) ;
74
+ expect ( svg ) . toBeInTheDocument ( ) ;
75
+ expect ( svg ) . toHaveAttribute ( 'width' , '24' ) ;
76
+ expect ( svg ) . toHaveAttribute ( 'height' , '24' ) ;
42
77
} ) ;
43
78
44
79
it ( 'renders without theme color when not provided' , ( ) => {
45
- const themeWithoutColor : ThemeProps = { } ;
80
+ const themeWithoutColor : ThemeProps = {
81
+ colors : {
82
+ primaryColor : '#5D5FEF' ,
83
+ textColor : '#262626' ,
84
+ borderColor : '#E5E5E5' ,
85
+ } ,
86
+ } ;
46
87
47
88
render ( < ExpandIcon isExpanded theme = { themeWithoutColor } mode = "expand" /> ) ;
48
-
49
- const icon = screen . getByRole ( 'img' , { hidden : true } ) ;
50
- expect ( icon ) . toBeInTheDocument ( ) ;
89
+
90
+ const svg = document . querySelector ( 'svg' ) ;
91
+ expect ( svg ) . toBeInTheDocument ( ) ;
92
+ expect ( svg ) . toHaveAttribute ( 'width' , '24' ) ;
93
+ expect ( svg ) . toHaveAttribute ( 'height' , '24' ) ;
51
94
} ) ;
52
95
} ) ;
0 commit comments