@@ -2314,6 +2314,17 @@ describe('input', function() {
2314
2314
expect ( scope . form . alias . $error . month ) . toBeTruthy ( ) ;
2315
2315
} ) ;
2316
2316
2317
+ it ( 'should only change the month of a bound date' , function ( ) {
2318
+ compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2319
+
2320
+ scope . $apply ( function ( ) {
2321
+ scope . value = new Date ( Date . UTC ( 2013 , 7 , 1 , 1 , 0 , 0 , 0 ) ) ;
2322
+ } ) ;
2323
+ changeInputValueTo ( '2013-12' ) ;
2324
+ expect ( + scope . value ) . toBe ( Date . UTC ( 2013 , 11 , 1 , 1 , 0 , 0 , 0 ) ) ;
2325
+ expect ( inputElm . val ( ) ) . toBe ( '2013-12' ) ;
2326
+ } ) ;
2327
+
2317
2328
describe ( 'min' , function ( ) {
2318
2329
var scope ;
2319
2330
beforeEach ( inject ( function ( $rootScope ) {
@@ -2406,6 +2417,18 @@ describe('input', function() {
2406
2417
expect ( inputElm . val ( ) ) . toBe ( '2013-W02' ) ;
2407
2418
} ) ;
2408
2419
2420
+ it ( 'should not affect the hours or minutes of a bound date' , function ( ) {
2421
+ compileInput ( '<input type="week" ng-model="secondWeek"/>' ) ;
2422
+
2423
+ scope . $apply ( function ( ) {
2424
+ scope . secondWeek = new Date ( 2013 , 0 , 11 , 1 , 0 , 0 , 0 ) ;
2425
+ } ) ;
2426
+
2427
+ changeInputValueTo ( '2013-W03' ) ;
2428
+
2429
+ expect ( + scope . secondWeek ) . toBe ( + new Date ( 2013 , 0 , 17 , 1 , 0 , 0 , 0 ) ) ;
2430
+ } ) ;
2431
+
2409
2432
it ( 'should set the model undefined if the input is an invalid week string' , function ( ) {
2410
2433
compileInput ( '<input type="week" ng-model="value"/>' ) ;
2411
2434
@@ -2934,6 +2957,17 @@ describe('input', function() {
2934
2957
expect ( scope . form . alias . $error . time ) . toBeTruthy ( ) ;
2935
2958
} ) ;
2936
2959
2960
+ it ( 'should only change hours and minute of a bound date' , function ( ) {
2961
+ compileInput ( '<input type="time" ng-model="value"" />' ) ;
2962
+
2963
+ scope . $apply ( function ( ) {
2964
+ scope . value = new Date ( 2013 , 2 , 3 , 1 , 0 , 0 ) ;
2965
+ } ) ;
2966
+
2967
+ changeInputValueTo ( '01:02' ) ;
2968
+ expect ( + scope . value ) . toBe ( + new Date ( 2013 , 2 , 3 , 1 , 2 , 0 ) ) ;
2969
+ } ) ;
2970
+
2937
2971
describe ( 'min' , function ( ) {
2938
2972
var scope ;
2939
2973
beforeEach ( inject ( function ( $rootScope ) {
@@ -3141,6 +3175,50 @@ describe('input', function() {
3141
3175
expect ( scope . form . alias . $error . date ) . toBeTruthy ( ) ;
3142
3176
} ) ;
3143
3177
3178
+ it ( 'should work with multiple date types bound to the same model' , function ( ) {
3179
+ formElm = jqLite ( '<form name="form"></form>' ) ;
3180
+
3181
+ var timeElm = jqLite ( '<input type="time" ng-model="val" />' ) ,
3182
+ monthElm = jqLite ( '<input type="month" ng-model="val" />' ) ,
3183
+ weekElm = jqLite ( '<input type="week" ng-model="val" />' ) ;
3184
+
3185
+ formElm . append ( timeElm ) ;
3186
+ formElm . append ( monthElm ) ;
3187
+ formElm . append ( weekElm ) ;
3188
+
3189
+ $compile ( formElm ) ( scope ) ;
3190
+
3191
+ scope . $apply ( function ( ) {
3192
+ scope . val = new Date ( 2013 , 1 , 2 , 3 , 4 , 5 , 6 ) ;
3193
+ } ) ;
3194
+
3195
+ expect ( timeElm . val ( ) ) . toBe ( '03:04:05' ) ;
3196
+ expect ( monthElm . val ( ) ) . toBe ( '2013-02' ) ;
3197
+ expect ( weekElm . val ( ) ) . toBe ( '2013-W05' ) ;
3198
+
3199
+ changeGivenInputTo ( monthElm , '2012-02' ) ;
3200
+ expect ( monthElm . val ( ) ) . toBe ( '2012-02' ) ;
3201
+ expect ( timeElm . val ( ) ) . toBe ( '03:04:05' ) ;
3202
+ expect ( weekElm . val ( ) ) . toBe ( '2012-W05' ) ;
3203
+
3204
+ changeGivenInputTo ( timeElm , '04:05:06' ) ;
3205
+ expect ( monthElm . val ( ) ) . toBe ( '2012-02' ) ;
3206
+ expect ( timeElm . val ( ) ) . toBe ( '04:05:06' ) ;
3207
+ expect ( weekElm . val ( ) ) . toBe ( '2012-W05' ) ;
3208
+
3209
+ changeGivenInputTo ( weekElm , '2014-W01' ) ;
3210
+ expect ( monthElm . val ( ) ) . toBe ( '2014-01' ) ;
3211
+ expect ( timeElm . val ( ) ) . toBe ( '04:05:06' ) ;
3212
+ expect ( weekElm . val ( ) ) . toBe ( '2014-W01' ) ;
3213
+
3214
+ expect ( + scope . val ) . toBe ( + new Date ( 2014 , 0 , 2 , 4 , 5 , 6 , 6 ) ) ;
3215
+
3216
+ function changeGivenInputTo ( inputElm , value ) {
3217
+ inputElm . val ( value ) ;
3218
+ browserTrigger ( inputElm , $sniffer . hasEvent ( 'input' ) ? 'input' : 'change' ) ;
3219
+ }
3220
+ } ) ;
3221
+
3144
3222
describe ( 'min' , function ( ) {
3145
3223
beforeEach ( function ( ) {
3146
3224
compileInput ( '<input type="date" ng-model="value" name="alias" min="2000-01-01" />' ) ;
0 commit comments