@@ -726,50 +726,138 @@ describe('input', function() {
726
726
} ) ;
727
727
728
728
describe ( 'email' , function ( ) {
729
+ describe ( 'should validate e-mail' , function ( ) {
730
+ it ( 'when used simply' , function ( ) {
731
+ compileInput ( '<input type="email" ng-model="email" name="alias" />' ) ;
732
+ var widget = scope . form . alias ;
729
733
730
- it ( 'should validate e-mail' , function ( ) {
731
- compileInput ( '<input type="email" ng-model="email" name="alias" />' ) ;
734
+ changeInputValueTo ( '[email protected] ' ) ;
735
+ expect ( scope . email ) . toBe ( '[email protected] ' ) ;
736
+ expect ( inputElm ) . toBeValid ( ) ;
737
+ expect ( widget . $error . email ) . toBe ( false ) ;
732
738
733
- var widget = scope . form . alias ;
734
- changeInputValueTo ( '[email protected] ' ) ;
739
+ changeInputValueTo ( 'invalid@' ) ;
740
+ expect ( scope . email ) . toBeUndefined ( ) ;
741
+ expect ( inputElm ) . toBeInvalid ( ) ;
742
+ expect ( widget . $error . email ) . toBeTruthy ( ) ;
743
+ } ) ;
744
+ it ( 'when used with ngList (default separator)' , function ( ) {
745
+ compileInput ( '<input ng-list type="email" ng-model="email" name="alias" />' ) ;
746
+ var widget = scope . form . alias ;
735
747
736
- expect ( scope . email ) . toBe ( '[email protected] ' ) ;
737
- expect ( inputElm ) . toBeValid ( ) ;
738
- expect ( widget . $error . email ) . toBe ( false ) ;
748
+ changeInputValueTo ( '[email protected] ' ) ;
749
+ expect ( scope . email ) . toEqual ( [ '[email protected] ' ] ) ;
750
+ expect ( inputElm ) . toBeValid ( ) ;
751
+ expect ( widget . $error . email ) . toBe ( false ) ;
739
752
740
- changeInputValueTo ( 'invalid@' ) ;
741
- expect ( scope . email ) . toBeUndefined ( ) ;
742
- expect ( inputElm ) . toBeInvalid ( ) ;
743
- expect ( widget . $error . email ) . toBeTruthy ( ) ;
744
- } ) ;
753
+
754
+ expect ( scope . email ) . toEqual ( [ '[email protected] ' , '[email protected] ' ] ) ;
755
+ expect ( inputElm ) . toBeValid ( ) ;
756
+ expect ( widget . $error . email ) . toBe ( false ) ;
757
+
758
+ changeInputValueTo ( 'invalid@' ) ;
759
+ expect ( scope . email ) . toBeUndefined ( ) ;
760
+ expect ( inputElm ) . toBeInvalid ( ) ;
761
+ expect ( widget . $error . email ) . toBeTruthy ( ) ;
762
+ } ) ;
763
+ it ( 'when used with ngList (custom separator)' , function ( ) {
764
+ compileInput ( '<input ng-list=";" type="email" ng-model="email" name="alias" />' ) ;
745
765
766
+ var widget = scope . form . alias ;
767
+ changeInputValueTo ( '[email protected] ' ) ;
768
+ expect ( scope . email ) . toEqual ( [ '[email protected] ' ] ) ;
769
+ expect ( inputElm ) . toBeValid ( ) ;
770
+ expect ( widget . $error . email ) . toBe ( false ) ;
771
+
772
+
773
+ expect ( scope . email ) . toEqual ( [ '[email protected] ' , '[email protected] ' ] ) ;
774
+ expect ( inputElm ) . toBeValid ( ) ;
775
+ expect ( widget . $error . email ) . toBe ( false ) ;
776
+
777
+
778
+ expect ( scope . email ) . toBeUndefined ( ) ;
779
+ expect ( inputElm ) . toBeInvalid ( ) ;
780
+ expect ( widget . $error . email ) . toBeTruthy ( ) ;
781
+
782
+
783
+ changeInputValueTo ( 'invalid@' ) ;
784
+ expect ( scope . email ) . toBeUndefined ( ) ;
785
+ expect ( inputElm ) . toBeInvalid ( ) ;
786
+ expect ( widget . $error . email ) . toBeTruthy ( ) ;
787
+ } ) ;
788
+ } ) ;
746
789
747
- describe ( 'EMAIL_REGEXP' , function ( ) {
748
790
791
+ describe ( 'EMAIL_REGEXP' , function ( ) {
749
792
it ( 'should validate email' , function ( ) {
750
793
expect ( EMAIL_REGEXP . test ( '[email protected] ' ) ) . toBe ( true ) ;
751
794
expect ( EMAIL_REGEXP . test ( '[email protected] ' ) ) . toBe ( true ) ;
752
795
expect ( EMAIL_REGEXP . test ( '[email protected] ' ) ) . toBe ( false ) ;
753
796
} ) ;
754
797
} ) ;
798
+
755
799
} ) ;
756
800
757
801
758
802
describe ( 'url' , function ( ) {
803
+ describe ( 'should validate url' , function ( ) {
804
+ it ( 'when used simply' , function ( ) {
805
+ compileInput ( '<input type="url" ng-model="url" name="alias" />' ) ;
806
+ var widget = scope . form . alias ;
759
807
760
- it ( 'should validate url' , function ( ) {
761
- compileInput ( '<input type="url" ng-model="url" name="alias" />' ) ;
762
- var widget = scope . form . alias ;
808
+ changeInputValueTo ( 'http://www.something.com' ) ;
809
+ expect ( scope . url ) . toBe ( 'http://www.something.com' ) ;
810
+ expect ( inputElm ) . toBeValid ( ) ;
811
+ expect ( widget . $error . url ) . toBe ( false ) ;
763
812
764
- changeInputValueTo ( 'http://www.something.com' ) ;
765
- expect ( scope . url ) . toBe ( 'http://www.something.com' ) ;
766
- expect ( inputElm ) . toBeValid ( ) ;
767
- expect ( widget . $error . url ) . toBe ( false ) ;
813
+ changeInputValueTo ( 'invalid.com' ) ;
814
+ expect ( scope . url ) . toBeUndefined ( ) ;
815
+ expect ( inputElm ) . toBeInvalid ( ) ;
816
+ expect ( widget . $error . url ) . toBeTruthy ( ) ;
817
+ } ) ;
818
+ it ( 'when used with ngList (default separator)' , function ( ) {
819
+ compileInput ( '<input ng-list type="url" ng-model="url" name="alias" />' ) ;
768
820
769
- changeInputValueTo ( 'invalid.com' ) ;
770
- expect ( scope . url ) . toBeUndefined ( ) ;
771
- expect ( inputElm ) . toBeInvalid ( ) ;
772
- expect ( widget . $error . url ) . toBeTruthy ( ) ;
821
+ var widget = scope . form . alias ;
822
+ changeInputValueTo ( 'http://www.something.com' ) ;
823
+ expect ( scope . url ) . toEqual ( [ 'http://www.something.com' ] ) ;
824
+ expect ( inputElm ) . toBeValid ( ) ;
825
+ expect ( widget . $error . url ) . toBe ( false ) ;
826
+
827
+ changeInputValueTo ( 'http://www.something.com, http://www.somethingelse.com' ) ;
828
+ expect ( scope . url ) . toEqual ( [ 'http://www.something.com' , 'http://www.somethingelse.com' ] ) ;
829
+ expect ( inputElm ) . toBeValid ( ) ;
830
+ expect ( widget . $error . url ) . toBe ( false ) ;
831
+
832
+ changeInputValueTo ( 'http:' ) ;
833
+ expect ( scope . url ) . toBeUndefined ( ) ;
834
+ expect ( inputElm ) . toBeInvalid ( ) ;
835
+ expect ( widget . $error . url ) . toBeTruthy ( ) ;
836
+ } ) ;
837
+ it ( 'when used with ngList (custom separator)' , function ( ) {
838
+ compileInput ( '<input ng-list=";" type="url" ng-model="url" name="alias" />' ) ;
839
+
840
+ var widget = scope . form . alias ;
841
+ changeInputValueTo ( 'http://www.something.com' ) ;
842
+ expect ( scope . url ) . toEqual ( [ 'http://www.something.com' ] ) ;
843
+ expect ( inputElm ) . toBeValid ( ) ;
844
+ expect ( widget . $error . url ) . toBe ( false ) ;
845
+
846
+ changeInputValueTo ( 'http://www.something.com;http://www.somethingelse.com' ) ;
847
+ expect ( scope . url ) . toEqual ( [ 'http://www.something.com' , 'http://www.somethingelse.com' ] ) ;
848
+ expect ( inputElm ) . toBeValid ( ) ;
849
+ expect ( widget . $error . url ) . toBe ( false ) ;
850
+
851
+ changeInputValueTo ( 'http://www.something.com, http://www.somethingelse.com' ) ;
852
+ expect ( scope . url ) . toBeUndefined ( ) ;
853
+ expect ( inputElm ) . toBeInvalid ( ) ;
854
+ expect ( widget . $error . url ) . toBeTruthy ( ) ;
855
+
856
+ changeInputValueTo ( 'http:' ) ;
857
+ expect ( scope . url ) . toBeUndefined ( ) ;
858
+ expect ( inputElm ) . toBeInvalid ( ) ;
859
+ expect ( widget . $error . url ) . toBeTruthy ( ) ;
860
+ } ) ;
773
861
} ) ;
774
862
775
863
0 commit comments