1- describe ( "Focus Specifications" , function ( ) {
2- var input ;
3-
4- beforeEach ( function ( ) {
5- input =
6- $ ( "<input />" )
7- . appendTo ( "body" ) ;
1+ feature ( "Focusing A Masked Input" , function ( ) {
2+ scenario ( "Mask starts with a placeholder" , function ( ) {
3+ given ( "a mask beginning with a placeholder" , function ( ) {
4+ input . mask ( "9" ) ;
5+ } ) ;
6+ when ( "focusing" , function ( ) {
7+ input . focus ( ) ;
8+ } ) ;
9+ waits ( 1 ) ;
10+ then ( "placeholder text should be correct" , function ( ) {
11+ expect ( input ) . toHaveValue ( '_' ) ;
12+ } ) ;
13+ and ( "caret position should be correct" , function ( ) {
14+ var caret = input . caret ( ) ;
15+ expect ( caret . begin ) . toEqual ( 0 ) ;
16+ expect ( caret . end ) . toEqual ( 0 ) ;
17+ } ) ;
818 } ) ;
9-
10- afterEach ( function ( ) {
11- input . remove ( ) ;
12- } ) ;
13-
14- describe ( "when focusing with a mask that starts with a placeholder" , function ( ) {
15- beforeEach ( function ( ) {
16- input . mask ( "9" ) . focus ( ) ;
17- } ) ;
18-
19- it ( "should have the correct placeholder text" , function ( ) {
20- expect ( input ) . toHaveValue ( '_' ) ;
21- } ) ;
22-
23- it ( "should have the correct caret position" , function ( ) {
24- waits ( 1 ) ;
25- runs ( function ( ) {
26- var caret = input . caret ( ) ;
27- expect ( caret . begin ) . toEqual ( 0 ) ;
28- expect ( caret . end ) . toEqual ( 0 ) ;
29- } ) ;
30- } ) ;
31-
32- describe ( "when blurring" , function ( ) {
33- beforeEach ( function ( ) {
34- input . blur ( ) ;
35- } ) ;
36-
37- it ( "should have an empty value" , function ( ) {
38- expect ( input ) . toHaveValue ( '' ) ;
39- } ) ;
40- } ) ;
19+
20+ scenario ( "Mask starts with a literal" , function ( ) {
21+ given ( "a mask beginning with a literal" , function ( ) {
22+ input . mask ( "(9)" ) ;
23+ } ) ;
24+ when ( "focusing" , function ( ) {
25+ input . focus ( ) ;
26+ } ) ;
27+ waits ( 1 ) ;
28+ then ( "placeholder text should be correct" , function ( ) {
29+ expect ( input ) . toHaveValue ( '(_)' ) ;
30+ } ) ;
31+ and ( "caret position should be correct" , function ( ) {
32+ var caret = input . caret ( ) ;
33+ expect ( caret . begin ) . toEqual ( 1 ) ;
34+ expect ( caret . end ) . toEqual ( 1 ) ;
35+ } ) ;
4136 } ) ;
42-
43- describe ( "when focusing with a mask that starts with a literal" , function ( ) {
44- beforeEach ( function ( ) {
45- input . mask ( "(9)" ) . focus ( ) ;
46- } ) ;
47-
48- it ( "should have the correct placeholder text" , function ( ) {
49- expect ( input ) . toHaveValue ( '(_)' ) ;
50- } ) ;
51-
52- it ( "should have the correct caret position" , function ( ) {
53- waits ( 1 ) ;
54- runs ( function ( ) {
55- var caret = input . caret ( ) ;
56- expect ( caret . begin ) . toEqual ( 1 ) ;
57- expect ( caret . end ) . toEqual ( 1 ) ;
58- } ) ;
59- } ) ;
60-
61- describe ( "when blurring" , function ( ) {
62- beforeEach ( function ( ) {
63- input . blur ( ) ;
64- } ) ;
65-
66- it ( "should have an empty value" , function ( ) {
67- expect ( input ) . toHaveValue ( '' ) ;
68- } ) ;
69- } ) ;
37+ } ) ;
38+
39+ feature ( "Leaving A Masked Input" , function ( ) {
40+ scenario ( "All placeholders filled" , function ( ) {
41+ given ( "a mask with two placeholders" , function ( ) {
42+ input . mask ( "99" ) ;
43+ } ) ;
44+ when ( "typing two characters and blurring" , function ( ) {
45+ input . mashKeys ( "12" ) . blur ( ) ;
46+ } ) ;
47+ then ( "value should be correct" , function ( ) {
48+ expect ( input ) . toHaveValue ( "12" ) ;
49+ } ) ;
7050 } ) ;
71- } ) ;
51+
52+ scenario ( "Empty placeholders remaining" , function ( ) {
53+ given ( "a mask with two placeholders" , function ( ) {
54+ input . mask ( "99" ) ;
55+ } ) ;
56+ when ( "typing one character and blurring" , function ( ) {
57+ input . mashKeys ( "1" ) . blur ( ) ;
58+ } ) ;
59+ then ( "value should be empty" , function ( ) {
60+ expect ( input ) . toHaveValue ( "" ) ;
61+ } ) ;
62+ } ) ;
63+ } ) ;
64+
65+ feature ( "Optional marker" , function ( ) {
66+ scenario ( "Placeholders not filled to marker" , function ( ) {
67+ given ( "a mask with an optional marker" , function ( ) {
68+ input . mask ( "99?99" ) ;
69+ } ) ;
70+ when ( "typing one character and leaving" , function ( ) {
71+ input . mashKeys ( "1" ) . blur ( ) ;
72+ } ) ;
73+ then ( "value should be empty" , function ( ) {
74+ expect ( input ) . toHaveValue ( "" ) ;
75+ } ) ;
76+ } ) ;
77+
78+ scenario ( "Placeholders filled to marker" , function ( ) {
79+ given ( "a mask with an optional marker" , function ( ) {
80+ input . mask ( "99?99" ) ;
81+ } ) ;
82+ when ( "typing two characters and leaving" , function ( ) {
83+ input . mashKeys ( "12" ) . blur ( ) ;
84+ } ) ;
85+ then ( "value should remain" , function ( ) {
86+ expect ( input ) . toHaveValue ( "12" ) ;
87+ } ) ;
88+ } ) ;
89+ } ) ;
0 commit comments