@@ -8,7 +8,6 @@ import { styles } from '../styles';
8
8
import { waitForElement } from 'enzyme-async-helpers' ;
9
9
10
10
describe ( 'Switch' , ( ) => {
11
-
12
11
it ( 'should set the checked to true when checked is true' , async ( ) => {
13
12
const component = mount (
14
13
< BlueBaseApp plugins = { [ Plugin ] } >
@@ -18,11 +17,15 @@ describe('Switch', () => {
18
17
await waitForElement ( component , Switch ) ;
19
18
20
19
// expect(component).toMatchSnapshot();
21
- expect ( component . find ( 'Switch' ) . first ( ) . prop ( 'checked' ) ) . toEqual ( true ) ;
20
+ expect (
21
+ component
22
+ . find ( 'Switch' )
23
+ . first ( )
24
+ . prop ( 'checked' )
25
+ ) . toEqual ( true ) ;
22
26
} ) ;
23
27
24
28
it ( 'should have different colors in dark mode' , ( ) => {
25
-
26
29
const theme = createMuiTheme ( { palette : { type : 'dark' } } ) ;
27
30
28
31
const classes = styles ( { color : 'red' } , theme ) ;
@@ -38,7 +41,12 @@ describe('Switch', () => {
38
41
) ;
39
42
await waitForElement ( component , Switch ) ;
40
43
41
- expect ( component . find ( 'Switch' ) . first ( ) . prop ( 'checked' ) ) . toEqual ( false ) ;
44
+ expect (
45
+ component
46
+ . find ( 'Switch' )
47
+ . first ( )
48
+ . prop ( 'checked' )
49
+ ) . toEqual ( false ) ;
42
50
} ) ;
43
51
44
52
it ( 'should pass the color as is when set to "primary"' , async ( ) => {
@@ -49,7 +57,12 @@ describe('Switch', () => {
49
57
) ;
50
58
await waitForElement ( component , Switch ) ;
51
59
52
- expect ( component . find ( 'Switch' ) . first ( ) . prop ( 'color' ) ) . toEqual ( 'primary' ) ;
60
+ expect (
61
+ component
62
+ . find ( 'Switch' )
63
+ . first ( )
64
+ . prop ( 'color' )
65
+ ) . toEqual ( 'primary' ) ;
53
66
} ) ;
54
67
55
68
it ( 'should pass the color as is when set to "secondary"' , async ( ) => {
@@ -60,7 +73,12 @@ describe('Switch', () => {
60
73
) ;
61
74
await waitForElement ( component , Switch ) ;
62
75
63
- expect ( component . find ( 'Switch' ) . first ( ) . prop ( 'color' ) ) . toEqual ( 'secondary' ) ;
76
+ expect (
77
+ component
78
+ . find ( 'Switch' )
79
+ . first ( )
80
+ . prop ( 'color' )
81
+ ) . toEqual ( 'secondary' ) ;
64
82
} ) ;
65
83
66
84
it ( 'should pass the color as is when set to "default"' , async ( ) => {
@@ -71,7 +89,12 @@ describe('Switch', () => {
71
89
) ;
72
90
await waitForElement ( component , Switch ) ;
73
91
74
- expect ( component . find ( 'Switch' ) . first ( ) . prop ( 'color' ) ) . toEqual ( 'default' ) ;
92
+ expect (
93
+ component
94
+ . find ( 'Switch' )
95
+ . first ( )
96
+ . prop ( 'color' )
97
+ ) . toEqual ( 'default' ) ;
75
98
} ) ;
76
99
77
100
it ( 'should set the color prop to undefined and create classes for custom colors' , async ( ) => {
@@ -81,9 +104,13 @@ describe('Switch', () => {
81
104
</ BlueBaseApp >
82
105
) ;
83
106
await waitForElement ( component , Switch ) ;
84
- // expect(component).toMatchSnapshot();
85
- expect ( component . find ( 'WithStyles(Switch)' ) . first ( ) . prop ( 'classes' ) ) . toBeTruthy ( ) ;
86
- expect ( component . find ( 'WithStyles(Switch)' ) . first ( ) . prop ( 'color' ) ) . toEqual ( 'red' ) ;
107
+
108
+ expect (
109
+ component
110
+ . find ( 'WithStyles(Component)' )
111
+ . first ( )
112
+ . prop ( 'color' )
113
+ ) . toEqual ( 'red' ) ;
87
114
} ) ;
88
115
89
116
it ( 'should set the label component' , async ( ) => {
@@ -95,15 +122,18 @@ describe('Switch', () => {
95
122
await waitForElement ( component , Switch ) ;
96
123
// expect(component).toMatchSnapshot();
97
124
expect ( component . find ( 'FormControlLabel' ) . length ) . toBeGreaterThan ( 0 ) ;
98
- expect ( component . find ( 'FormControlLabel' ) . first ( ) . prop ( 'label' ) ) . toEqual ( 'Foo' ) ;
125
+ expect (
126
+ component
127
+ . find ( 'FormControlLabel' )
128
+ . first ( )
129
+ . prop ( 'label' )
130
+ ) . toEqual ( 'Foo' ) ;
99
131
} ) ;
100
132
101
133
it ( 'should map onValueChange fn to onChange fn' , async ( ) => {
102
-
103
134
const cb = jest . fn ( ) ;
104
135
const component = mount (
105
136
< BlueBaseApp plugins = { [ Plugin ] } >
106
-
107
137
< Switch label = "Foo" onValueChange = { cb } />
108
138
</ BlueBaseApp >
109
139
) ;
@@ -119,11 +149,9 @@ describe('Switch', () => {
119
149
} ) ;
120
150
121
151
it ( 'should map onValueChange fn to onChange fn with value' , async ( ) => {
122
-
123
152
const cb = jest . fn ( ) ;
124
153
const component = mount (
125
154
< BlueBaseApp plugins = { [ Plugin ] } >
126
-
127
155
< Switch label = "Foo" value = "foo" onValueChange = { cb } />
128
156
</ BlueBaseApp >
129
157
) ;
@@ -140,27 +168,25 @@ describe('Switch', () => {
140
168
} ) ;
141
169
142
170
it ( 'should pass onChange as is if available' , async ( ) => {
143
-
144
171
const cb = jest . fn ( ) ;
145
172
146
173
const SWITCH = Switch as any ;
147
174
148
175
const component = mount (
149
176
< BlueBaseApp plugins = { [ Plugin ] } >
150
-
151
177
< SWITCH label = "Foo" onChange = { cb } />
152
178
</ BlueBaseApp >
153
179
) ;
154
180
await waitForElement ( component , SWITCH ) ;
155
- const onChange = component . find ( 'Switch' ) . first ( ) . prop ( 'onChange' ) as any ;
181
+ const onChange = component
182
+ . find ( 'Switch' )
183
+ . first ( )
184
+ . prop ( 'onChange' ) as any ;
156
185
157
186
onChange ( 'foo' , true ) ;
158
187
159
188
// expect(component).toMatchSnapshot();
160
189
expect ( cb ) . toBeCalledTimes ( 1 ) ;
161
190
expect ( cb ) . toBeCalledWith ( 'foo' , true ) ;
162
191
} ) ;
163
-
164
192
} ) ;
165
-
166
-
0 commit comments