@@ -2284,6 +2284,15 @@ describe('input', function() {
22842284
22852285 describe ( 'number' , function ( ) {
22862286
2287+ // Helpers for min / max tests
2288+ var subtract = function ( value ) {
2289+ return value - 5 ;
2290+ } ;
2291+
2292+ var add = function ( value ) {
2293+ return value + 5 ;
2294+ } ;
2295+
22872296 it ( 'should reset the model if view is invalid' , function ( ) {
22882297 var inputElm = helper . compileInput ( '<input type="number" ng-model="age"/>' ) ;
22892298
@@ -2465,6 +2474,29 @@ describe('input', function() {
24652474 expect ( $rootScope . form . alias . $error . min ) . toBeFalsy ( ) ;
24662475 } ) ;
24672476
2477+
2478+ it ( 'should validate against the viewValue' , function ( ) {
2479+ var inputElm = helper . compileInput (
2480+ '<input type="number" ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" min="10" />' ) ;
2481+
2482+ var ngModelCtrl = inputElm . controller ( 'ngModel' ) ;
2483+ ngModelCtrl . $parsers . push ( subtract ) ;
2484+
2485+ helper . changeInputValueTo ( '10' ) ;
2486+ expect ( inputElm ) . toBeValid ( ) ;
2487+ expect ( $rootScope . value ) . toBe ( 5 ) ;
2488+ expect ( $rootScope . form . alias . $error . min ) . toBeFalsy ( ) ;
2489+
2490+ ngModelCtrl . $parsers . pop ( ) ;
2491+ ngModelCtrl . $parsers . push ( add ) ;
2492+
2493+ helper . changeInputValueTo ( '5' ) ;
2494+ expect ( inputElm ) . toBeInvalid ( ) ;
2495+ expect ( $rootScope . form . alias . $error . min ) . toBeTruthy ( ) ;
2496+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2497+ } ) ;
2498+
2499+
24682500 it ( 'should validate even if min value changes on-the-fly' , function ( ) {
24692501 $rootScope . min = undefined ;
24702502 var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" min="{{min}}" />' ) ;
@@ -2511,6 +2543,28 @@ describe('input', function() {
25112543 expect ( $rootScope . form . alias . $error . min ) . toBeFalsy ( ) ;
25122544 } ) ;
25132545
2546+
2547+ it ( 'should validate against the viewValue' , function ( ) {
2548+ var inputElm = helper . compileInput (
2549+ '<input type="number" ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" ng-min="10" />' ) ;
2550+ var ngModelCtrl = inputElm . controller ( 'ngModel' ) ;
2551+ ngModelCtrl . $parsers . push ( subtract ) ;
2552+
2553+ helper . changeInputValueTo ( '10' ) ;
2554+ expect ( inputElm ) . toBeValid ( ) ;
2555+ expect ( $rootScope . value ) . toBe ( 5 ) ;
2556+ expect ( $rootScope . form . alias . $error . min ) . toBeFalsy ( ) ;
2557+
2558+ ngModelCtrl . $parsers . pop ( ) ;
2559+ ngModelCtrl . $parsers . push ( add ) ;
2560+
2561+ helper . changeInputValueTo ( '5' ) ;
2562+ expect ( inputElm ) . toBeInvalid ( ) ;
2563+ expect ( $rootScope . form . alias . $error . min ) . toBeTruthy ( ) ;
2564+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2565+ } ) ;
2566+
2567+
25142568 it ( 'should validate even if the ngMin value changes on-the-fly' , function ( ) {
25152569 $rootScope . min = undefined ;
25162570 var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" ng-min="min" />' ) ;
@@ -2558,6 +2612,28 @@ describe('input', function() {
25582612 expect ( $rootScope . form . alias . $error . max ) . toBeFalsy ( ) ;
25592613 } ) ;
25602614
2615+
2616+ it ( 'should validate against the viewValue' , function ( ) {
2617+ var inputElm = helper . compileInput ( '<input type="number"' +
2618+ 'ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" max="10" />' ) ;
2619+ var ngModelCtrl = inputElm . controller ( 'ngModel' ) ;
2620+ ngModelCtrl . $parsers . push ( add ) ;
2621+
2622+ helper . changeInputValueTo ( '10' ) ;
2623+ expect ( inputElm ) . toBeValid ( ) ;
2624+ expect ( $rootScope . value ) . toBe ( 15 ) ;
2625+ expect ( $rootScope . form . alias . $error . max ) . toBeFalsy ( ) ;
2626+
2627+ ngModelCtrl . $parsers . pop ( ) ;
2628+ ngModelCtrl . $parsers . push ( subtract ) ;
2629+
2630+ helper . changeInputValueTo ( '15' ) ;
2631+ expect ( inputElm ) . toBeInvalid ( ) ;
2632+ expect ( $rootScope . form . alias . $error . max ) . toBeTruthy ( ) ;
2633+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2634+ } ) ;
2635+
2636+
25612637 it ( 'should validate even if max value changes on-the-fly' , function ( ) {
25622638 $rootScope . max = undefined ;
25632639 var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" max="{{max}}" />' ) ;
@@ -2604,6 +2680,28 @@ describe('input', function() {
26042680 expect ( $rootScope . form . alias . $error . max ) . toBeFalsy ( ) ;
26052681 } ) ;
26062682
2683+
2684+ it ( 'should validate against the viewValue' , function ( ) {
2685+ var inputElm = helper . compileInput ( '<input type="number"' +
2686+ 'ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" ng-max="10" />' ) ;
2687+ var ngModelCtrl = inputElm . controller ( 'ngModel' ) ;
2688+ ngModelCtrl . $parsers . push ( add ) ;
2689+
2690+ helper . changeInputValueTo ( '10' ) ;
2691+ expect ( inputElm ) . toBeValid ( ) ;
2692+ expect ( $rootScope . value ) . toBe ( 15 ) ;
2693+ expect ( $rootScope . form . alias . $error . max ) . toBeFalsy ( ) ;
2694+
2695+ ngModelCtrl . $parsers . pop ( ) ;
2696+ ngModelCtrl . $parsers . push ( subtract ) ;
2697+
2698+ helper . changeInputValueTo ( '15' ) ;
2699+ expect ( inputElm ) . toBeInvalid ( ) ;
2700+ expect ( $rootScope . form . alias . $error . max ) . toBeTruthy ( ) ;
2701+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2702+ } ) ;
2703+
2704+
26072705 it ( 'should validate even if the ngMax value changes on-the-fly' , function ( ) {
26082706 $rootScope . max = undefined ;
26092707 var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" ng-max="max" />' ) ;
0 commit comments