@@ -67,7 +67,6 @@ describe("Date Picker", function() {
67
67
} ) ;
68
68
const hiddenInputElement = document . getElementById ( id ) ;
69
69
assertIsoStringsHaveSameDate ( hiddenInputElement . value , value ) ;
70
- console . log ( hiddenInputElement . value , hiddenInputElement . getAttribute ( 'data-formattedvalue' ) ) ;
71
70
assert . equal ( hiddenInputElement . getAttribute ( 'data-formattedvalue' ) , `${ value . slice ( 5 , 7 ) } /${ value . slice ( 8 , 10 ) } /${ value . slice ( 0 , 4 ) } ` ) ;
72
71
ReactDOM . unmountComponentAtNode ( container ) ;
73
72
} ) ) ;
@@ -605,4 +604,99 @@ describe("Date Picker", function() {
605
604
assertIsoStringsHaveSameDate ( value , originalValue ) ;
606
605
ReactDOM . unmountComponentAtNode ( container ) ;
607
606
} ) ) ;
607
+ it ( "should display the correct day of the week in the calendar." , co . wrap ( function * ( ) {
608
+ const id = UUID . v4 ( ) ;
609
+ let value = null ;
610
+ let formattedValue = null ;
611
+ const App = React . createClass ( {
612
+ handleChange : function ( newValue , newFormattedValue ) {
613
+ value = newValue ;
614
+ formattedValue = newFormattedValue ;
615
+ } ,
616
+ render : function ( ) {
617
+ return < div >
618
+ < DatePicker id = { id } onChange = { this . handleChange } dateFormat = "MM/DD/YYYY" />
619
+ </ div > ;
620
+ }
621
+ } ) ;
622
+ yield new Promise ( function ( resolve , reject ) {
623
+ ReactDOM . render ( < App /> , container , resolve ) ;
624
+ } ) ;
625
+ const inputElement = document . querySelector ( "input.form-control" ) ;
626
+ const hiddenInputElement = document . getElementById ( id ) ;
627
+ const checkMonthAndYear = function ( startValue ) {
628
+ inputElement . value = `${ startValue . slice ( 5 , 7 ) } /${ startValue . slice ( 8 , 10 ) } /${ startValue . slice ( 0 , 4 ) } ` ;
629
+ TestUtils . Simulate . change ( inputElement ) ;
630
+ TestUtils . Simulate . focus ( inputElement ) ;
631
+ const weekElements = document . querySelectorAll ( "table tbody tr" ) ;
632
+ weekElements . forEach ( weekElement => {
633
+ const dayElements = weekElement . querySelectorAll ( "td" ) ;
634
+ dayElements . forEach ( ( dayElement , index ) => {
635
+ if ( dayElement . innerHTML === '' ) {
636
+ return ;
637
+ }
638
+ TestUtils . Simulate . click ( dayElement ) ;
639
+ let date = new Date ( hiddenInputElement . value ) ;
640
+ assert . equal ( date . getDay ( ) , index ) ;
641
+ } ) ;
642
+ } ) ;
643
+ }
644
+ const today = new Date ( ) ;
645
+ for ( let year = today . getFullYear ( ) - 2 ; year < today . getFullYear ( ) + 2 ; year ++ ) {
646
+ for ( let month = 0 ; month < 12 ; month ++ ) {
647
+ const date = new Date ( ) ;
648
+ date . setMonth ( month ) ;
649
+ date . setYear ( year ) ;
650
+ checkMonthAndYear ( date . toISOString ( ) ) ;
651
+ }
652
+ }
653
+ } ) ) ;
654
+ it ( "should display the correct day of the week in the calendar when starting on Monday." , co . wrap ( function * ( ) {
655
+ const id = UUID . v4 ( ) ;
656
+ let value = null ;
657
+ let formattedValue = null ;
658
+ const App = React . createClass ( {
659
+ handleChange : function ( newValue , newFormattedValue ) {
660
+ value = newValue ;
661
+ formattedValue = newFormattedValue ;
662
+ } ,
663
+ render : function ( ) {
664
+ return < div >
665
+ < DatePicker id = { id } onChange = { this . handleChange } dateFormat = "MM/DD/YYYY" weekStartsOnMonday />
666
+ </ div > ;
667
+ }
668
+ } ) ;
669
+ yield new Promise ( function ( resolve , reject ) {
670
+ ReactDOM . render ( < App /> , container , resolve ) ;
671
+ } ) ;
672
+ const inputElement = document . querySelector ( "input.form-control" ) ;
673
+ const hiddenInputElement = document . getElementById ( id ) ;
674
+ const checkMonthAndYear = function ( startValue ) {
675
+ inputElement . value = `${ startValue . slice ( 5 , 7 ) } /${ startValue . slice ( 8 , 10 ) } /${ startValue . slice ( 0 , 4 ) } ` ;
676
+ TestUtils . Simulate . change ( inputElement ) ;
677
+ TestUtils . Simulate . focus ( inputElement ) ;
678
+ const weekElements = document . querySelectorAll ( "table tbody tr" ) ;
679
+ weekElements . forEach ( weekElement => {
680
+ const dayElements = weekElement . querySelectorAll ( "td" ) ;
681
+ dayElements . forEach ( ( dayElement , index ) => {
682
+ if ( dayElement . innerHTML === '' ) {
683
+ return ;
684
+ }
685
+ TestUtils . Simulate . click ( dayElement ) ;
686
+ let date = new Date ( hiddenInputElement . value ) ;
687
+ assert . equal ( date . getDay ( ) , index === 6 ? 0 : index + 1 ) ;
688
+ } ) ;
689
+ } ) ;
690
+ }
691
+ const today = new Date ( ) ;
692
+ for ( let year = today . getFullYear ( ) - 2 ; year < today . getFullYear ( ) + 2 ; year ++ ) {
693
+ for ( let month = 0 ; month < 12 ; month ++ ) {
694
+ const date = new Date ( ) ;
695
+ date . setMonth ( month ) ;
696
+ date . setYear ( year ) ;
697
+ checkMonthAndYear ( date . toISOString ( ) ) ;
698
+ }
699
+ }
700
+ } ) ) ;
701
+
608
702
} ) ;
0 commit comments