@@ -404,6 +404,9 @@ describe('form', function() {
404
404
405
405
child . $setDirty ( ) ;
406
406
expect ( parent . $dirty ) . toBeTruthy ( ) ;
407
+
408
+ child . $setSubmitted ( ) ;
409
+ expect ( parent . $submitted ) . toBeTruthy ( ) ;
407
410
} ) ;
408
411
409
412
@@ -681,14 +684,42 @@ describe('form', function() {
681
684
expect ( nestedInputCtrl . $dirty ) . toBe ( false ) ;
682
685
} ) ;
683
686
} ) ;
687
+
688
+ describe ( '$setSubmitted' , function ( ) {
689
+ beforeEach ( function ( ) {
690
+ doc = $compile (
691
+ '<form name="form" ng-submit="submitted = true">' +
692
+ '<input type="text" ng-model="name" required />' +
693
+ '<input type="submit" />' +
694
+ '</form>' ) ( scope ) ;
695
+
696
+ scope . $digest ( ) ;
697
+ } ) ;
698
+
699
+ it ( 'should not init in submitted state' , function ( ) {
700
+ expect ( scope . form . $submitted ) . toBe ( false ) ;
701
+ } ) ;
702
+
703
+ it ( 'should be in submitted state when submitted' , function ( ) {
704
+ browserTrigger ( doc , 'submit' ) ;
705
+ expect ( scope . form . $submitted ) . toBe ( true ) ;
706
+ } ) ;
707
+
708
+ it ( 'should revert submitted back to false when $setPristine is called on the form' , function ( ) {
709
+ scope . form . $submitted = true ;
710
+ scope . form . $setPristine ( ) ;
711
+ expect ( scope . form . $submitted ) . toBe ( false ) ;
712
+ } ) ;
713
+ } ) ;
684
714
} ) ;
685
715
686
716
describe ( 'form animations' , function ( ) {
687
717
beforeEach ( module ( 'ngAnimateMock' ) ) ;
688
718
689
- function assertValidAnimation ( animation , event , className ) {
719
+ function assertValidAnimation ( animation , event , classNameAdded , classNameRemoved ) {
690
720
expect ( animation . event ) . toBe ( event ) ;
691
- expect ( animation . args [ 1 ] ) . toBe ( className ) ;
721
+ expect ( animation . args [ 1 ] ) . toBe ( classNameAdded ) ;
722
+ expect ( animation . args [ 2 ] ) . toBe ( classNameRemoved ) ;
692
723
}
693
724
694
725
var doc , scope , form ;
@@ -741,8 +772,7 @@ describe('form animations', function() {
741
772
742
773
form . $setPristine ( ) ;
743
774
744
- assertValidAnimation ( $animate . queue [ 0 ] , 'removeClass' , 'ng-dirty' ) ;
745
- assertValidAnimation ( $animate . queue [ 1 ] , 'addClass' , 'ng-pristine' ) ;
775
+ assertValidAnimation ( $animate . queue [ 0 ] , 'setClass' , 'ng-pristine' , 'ng-dirty ng-submitted' ) ;
746
776
} ) ) ;
747
777
748
778
it ( 'should trigger custom errors as addClass/removeClass when invalid/valid' , inject ( function ( $animate ) {
0 commit comments