@@ -9,7 +9,7 @@ describe('<Carousel>', () => {
9
9
< Carousel . Item key = { 2 } > Item 2 content</ Carousel . Item > ,
10
10
] ;
11
11
12
- it ( 'Should show the correct item' , ( ) => {
12
+ it ( 'should show the correct item' , ( ) => {
13
13
const wrapper = mount ( < Carousel defaultActiveIndex = { 1 } > { items } </ Carousel > ) ;
14
14
15
15
const carouselItems = wrapper . find ( 'CarouselItem' ) ;
@@ -18,7 +18,7 @@ describe('<Carousel>', () => {
18
18
assert . equal ( carouselItems . at ( 1 ) . is ( '.active' ) , true ) ;
19
19
} ) ;
20
20
21
- it ( 'Should show the correct item with defaultActiveIndex' , ( ) => {
21
+ it ( 'should show the correct item with defaultActiveIndex' , ( ) => {
22
22
const wrapper = mount ( < Carousel defaultActiveIndex = { 1 } > { items } </ Carousel > ) ;
23
23
24
24
const carouselItems = wrapper . find ( 'CarouselItem' ) ;
@@ -29,7 +29,7 @@ describe('<Carousel>', () => {
29
29
wrapper . find ( '.carousel-indicators > li' ) . length . should . equal ( 2 ) ;
30
30
} ) ;
31
31
32
- it ( 'Should handle null children' , ( ) => {
32
+ it ( 'should handle null children' , ( ) => {
33
33
const wrapper = mount (
34
34
< Carousel defaultActiveIndex = { 1 } >
35
35
< Carousel . Item > Item 1 content</ Carousel . Item >
@@ -47,7 +47,7 @@ describe('<Carousel>', () => {
47
47
wrapper . find ( '.carousel-indicators > li' ) . length . should . equal ( 2 ) ;
48
48
} ) ;
49
49
50
- it ( 'Should call onSelect when indicator selected' , done => {
50
+ it ( 'should call onSelect when indicator selected' , done => {
51
51
function onSelect ( index ) {
52
52
expect ( index ) . to . equal ( 0 ) ;
53
53
@@ -66,7 +66,7 @@ describe('<Carousel>', () => {
66
66
. simulate ( 'click' ) ;
67
67
} ) ;
68
68
69
- it ( 'Should call onSelect with direction' , done => {
69
+ it ( 'should call onSelect with direction' , done => {
70
70
function onSelect ( index , direction , event ) {
71
71
expect ( index ) . to . equal ( 0 ) ;
72
72
expect ( direction ) . to . equal ( 'prev' ) ;
@@ -87,7 +87,7 @@ describe('<Carousel>', () => {
87
87
. simulate ( 'click' ) ;
88
88
} ) ;
89
89
90
- it ( 'Should show back button control on the first image if wrap is true' , ( ) => {
90
+ it ( 'should show back button control on the first image if wrap is true' , ( ) => {
91
91
const wrapper = mount (
92
92
< Carousel defaultActiveIndex = { 0 } controls wrap >
93
93
{ items }
@@ -97,7 +97,7 @@ describe('<Carousel>', () => {
97
97
wrapper . assertSingle ( 'a.carousel-control-prev' ) ;
98
98
} ) ;
99
99
100
- it ( 'Should show next button control on the last image if wrap is true' , ( ) => {
100
+ it ( 'should show next button control on the last image if wrap is true' , ( ) => {
101
101
const wrapper = mount (
102
102
< Carousel defaultActiveIndex = { 1 } controls wrap >
103
103
{ items }
@@ -107,23 +107,23 @@ describe('<Carousel>', () => {
107
107
wrapper . assertSingle ( 'a.carousel-control-next' ) ;
108
108
} ) ;
109
109
110
- it ( 'Should not show the prev button on the first image if wrap is false' , ( ) => {
110
+ it ( 'should not show the prev button on the first image if wrap is false' , ( ) => {
111
111
mount (
112
112
< Carousel defaultActiveIndex = { 0 } controls wrap = { false } >
113
113
{ items }
114
114
</ Carousel > ,
115
115
) . assertNone ( 'a.carousel-control-prev' ) ;
116
116
} ) ;
117
117
118
- it ( 'Should not show the next button on the last image if wrap is false' , ( ) => {
118
+ it ( 'should not show the next button on the last image if wrap is false' , ( ) => {
119
119
mount (
120
120
< Carousel defaultActiveIndex = { 1 } controls wrap = { false } >
121
121
{ items }
122
122
</ Carousel > ,
123
123
) . assertNone ( 'a.carousel-control-next' ) ;
124
124
} ) ;
125
125
126
- it ( 'Should allow user to specify a previous and next icon' , ( ) => {
126
+ it ( 'should allow user to specify a previous and next icon' , ( ) => {
127
127
const wrapper = mount (
128
128
< Carousel
129
129
controls
@@ -142,7 +142,7 @@ describe('<Carousel>', () => {
142
142
wrapper . assertSingle ( '.ficon-right' ) ;
143
143
} ) ;
144
144
145
- it ( 'Should allow user to specify a previous and next SR label' , ( ) => {
145
+ it ( 'should allow user to specify a previous and next SR label' , ( ) => {
146
146
const wrapper = mount (
147
147
< Carousel
148
148
controls
@@ -164,7 +164,7 @@ describe('<Carousel>', () => {
164
164
assert . equal ( labels . at ( 1 ) . text ( ) , 'Next awesomeness' ) ;
165
165
} ) ;
166
166
167
- it ( 'Should not render labels when values are falsy' , ( ) => {
167
+ it ( 'should not render labels when values are falsy' , ( ) => {
168
168
[ null , '' ] . forEach ( falsyValue => {
169
169
const wrapper = mount (
170
170
< Carousel
@@ -188,7 +188,7 @@ describe('<Carousel>', () => {
188
188
} ) ;
189
189
} ) ;
190
190
191
- it ( 'Should transition properly when slide animation is disabled' , done => {
191
+ it ( 'should transition properly when slide animation is disabled' , done => {
192
192
const spy = sinon . spy ( ) ;
193
193
const wrapper = mount (
194
194
< Carousel defaultActiveIndex = { 0 } slide = { false } onSelect = { spy } >
@@ -211,7 +211,7 @@ describe('<Carousel>', () => {
211
211
} , 150 ) ;
212
212
} ) ;
213
213
214
- it ( 'Should render on update, active item > new child length' , ( ) => {
214
+ it ( 'should render on update, active item > new child length' , ( ) => {
215
215
// default active is the 2nd item, which will be removed on
216
216
// subsequent render
217
217
let wrapper = mount ( < Carousel defaultActiveIndex = { 1 } > { items } </ Carousel > ) ;
@@ -234,8 +234,57 @@ describe('<Carousel>', () => {
234
234
wrapper . find ( 'div.carousel-item' ) . length . should . equal ( 1 ) ;
235
235
} ) ;
236
236
237
- it ( 'Should have div as default component' , ( ) => {
237
+ it ( 'should have div as default component' , ( ) => {
238
238
const wrapper = mount ( < Carousel > { items } </ Carousel > ) ;
239
239
wrapper . find ( 'div' ) . length . should . equal ( 4 ) ;
240
240
} ) ;
241
+
242
+ it ( 'should go through the items after given seconds' , ( ) => {
243
+ const clock = sinon . useFakeTimers ( ) ;
244
+
245
+ try {
246
+ const onSelectSpy = sinon . spy ( ) ;
247
+ const interval = 500 ;
248
+ mount (
249
+ < Carousel interval = { interval } onSelect = { onSelectSpy } >
250
+ { items }
251
+ </ Carousel > ,
252
+ ) ;
253
+ clock . tick ( interval * 2 ) ;
254
+ expect ( onSelectSpy ) . to . have . been . calledOnce ;
255
+ } finally {
256
+ clock . restore ( ) ;
257
+ }
258
+ } ) ;
259
+
260
+ it ( 'should handle Keyboard events' , ( ) => {
261
+ const clock = sinon . useFakeTimers ( ) ;
262
+
263
+ try {
264
+ const onSelectSpy = sinon . spy ( ) ;
265
+ const wrapper = mount (
266
+ < Carousel interval = { 0 } onSelect = { onSelectSpy } >
267
+ { items }
268
+ </ Carousel > ,
269
+ ) ;
270
+
271
+ wrapper . simulate ( 'keyDown' , {
272
+ key : 'ArrowRight' ,
273
+ } ) ;
274
+ clock . tick ( 50 ) ;
275
+ expect ( onSelectSpy ) . to . have . been . calledOnce ;
276
+ expect ( onSelectSpy . getCall ( 0 ) . args [ 0 ] ) . to . equal ( 1 ) ;
277
+
278
+ clock . tick ( 150 ) ;
279
+
280
+ wrapper . simulate ( 'keyDown' , {
281
+ key : 'ArrowLeft' ,
282
+ } ) ;
283
+ clock . tick ( 50 ) ;
284
+ expect ( onSelectSpy ) . to . have . been . calledTwice ;
285
+ expect ( onSelectSpy . getCall ( 1 ) . args [ 0 ] ) . to . equal ( 0 ) ;
286
+ } finally {
287
+ clock . restore ( ) ;
288
+ }
289
+ } ) ;
241
290
} ) ;
0 commit comments