1
1
import { render , screen , waitFor } from '@testing-library/react' ;
2
2
import userEvent from '@testing-library/user-event' ;
3
3
import { FC , useState } from 'react' ;
4
- import { HiEye , HiInformationCircle } from 'react-icons/hi' ;
4
+ import { HiEye , HiHeart , HiInformationCircle } from 'react-icons/hi' ;
5
5
import { describe , expect , it , vi } from 'vitest' ;
6
- import { Alert } from './Alert' ;
6
+ import { Flowbite } from '../Flowbite' ;
7
+
8
+ import { Alert , AlertProps } from './Alert' ;
7
9
8
10
describe . concurrent ( 'Components / Alert' , ( ) => {
9
11
describe . concurrent ( 'A11y' , ( ) => {
@@ -12,6 +14,122 @@ describe.concurrent('Components / Alert', () => {
12
14
13
15
expect ( alert ( ) ) . toBeInTheDocument ( ) ;
14
16
} ) ;
17
+
18
+ describe ( 'Theme' , ( ) => {
19
+ it ( 'should use custom `base` classes' , ( ) => {
20
+ const theme = {
21
+ alert : {
22
+ root : {
23
+ base : 'text-purple-100' ,
24
+ } ,
25
+ } ,
26
+ } ;
27
+ render (
28
+ < Flowbite theme = { { theme } } >
29
+ < TestAlert />
30
+ </ Flowbite > ,
31
+ ) ;
32
+
33
+ expect ( alert ( ) ) . toHaveClass ( 'text-purple-100' ) ;
34
+ } ) ;
35
+
36
+ it ( 'should use custom `borderAccent` classes' , ( ) => {
37
+ const theme = {
38
+ alert : {
39
+ root : {
40
+ borderAccent : 'border-t-4 border-purple-500' ,
41
+ } ,
42
+ } ,
43
+ } ;
44
+ render (
45
+ < Flowbite theme = { { theme } } >
46
+ < TestAlert withBorderAccent />
47
+ </ Flowbite > ,
48
+ ) ;
49
+
50
+ expect ( alert ( ) ) . toHaveClass ( 'border-t-4 border-purple-500' ) ;
51
+ } ) ;
52
+
53
+ it ( 'should use custom `wrapper` classes' , ( ) => {
54
+ const theme = {
55
+ alert : {
56
+ root : {
57
+ wrapper : 'flex items-center' ,
58
+ } ,
59
+ } ,
60
+ } ;
61
+ render (
62
+ < Flowbite theme = { { theme } } >
63
+ < TestAlert />
64
+ </ Flowbite > ,
65
+ ) ;
66
+
67
+ expect ( wrapper ( ) ) . toHaveClass ( 'flex items-center' ) ;
68
+ } ) ;
69
+
70
+ it ( 'should use custom `color` classes' , ( ) => {
71
+ const theme = {
72
+ alert : {
73
+ root : {
74
+ color : {
75
+ info : 'text-purple-700 bg-purple-100 border-purple-500 dark:bg-purple-200 dark:text-purple-800' ,
76
+ } ,
77
+ } ,
78
+ closeButton : {
79
+ color : {
80
+ info : 'text-purple-500 hover:bg-purple-200 dark:text-purple-600 dark:hover:text-purple-300' ,
81
+ } ,
82
+ } ,
83
+ } ,
84
+ } ;
85
+ render (
86
+ < Flowbite theme = { { theme } } >
87
+ < TestAlert />
88
+ </ Flowbite > ,
89
+ ) ;
90
+
91
+ expect ( alert ( ) ) . toHaveClass (
92
+ 'text-purple-700 bg-purple-100 border-purple-500 dark:bg-purple-200 dark:text-purple-800' ,
93
+ ) ;
94
+ expect ( dismiss ( ) ) . toHaveClass (
95
+ 'text-purple-500 hover:bg-purple-200 dark:text-purple-600 dark:hover:text-purple-300' ,
96
+ ) ;
97
+ } ) ;
98
+
99
+ it ( 'should use custom `icon`' , ( ) => {
100
+ const theme = {
101
+ alert : {
102
+ root : {
103
+ icon : 'alert-custom-icon' ,
104
+ } ,
105
+ } ,
106
+ } ;
107
+ render (
108
+ < Flowbite theme = { { theme } } >
109
+ < TestAlert icon = { HiHeart } />
110
+ </ Flowbite > ,
111
+ ) ;
112
+
113
+ expect ( icon ( ) ) . toHaveClass ( 'alert-custom-icon' ) ;
114
+ } ) ;
115
+
116
+ it ( 'should show custom `rounded` class' , ( ) => {
117
+ const theme = {
118
+ alert : {
119
+ root : {
120
+ rounded : 'rounded' ,
121
+ } ,
122
+ } ,
123
+ } ;
124
+ render (
125
+ < Flowbite theme = { { theme } } >
126
+ < TestAlert />
127
+ </ Flowbite > ,
128
+ ) ;
129
+
130
+ expect ( alert ( ) ) . toHaveClass ( 'rounded' ) ;
131
+ } ) ;
132
+ } ) ;
15
133
} ) ;
16
134
17
135
describe . concurrent ( 'Keyboard interactions' , ( ) => {
@@ -45,11 +163,12 @@ describe.concurrent('Components / Alert', () => {
45
163
} ) ;
46
164
} ) ;
47
165
48
- const TestAlert : FC = ( ) => {
166
+ const TestAlert : FC < AlertProps > = ( props : AlertProps ) => {
49
167
const [ isDismissed , setDismissed ] = useState ( false ) ;
50
168
51
169
return (
52
170
< Alert
171
+ { ...props }
53
172
additionalContent = {
54
173
< >
55
174
< div className = "mt-2 mb-4 text-sm text-blue-700 dark:text-blue-800" >
@@ -86,4 +205,8 @@ const TestAlert: FC = () => {
86
205
87
206
const alert = ( ) => screen . getByRole ( 'alert' ) ;
88
207
208
+ const wrapper = ( ) => screen . getByTestId ( 'flowbite-alert-wrapper' ) ;
209
+
210
+ const icon = ( ) => screen . getByTestId ( 'flowbite-alert-icon' ) ;
211
+
89
212
const dismiss = ( ) => screen . getByLabelText ( 'Dismiss' ) ;
0 commit comments