@@ -319,6 +319,25 @@ describe('validators', function() {
319
319
expect ( ctrl . $error . minlength ) . toBe ( true ) ;
320
320
expect ( ctrlNg . $error . minlength ) . toBe ( true ) ;
321
321
} ) ) ;
322
+
323
+ describe ( 'collection validation' , function ( ) {
324
+
325
+ it ( 'should validate the viewValue and not the individual values' , function ( ) {
326
+ var inputElm = helper . compileInput ( '<input type="text" minlength="10" ng-list ng-model="list">' ) ;
327
+ var ctrl = inputElm . controller ( 'ngModel' ) ;
328
+ spyOn ( ctrl . $validators , 'minlength' ) . andCallThrough ( ) ;
329
+
330
+ helper . changeInputValueTo ( '2,2' ) ;
331
+ expect ( inputElm ) . toBeInvalid ( ) ;
332
+ expect ( ctrl . $error . minlength ) . toBe ( true ) ;
333
+ expect ( ctrl . $validators . minlength . calls [ 0 ] . args ) . toEqual ( [ [ '2' , '2' ] , '2,2' ] ) ;
334
+
335
+ helper . changeInputValueTo ( '20000,20000' ) ;
336
+ expect ( inputElm ) . toBeInvalid ( ) ;
337
+ expect ( ctrl . $error . minlength ) . toBe ( false ) ;
338
+ } ) ;
339
+ } ) ;
340
+
322
341
} ) ;
323
342
324
343
@@ -507,6 +526,24 @@ describe('validators', function() {
507
526
expect ( ctrl . $error . maxlength ) . toBe ( true ) ;
508
527
expect ( ctrlNg . $error . maxlength ) . toBe ( true ) ;
509
528
} ) ) ;
529
+
530
+ describe ( 'collection validation' , function ( ) {
531
+
532
+ it ( 'should validate the viewValue and not the individual values' , function ( ) {
533
+ var inputElm = helper . compileInput ( '<input type="text" maxlength="10" ng-list ng-model="list">' ) ;
534
+ var ctrl = inputElm . controller ( 'ngModel' ) ;
535
+ spyOn ( ctrl . $validators , 'maxlength' ) . andCallThrough ( ) ;
536
+
537
+ helper . changeInputValueTo ( '2,2' ) ;
538
+ expect ( inputElm ) . toBeValid ( ) ;
539
+ expect ( ctrl . $error . maxlength ) . toBeFalsy ( ) ;
540
+ expect ( ctrl . $validators . maxlength . calls [ 0 ] . args ) . toEqual ( [ [ '2' , '2' ] , '2,2' ] ) ;
541
+
542
+ helper . changeInputValueTo ( '20000,20000' ) ;
543
+ expect ( inputElm ) . toBeInvalid ( ) ;
544
+ expect ( ctrl . $error . maxlength ) . toBe ( true ) ;
545
+ } ) ;
546
+ } ) ;
510
547
} ) ;
511
548
512
549
0 commit comments