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
24import moment from 'moment' ;
35import utils from './testUtils' ;
46
@@ -11,6 +13,42 @@ describe('Datetime', () => {
1113 expect ( component . find ( '.rdt > .rdtPicker' ) . length ) . toEqual ( 1 ) ;
1214 } ) ;
1315
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+
1452 it ( 'switch from day view to time view and back' , ( ) => {
1553 const component = utils . createDatetime ( { } ) ;
1654
@@ -187,10 +225,10 @@ describe('Datetime', () => {
187225
188226 utils . openDatepicker ( component ) ;
189227
190- prevMonthDaysIndexes . forEach ( function ( index ) {
228+ prevMonthDaysIndexes . forEach ( ( index ) => {
191229 expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtOld' ) ) . toBeTruthy ( ) ;
192230 } ) ;
193- nextMonthDaysIndexes . forEach ( function ( index ) {
231+ nextMonthDaysIndexes . forEach ( ( index ) => {
194232 expect ( utils . getNthDay ( component , index ) . hasClass ( 'rdtNew' ) ) . toBeTruthy ( ) ;
195233 } ) ;
196234 } ) ;
@@ -206,6 +244,17 @@ describe('Datetime', () => {
206244 expect ( utils . getNthDay ( component , 36 ) . hasClass ( 'rdtActive' ) ) . toBeTruthy ( ) ;
207245 } ) ;
208246
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+
209258 // Proof of bug
210259 it ( 'should show correct selected month when traversing view modes' , ( ) => {
211260 const date = new Date ( 2000 , 4 , 3 , 2 , 2 , 2 , 2 ) ,
@@ -634,29 +683,37 @@ describe('Datetime', () => {
634683 expect ( actualMonths ) . toEqual ( expectedMonths ) ;
635684 } ) ;
636685
637- it ( 'closeOnSelect=false' , ( ) => {
686+ it ( 'closeOnSelect=false' , ( done ) => {
638687 const component = utils . createDatetime ( { closeOnSelect : false } ) ;
639688
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
641693 setTimeout ( ( ) => {
642694 expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
643695 utils . openDatepicker ( component ) ;
644696 expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
645697 utils . clickNthDay ( component , 2 ) ;
646698 expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
699+ done ( ) ;
647700 } , 0 ) ;
648701 } ) ;
649702
650- it ( 'closeOnSelect=true' , ( ) => {
703+ it ( 'closeOnSelect=true' , ( done ) => {
651704 const component = utils . createDatetime ( { closeOnSelect : true } ) ;
652705
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
654710 setTimeout ( ( ) => {
655711 expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
656712 utils . openDatepicker ( component ) ;
657713 expect ( utils . isOpen ( component ) ) . toBeTruthy ( ) ;
658714 utils . clickNthDay ( component , 2 ) ;
659715 expect ( utils . isOpen ( component ) ) . toBeFalsy ( ) ;
716+ done ( ) ;
660717 } , 0 ) ;
661718 } ) ;
662719
@@ -710,19 +767,23 @@ describe('Datetime', () => {
710767 } ) ;
711768
712769 describe ( 'being updated and should trigger update' , ( ) => {
713- it ( 'dateFormat -> value should change format' , ( ) => {
770+ it ( 'dateFormat -> value should change format' , ( done ) => {
714771 const date = new Date ( 2000 , 0 , 15 , 2 , 2 , 2 , 2 ) ,
715772 component = utils . createDatetime ( {
716773 dateFormat : 'YYYY-MM-DD' , timeFormat : false , defaultValue : date
717774 } ) ;
718775
719776 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
721781 setTimeout ( ( ) => {
722782 component . setProps ( { dateFormat : 'DD.MM.YYYY' } ) ;
723783 const valueAfter = utils . getInputValue ( component ) ;
724784
725785 expect ( valueBefore ) . not . toEqual ( valueAfter ) ;
786+ done ( ) ;
726787 } , 0 ) ;
727788 } ) ;
728789
0 commit comments