Focus.Spec.js
5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
feature("Focusing A Masked Input",function(){
scenario("Mask starts with a placeholder",function(){
given("a mask beginning with a placeholder",function(){
input.mask("9");
});
when("focusing",function(){
input.focus();
});
waits(20);
then("placeholder text should be correct",function(){
expect(input).toHaveValue('_');
});
and("caret position should be correct",function(){
var caret=input.caret();
expect(caret.begin).toEqual(0);
expect(caret.end).toEqual(0);
});
});
scenario("Mask starts with a literal",function(){
given("a mask beginning with a literal",function(){
input.mask("(9)");
});
when("focusing",function(){
input.focus();
});
waits(20);
then("placeholder text should be correct",function(){
expect(input).toHaveValue('(_)');
});
and("caret position should be correct",function(){
var caret=input.caret();
expect(caret.begin).toEqual(1);
expect(caret.end).toEqual(1);
});
});
scenario("Masking a hidden input",function(){
var error;
$(window).on("error.test",function(err){error=err;})
given("a mask on a hidden input",function(){
input.hide().mask("9");
});
when("focusing input",function(){
input.focus();
});
waits(1);
then("should not throw an error",function(){
expect(error).toBeUndefined();
})
});
scenario("Mask contains a partial value with autoclear set to false",function(){
given("the input has a partial value",function(){
input.val("1");
});
given("a mask with two placeholders and autoclear=false",function(){
input.mask("99", { autoclear: false });
});
when("focusing on the input",function(){
input.focus();
});
then("the value should be partially filled out",function(){
expect(input).toHaveValue("1_");
});
then("the input partial value should remain",function(){
expect(input).toHaveValue("1_");
});
});
scenario("Mask containing optional mask ?",function(){
given("the input has a partial value",function(){
input.val("99");
});
given("a optional mask on input",function(){
input.mask("9?9");
});
when("focusing input",function(){
input.focus();
});
waits(1);
then("caret position should be correct",function(){
var caret=input.caret();
expect(caret.begin).toEqual(0);
expect(caret.end).toEqual(2);
});
});
});
feature("Leaving A Masked Input",function(){
scenario("All placeholders filled",function(){
given("a mask with two placeholders",function(){
input.mask("99");
});
when("typing two characters and blurring",function(){
input.mashKeys("12").blur();
});
then("value should be correct",function(){
expect(input).toHaveValue("12");
});
});
scenario("Empty placeholders remaining",function(){
given("a mask with two placeholders",function(){
input.mask("99");
});
when("typing one character and blurring",function(){
input.mashKeys("1").blur();
});
then("value should be empty",function(){
expect(input).toHaveValue("");
});
});
scenario("Empty placeholders remaining with autoclear set to false",function(){
given("a mask with two placeholders",function(){
input.mask("99", { autoclear: false });
});
when("typing one character and blurring",function(){
input.caret(0);
input.mashKeys("1")
input.blur();
});
then("value should remain visible with placeholders",function(){
expect(input).toHaveValue("1_");
});
});
});
feature("Optional marker",function(){
scenario("Placeholders not filled to marker",function(){
given("a mask with an optional marker",function(){
input.mask("99?99");
});
when("typing one character and leaving",function(){
input.mashKeys("1").blur();
});
then("value should be empty",function(){
expect(input).toHaveValue("");
});
});
scenario("Placeholders not filled to marker and autoclear = false", function() {
given("a mask with an optional marker",function(){
input.mask("99?99", { autoclear: false });
});
when("typing one character and leaving",function(){
input.mashKeys("1").blur();
});
then("value should be empty",function(){
expect(input).toHaveValue("1___");
});
});
scenario("Placeholders filled to marker",function(){
given("a mask with an optional marker",function(){
input.mask("99?99");
});
when("typing two characters and leaving",function(){
input.mashKeys("12").blur();
});
then("value should remain",function(){
expect(input).toHaveValue("12");
});
});
scenario("Placeholders filled to marker and autoclear = false", function() {
given("a mask with an optional marker",function(){
input.mask("99?99", { autoclear: false });
});
when("typing two characters and leaving",function(){
input.mashKeys("12").blur();
});
then("value should remain",function(){
expect(input).toHaveValue("12");
});
});
scenario("Placeholders filled, one marker filled, and autoclear = false", function() {
given("a mask with an optional marker",function(){
input.mask("99?99", { autoclear: false });
});
when("typing three characters and leaving",function(){
input.mashKeys("123").blur();
});
then("value should remain",function(){
expect(input).toHaveValue("123");
});
});
scenario("Placeholders and markers filled, and autoclear = false", function() {
given("a mask with an optional marker",function(){
input.mask("99?99", { autoclear: false });
});
when("typing four characters and leaving",function(){
input.mashKeys("1234").blur();
});
then("value should remain",function(){
expect(input).toHaveValue("1234");
});
});
});