forked from digitalBush/jquery.maskedinput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompleted.Spec.js
More file actions
122 lines (98 loc) · 3.16 KB
/
Completed.Spec.js
File metadata and controls
122 lines (98 loc) · 3.16 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
feature("Completed callback", function() {
scenario('Completing mask by typing last character',function(){
var completed=false;
given("an input with a completed callback", function(){
input.mask("99",{completed:function(){completed=true;}});
});
when("typing left to right",function(){
input.mashKeys("12");
});
then("completed callback should be called",function(){
expect(completed).toBeTruthy();
});
then("value should be correct",function(){
expect(input).toHaveValue('12');
});
});
scenario('Completing mask by typing first character',function(){
var completed=false;
given("an input with a completed callback", function(){
input.val("12").mask("99",{completed:function(){completed=true;}});
});
when("replacing first character value",function(){
input
.caret(1)
.mashKeys(function(keys){keys.type(keys.backspace)})
.mashKeys("3");
});
then("completed callback should be called",function(){
expect(completed).toBeTruthy();
});
then("value should be correct",function(){
expect(input).toHaveValue('32');
});
});
scenario('Typing last character of incomplete mask',function(){
var completed=false;
given("an input with a completed callback", function(){
input
.mask("99",{completed:function(){completed=true;}})
.mashKeys("1")
.mashKeys(function(keys){keys.type(keys.backspace)});
});
when("moving cursor to last position and typing",function(){
input.caret(1).mashKeys("5");
});
then("completed callback should not be called",function(){
expect(completed).toBeFalsy();
});
then("value should be correct",function(){
expect(input).toHaveValue('_5');
});
});
scenario('Typing last character of required portion of mask containing optional',function(){
var completed=false;
given("an input with a completed callback", function(){
input.mask("99?99",{completed:function(){completed=true;}});
});
when("typing left to right",function(){
input.mashKeys("12");
});
then("completed callback should be called",function(){
expect(completed).toBeTruthy();
});
then("value should be correct",function(){
expect(input).toHaveValue('12__');
});
});
scenario('Typing all characters of required portion of mask containing optional',function(){
var completedCount=0;
given("an input with a completed callback", function(){
input.mask("99?99",{completed:function(){completedCount++;}});
});
when("typing left to right",function(){
input.mashKeys("1234");
});
then("completed callback should be called",function(){
expect(completedCount).toEqual(1);
});
then("value should be correct",function(){
expect(input).toHaveValue('1234');
});
});
scenario('Completing mask by typing last character with literal to right',function(){
var completed=false;
given("an input with a completed callback", function(){
input.mask("99!",{completed:function(){completed=true;}});
});
when("typing left to right",function(){
input.mashKeys("12");
});
then("completed callback should be called",function(){
expect(completed).toBeTruthy();
});
then("value should be correct",function(){
expect(input).toHaveValue('12!');
});
});
});