1- xdescribe ( 'uiMask' , function ( ) {
1+ describe ( 'uiMask' , function ( ) {
22
3- var inputHtml = "<input ui-mask=\"'(9)9'\" ng-model='x'>" ;
4- var $compile , $rootScope , element ;
3+ var staticMaskHtml = "<input ui-mask='(9)9' ng-model='x'>" ;
4+ var dynamicMaskHtml = "<input ui-mask='{{mask}}' ng-model='x'>" ;
5+ var compileElement , scope ;
56
67 beforeEach ( module ( 'ui.directives' ) ) ;
7- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ ) {
8- $rootScope = _$rootScope_ ;
9- $compile = _$compile_ ;
8+ beforeEach ( inject ( function ( $rootScope , $compile ) {
9+ scope = $rootScope ;
10+ compileElement = function ( html ) {
11+ return $compile ( html ) ( scope ) ;
12+ } ;
1013 } ) ) ;
1114
1215 describe ( 'ui changes on model changes' , function ( ) {
1316 it ( 'should update ui valid model value' , function ( ) {
14- $rootScope . x = undefined ;
15- element = $compile ( inputHtml ) ( $rootScope ) ;
16- $rootScope . $digest ( ) ;
17- expect ( element . val ( ) ) . toBe ( '' ) ;
18- $rootScope . $apply ( function ( ) {
19- $rootScope . x = 12 ;
20- } ) ;
17+ var element = compileElement ( staticMaskHtml ) ;
18+ scope . $digest ( ) ;
19+ expect ( element . val ( ) ) . toBe ( '(_)_' ) ;
20+ scope . $apply ( 'x = 12' ) ;
2121 expect ( element . val ( ) ) . toBe ( '(1)2' ) ;
2222 } ) ;
2323 it ( 'should wipe out ui on invalid model value' , function ( ) {
24- $rootScope . x = 12 ;
25- element = $compile ( inputHtml ) ( $rootScope ) ;
26- $rootScope . $digest ( ) ;
24+ var element = compileElement ( staticMaskHtml ) ;
25+ scope . $apply ( 'x = 12' ) ;
2726 expect ( element . val ( ) ) . toBe ( '(1)2' ) ;
28- $rootScope . $apply ( function ( ) {
29- $rootScope . x = 1 ;
30- } ) ;
27+ scope . $apply ( 'x = 1' ) ;
3128 expect ( element . val ( ) ) . toBe ( '' ) ;
3229 } ) ;
3330 } ) ;
3431
35- describe ( 'model binding on ui change' , function ( ) {
36- //TODO: was having har time writing those tests, will open a separate issue for those
32+ describe ( 'interpolated masks' , function ( ) {
33+ it ( 'should allow mask to change' , function ( ) {
34+ var element = compileElement ( dynamicMaskHtml ) ;
35+ scope . $apply ( 'mask = "(99)99"; x = 1234' ) ;
36+ expect ( element . val ( ) ) . toBe ( '(12)34' ) ;
37+ scope . $apply ( 'mask = "(9)9"' ) ;
38+ expect ( element . val ( ) ) . toBe ( '(1)2' ) ;
39+ } ) ;
3740 } ) ;
3841
39- describe ( 'should fail ', function ( ) {
40- it ( 'errors on missing quotes ' , function ( ) {
41- $rootScope . x = 42 ;
42- var errorInputHtml = "<input ui-mask=\"(9)9\" ng-model='x'>" ;
43- element = $compile ( errorInputHtml ) ( $rootScope ) ;
44- expect ( $rootScope . $digest ) . toThrow ( 'The Mask widget is not correctly set up' ) ;
42+ xdescribe ( 'model binding on ui change ', function ( ) {
43+ it ( 'should change model when element value changes ' , function ( ) {
44+ var element = compileElement ( staticMaskHtml ) ;
45+ element . val ( '(2)4' ) ;
46+ element . trigger ( 'blur' ) ;
47+ expect ( scope . x ) . toBe ( 24 ) ;
4548 } ) ;
4649 } ) ;
50+
4751} ) ;
0 commit comments