1
- import React from 'react' ;
1
+ /* global it, describe, expect, jasmine, done, jest */
2
+
3
+ import React from 'react' ; // eslint-disable-line no-unused-vars
2
4
import moment from 'moment' ;
3
5
import utils from './testUtils' ;
4
6
@@ -11,6 +13,42 @@ describe('Datetime', () => {
11
13
expect ( component . find ( '.rdt > .rdtPicker' ) . length ) . toEqual ( 1 ) ;
12
14
} ) ;
13
15
16
+ it ( 'viewMode=days: renders days, week days, month, year' , ( ) => {
17
+ const date = new Date ( 2000 , 0 , 15 , 2 , 2 , 2 , 2 ) ,
18
+ component = utils . createDatetime ( { viewMode : 'days' , defaultValue : date } ) ;
19
+ utils . openDatepicker ( component ) ;
20
+
21
+ // Month and year
22
+ expect ( component . find ( '.rdtSwitch' ) . text ( ) ) . toEqual ( 'January 2000' ) ;
23
+
24
+ // Week days
25
+ const expectedWeekDays = [ 'Su' , 'Mo' , 'Tu' , 'We' , 'Th' , 'Fr' , 'Sa' ] ,
26
+ actualWeekdays = component . find ( '.rdtDays .dow' ) . map ( ( element ) =>
27
+ element . text ( )
28
+ ) ;
29
+ expect ( actualWeekdays ) . toEqual ( expectedWeekDays ) ;
30
+
31
+ // Dates
32
+ // "Old" dates belonging to prev month
33
+ const oldDatesIndexes = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
34
+ oldDatesIndexes . forEach ( ( index ) => {
35
+ expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtOld' ) ) . toBeTruthy ( ) ;
36
+ } ) ;
37
+
38
+ // Dates belonging to current month
39
+ for ( let i = 6 ; i < 37 ; i ++ ) {
40
+ expect ( utils . getNthDay ( component , i ) . hasClass ( 'rdtDay' ) ) . toBeTruthy ( ) ;
41
+ expect ( utils . getNthDay ( component , i ) . hasClass ( 'rdtOld' ) ) . toBeFalsy ( ) ;
42
+ expect ( utils . getNthDay ( component , i ) . hasClass ( 'rdtNew' ) ) . toBeFalsy ( ) ;
43
+ }
44
+
45
+ // "New" dates belonging to next month
46
+ const nextDatesIndexes = [ 37 , 38 , 39 , 40 , 41 ] ;
47
+ nextDatesIndexes . forEach ( ( index ) => {
48
+ expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtNew' ) ) . toBeTruthy ( ) ;
49
+ } ) ;
50
+ } ) ;
51
+
14
52
it ( 'switch from day view to time view and back' , ( ) => {
15
53
const component = utils . createDatetime ( { } ) ;
16
54
@@ -187,10 +225,10 @@ describe('Datetime', () => {
187
225
188
226
utils . openDatepicker ( component ) ;
189
227
190
- prevMonthDaysIndexes . forEach ( function ( index ) {
228
+ prevMonthDaysIndexes . forEach ( ( index ) => {
191
229
expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtOld' ) ) . toBeTruthy ( ) ;
192
230
} ) ;
193
- nextMonthDaysIndexes . forEach ( function ( index ) {
231
+ nextMonthDaysIndexes . forEach ( ( index ) => {
194
232
expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtNew' ) ) . toBeTruthy ( ) ;
195
233
} ) ;
196
234
} ) ;
@@ -206,6 +244,17 @@ describe('Datetime', () => {
206
244
expect ( utils . getNthDay ( component , 36 ) . hasClass ( 'rdtActive' ) ) . toBeTruthy ( ) ;
207
245
} ) ;
208
246
247
+ it ( 'sets CSS class on today date' , ( ) => {
248
+ const specificDate = moment ( '2015-04-19' ) ,
249
+ component = utils . createDatetime ( { defaultValue : specificDate } ) ;
250
+
251
+ // Mock the today date
252
+ jasmine . clock ( ) . mockDate ( specificDate . toDate ( ) ) ;
253
+
254
+ utils . openDatepicker ( component ) ;
255
+ expect ( component . find ( '.rdtDay.rdtToday' ) . text ( ) ) . toEqual ( '19' ) ;
256
+ } ) ;
257
+
209
258
// Proof of bug
210
259
it ( 'should show correct selected month when traversing view modes' , ( ) => {
211
260
const date = new Date ( 2000 , 4 , 3 , 2 , 2 , 2 , 2 ) ,
@@ -634,29 +683,37 @@ describe('Datetime', () => {
634
683
expect ( actualMonths ) . toEqual ( expectedMonths ) ;
635
684
} ) ;
636
685
637
- it ( 'closeOnSelect=false' , ( ) => {
686
+ it ( 'closeOnSelect=false' , ( done ) => {
638
687
const component = utils . createDatetime ( { closeOnSelect : false } ) ;
639
688
640
- // A unknown race condition is causing this test to fail without this
689
+ // A unknown race condition is causing this test to fail without this time out,
690
+ // and when the test fails it says:
691
+ // 'Timeout - Async callback was not invoked within timeout'
692
+ // Ideally it would say something else but at least we know the tests are passing now
641
693
setTimeout ( ( ) => {
642
694
expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
643
695
utils . openDatepicker ( component ) ;
644
696
expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
645
697
utils . clickNthDay ( component , 2 ) ;
646
698
expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
699
+ done ( ) ;
647
700
} , 0 ) ;
648
701
} ) ;
649
702
650
- it ( 'closeOnSelect=true' , ( ) => {
703
+ it ( 'closeOnSelect=true' , ( done ) => {
651
704
const component = utils . createDatetime ( { closeOnSelect : true } ) ;
652
705
653
- // A unknown race condition is causing this test to fail without this
706
+ // A unknown race condition is causing this test to fail without this time out,
707
+ // and when the test fails it says:
708
+ // 'Timeout - Async callback was not invoked within timeout'
709
+ // Ideally it would say something else but at least we know the tests are passing now
654
710
setTimeout ( ( ) => {
655
711
expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
656
712
utils . openDatepicker ( component ) ;
657
713
expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
658
714
utils . clickNthDay ( component , 2 ) ;
659
715
expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
716
+ done ( ) ;
660
717
} , 0 ) ;
661
718
} ) ;
662
719
@@ -710,19 +767,23 @@ describe('Datetime', () => {
710
767
} ) ;
711
768
712
769
describe ( 'being updated and should trigger update' , ( ) => {
713
- it ( 'dateFormat -> value should change format' , ( ) => {
770
+ it ( 'dateFormat -> value should change format' , ( done ) => {
714
771
const date = new Date ( 2000 , 0 , 15 , 2 , 2 , 2 , 2 ) ,
715
772
component = utils . createDatetime ( {
716
773
dateFormat : 'YYYY-MM-DD' , timeFormat : false , defaultValue : date
717
774
} ) ;
718
775
719
776
const valueBefore = utils . getInputValue ( component ) ;
720
- // A unknown race condition is causing this test to fail without this
777
+ // A unknown race condition is causing this test to fail without this time out,
778
+ // and when the test fails it says:
779
+ // 'Timeout - Async callback was not invoked within timeout'
780
+ // Ideally it would say something else but at least we know the tests are passing now
721
781
setTimeout ( ( ) => {
722
782
component . setProps ( { dateFormat : 'DD.MM.YYYY' } ) ;
723
783
const valueAfter = utils . getInputValue ( component ) ;
724
784
725
785
expect ( valueBefore ) . not . toEqual ( valueAfter ) ;
786
+ done ( ) ;
726
787
} , 0 ) ;
727
788
} ) ;
728
789
0 commit comments