@@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/react';
2
2
import userEvent from '@testing-library/user-event' ;
3
3
import { FC , useState } from 'react' ;
4
4
import { describe , expect , it , vi } from 'vitest' ;
5
+ import { Flowbite } from '../Flowbite' ;
5
6
import { TextInput } from '../TextInput' ;
6
7
import { ToggleSwitch } from './ToggleSwitch' ;
7
8
@@ -127,6 +128,94 @@ describe('Components / Toggle switch', () => {
127
128
expect ( toggleSwitch ( ) ) . toHaveAttribute ( 'type' , 'submit' ) ;
128
129
} ) ;
129
130
} ) ;
131
+
132
+ describe ( 'Theme' , ( ) => {
133
+ it ( 'should use `base` classes' , ( ) => {
134
+ const theme = {
135
+ toggleSwitch : {
136
+ root : {
137
+ base : 'text-blue-100' ,
138
+ } ,
139
+ } ,
140
+ } ;
141
+ render (
142
+ < Flowbite theme = { { theme } } >
143
+ < ToggleSwitch checked = { false } label = "Enable" onChange = { console . log } type = "submit" />
144
+ </ Flowbite > ,
145
+ ) ;
146
+
147
+ expect ( toggleSwitch ( ) ) . toHaveClass ( 'text-blue-100' ) ;
148
+ } ) ;
149
+
150
+ it ( 'should use `active` classes' , ( ) => {
151
+ const theme = {
152
+ toggleSwitch : {
153
+ root : {
154
+ active : {
155
+ off : 'text-blue-200' ,
156
+ on : 'text-blue-300' ,
157
+ } ,
158
+ } ,
159
+ } ,
160
+ } ;
161
+ render (
162
+ < Flowbite theme = { { theme } } >
163
+ < ToggleSwitch checked = { false } label = "Enable" onChange = { console . log } type = "submit" />
164
+ < ToggleSwitch disabled checked = { false } label = "Enable" onChange = { console . log } type = "submit" />
165
+ </ Flowbite > ,
166
+ ) ;
167
+ const activeToggleSwitch = toggleSwitches ( ) [ 0 ] ;
168
+ const disabledToggleSwitch = toggleSwitches ( ) [ 1 ] ;
169
+
170
+ expect ( activeToggleSwitch ) . toHaveClass ( 'text-blue-300' ) ;
171
+ expect ( disabledToggleSwitch ) . toHaveClass ( 'text-blue-200' ) ;
172
+ } ) ;
173
+
174
+ it ( 'should use `label` classes' , ( ) => {
175
+ const theme = {
176
+ toggleSwitch : {
177
+ root : {
178
+ label : 'test-label' ,
179
+ } ,
180
+ } ,
181
+ } ;
182
+ render (
183
+ < Flowbite theme = { { theme } } >
184
+ < ToggleSwitch checked = { false } label = "Enable" onChange = { console . log } type = "submit" />
185
+ </ Flowbite > ,
186
+ ) ;
187
+
188
+ expect ( label ( ) ) . toHaveClass ( 'test-label' ) ;
189
+ } ) ;
190
+
191
+ it ( 'should use `toggle` classes' , ( ) => {
192
+ const theme = {
193
+ toggleSwitch : {
194
+ toggle : {
195
+ base : 'h-6 w-11' ,
196
+ checked : {
197
+ color : {
198
+ blue : 'bg-pink-700' ,
199
+ } ,
200
+ } ,
201
+ } ,
202
+ } ,
203
+ } ;
204
+ render (
205
+ < Flowbite theme = { { theme } } >
206
+ < ToggleSwitch checked label = "Enable" onChange = { console . log } type = "submit" />
207
+ </ Flowbite > ,
208
+ ) ;
209
+
210
+ expect ( toggle ( ) ) . toHaveClass ( 'h-6 w-11 bg-pink-700' ) ;
211
+ } ) ;
212
+ } ) ;
130
213
} ) ;
131
214
132
215
const toggleSwitch = ( ) => screen . getByRole ( 'switch' ) ;
216
+
217
+ const toggleSwitches = ( ) => screen . getAllByRole ( 'switch' ) ;
218
+
219
+ const label = ( ) => screen . getByTestId ( 'flowbite-toggleswitch-label' ) ;
220
+
221
+ const toggle = ( ) => screen . getByTestId ( 'flowbite-toggleswitch-toggle' ) ;
0 commit comments