@@ -2062,6 +2062,17 @@ describe('input', function() {
2062
2062
expect ( scope . form . alias . $error . month ) . toBeTruthy ( ) ;
2063
2063
} ) ;
2064
2064
2065
+ it ( 'should only change the month of a bound date' , function ( ) {
2066
+ compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2067
+
2068
+ scope . $apply ( function ( ) {
2069
+ scope . value = new Date ( Date . UTC ( 2013 , 7 , 1 , 1 , 0 , 0 ) ) ;
2070
+ } ) ;
2071
+ changeInputValueTo ( '2013-12' ) ;
2072
+ expect ( + scope . value ) . toBe ( Date . UTC ( 2013 , 11 , 1 , 1 , 0 , 0 ) ) ;
2073
+ expect ( inputElm . val ( ) ) . toBe ( '2013-12' ) ;
2074
+ } ) ;
2075
+
2065
2076
describe ( 'min' , function ( ) {
2066
2077
beforeEach ( function ( ) {
2067
2078
compileInput ( '<input type="month" ng-model="value" name="alias" min="2013-01" />' ) ;
@@ -2124,6 +2135,18 @@ describe('input', function() {
2124
2135
expect ( inputElm . val ( ) ) . toBe ( '2013-W02' ) ;
2125
2136
} ) ;
2126
2137
2138
+ it ( 'should not affect the hours or minutes of a bound date' , function ( ) {
2139
+ compileInput ( '<input type="week" ng-model="secondWeek"/>' ) ;
2140
+
2141
+ scope . $apply ( function ( ) {
2142
+ scope . secondWeek = new Date ( 2013 , 0 , 11 , 1 , 0 , 0 ) ;
2143
+ } ) ;
2144
+
2145
+ changeInputValueTo ( '2013-W03' ) ;
2146
+
2147
+ expect ( + scope . secondWeek ) . toBe ( + new Date ( 2013 , 0 , 17 , 1 , 0 , 0 ) ) ;
2148
+ } ) ;
2149
+
2127
2150
it ( 'should set the model undefined if the input is an invalid week string' , function ( ) {
2128
2151
compileInput ( '<input type="week" ng-model="value"/>' ) ;
2129
2152
@@ -2549,6 +2572,17 @@ describe('input', function() {
2549
2572
expect ( scope . form . alias . $error . time ) . toBeTruthy ( ) ;
2550
2573
} ) ;
2551
2574
2575
+ it ( 'should only change hours and minute of a bound date' , function ( ) {
2576
+ compileInput ( '<input type="time" ng-model="value"" />' ) ;
2577
+
2578
+ scope . $apply ( function ( ) {
2579
+ scope . value = new Date ( 2013 , 2 , 3 , 1 , 0 , 0 ) ;
2580
+ } ) ;
2581
+
2582
+ changeInputValueTo ( '01:02' ) ;
2583
+ expect ( + scope . value ) . toBe ( + new Date ( 2013 , 2 , 3 , 1 , 2 , 0 ) ) ;
2584
+ } ) ;
2585
+
2552
2586
describe ( 'min' , function ( ) {
2553
2587
beforeEach ( function ( ) {
2554
2588
compileInput ( '<input type="time" ng-model="value" name="alias" min="09:30:00" />' ) ;
@@ -2717,6 +2751,48 @@ describe('input', function() {
2717
2751
expect ( scope . form . alias . $error . date ) . toBeTruthy ( ) ;
2718
2752
} ) ;
2719
2753
2754
+ it ( 'should work with multiple date types bound to the same model' , function ( ) {
2755
+ formElm = jqLite ( '<form name="form"></form>' ) ;
2756
+
2757
+ var timeElm = jqLite ( '<input type="time" ng-model="val" />' ) ,
2758
+ monthElm = jqLite ( '<input type="month" ng-model="val" />' ) ,
2759
+ weekElm = jqLite ( '<input type="week" ng-model="val" />' ) ;
2760
+
2761
+ formElm . append ( timeElm ) ;
2762
+ formElm . append ( monthElm ) ;
2763
+ formElm . append ( weekElm ) ;
2764
+
2765
+ $compile ( formElm ) ( scope ) ;
2766
+
2767
+ scope . $apply ( function ( ) {
2768
+ scope . val = new Date ( 2013 , 1 , 2 , 3 , 4 , 5 ) ;
2769
+ } ) ;
2770
+
2771
+ expect ( timeElm . val ( ) ) . toBe ( '03:04:05' ) ;
2772
+ expect ( monthElm . val ( ) ) . toBe ( '2013-02' ) ;
2773
+ expect ( weekElm . val ( ) ) . toBe ( '2013-W05' ) ;
2774
+
2775
+ changeGivenInputTo ( monthElm , '2012-02' ) ;
2776
+ expect ( monthElm . val ( ) ) . toBe ( '2012-02' ) ;
2777
+ expect ( timeElm . val ( ) ) . toBe ( '03:04:05' ) ;
2778
+ expect ( weekElm . val ( ) ) . toBe ( '2012-W05' ) ;
2779
+
2780
+ changeGivenInputTo ( timeElm , '04:05:06' ) ;
2781
+ expect ( monthElm . val ( ) ) . toBe ( '2012-02' ) ;
2782
+ expect ( timeElm . val ( ) ) . toBe ( '04:05:06' ) ;
2783
+ expect ( weekElm . val ( ) ) . toBe ( '2012-W05' ) ;
2784
+
2785
+ changeGivenInputTo ( weekElm , '2014-W01' ) ;
2786
+ expect ( monthElm . val ( ) ) . toBe ( '2014-01' ) ;
2787
+ expect ( timeElm . val ( ) ) . toBe ( '04:05:06' ) ;
2788
+ expect ( weekElm . val ( ) ) . toBe ( '2014-W01' ) ;
2789
+
2790
+ function changeGivenInputTo ( inputElm , value ) {
2791
+ inputElm . val ( value ) ;
2792
+ browserTrigger ( inputElm , $sniffer . hasEvent ( 'input' ) ? 'input' : 'change' ) ;
2793
+ }
2794
+ } ) ;
2795
+
2720
2796
describe ( 'min' , function ( ) {
2721
2797
beforeEach ( function ( ) {
2722
2798
compileInput ( '<input type="date" ng-model="value" name="alias" min="2000-01-01" />' ) ;
0 commit comments