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
204
205
206
207
208
209
210
211
|
define( [
"jquery",
"./spinner_test_helpers",
"ui/spinner"
], function( $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp;
module( "spinner: methods" );
test( "destroy", function( assert ) {
expect( 1 );
assert.domEqual( "#spin", function() {
$( "#spin" ).spinner().spinner( "destroy" );
});
});
test( "disable", function( assert ) {
expect( 15 );
var element = $( "#spin" ).val( 2 ).spinner(),
wrapper = $( "#spin" ).spinner( "widget" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" );
ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
element.spinner( "disable" );
assert.hasClasses( wrapper, "ui-state-disabled ui-spinner-disabled" );
ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" );
ok( element.is( ":disabled"), "after: input has disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value does not change on key UP" );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
equal( 2, element.val(), "mouse - value does not change on clicking up button" );
wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
equal( 2, element.val(), "mouse - value does not change on clicking down button" );
element.spinner( "stepUp", 6 );
equal( 8, element.val(), "script - stepUp 6 steps changes value");
element.spinner( "stepDown" );
equal( 7, element.val(), "script - stepDown 1 step changes value" );
element.spinner( "pageUp" );
equal( 17, element.val(), "script - pageUp 1 page changes value" );
element.spinner( "pageDown" );
equal( 7, element.val(), "script - pageDown 1 page changes value" );
});
test( "enable", function( assert ) {
expect( 5 );
var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }),
wrapper = element.spinner( "widget" );
assert.hasClasses( wrapper, "ui-spinner-disabled" );
ok( element.is( ":disabled" ), "before: input has disabled attribute" );
element.spinner( "enable" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" );
ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value changes on key UP" );
});
test( "isValid", function() {
expect( 8 );
var element = $( "#spin" ).spinner({
min: 0,
max: 10,
step: 2
}),
spinner = element.spinner( "instance" );
ok( !spinner.isValid(), "initial state is invalid" );
element.val( "this is not a number" );
ok( !spinner.isValid(), "text string is not valid" );
element.val( "0" );
ok( spinner.isValid(), "min value is valid" );
element.val( "10" );
ok( spinner.isValid(), "max value is valid" );
element.val( "4" );
ok( spinner.isValid(), "inbetween step is valid" );
element.val( "-1" );
ok( !spinner.isValid(), "below min is invalid" );
element.val( "11" );
ok( !spinner.isValid(), "above max is invalid" );
element.val( "1" );
ok( !spinner.isValid(), "step mismatch is invalid" );
});
test( "pageDown", function() {
expect( 4 );
var element = $( "#spin" ).val( -12 ).spinner({
page: 20,
min: -100
});
element.spinner( "pageDown" );
equal( element.val(), -32, "pageDown 1 page" );
element.spinner( "pageDown", 3 );
equal( element.val(), -92, "pageDown 3 pages" );
element.spinner( "pageDown" );
equal( element.val(), -100, "value close to min and pageDown 1 page" );
element.spinner( "pageDown", 10 );
equal( element.val(), -100, "value at min and pageDown 10 pages" );
});
test( "pageUp", function() {
expect( 4 );
var element = $( "#spin" ).val( 12 ).spinner({
page: 20,
max: 100
});
element.spinner( "pageUp" );
equal( element.val(), 32, "pageUp 1 page" );
element.spinner( "pageUp", 3 );
equal( element.val(), 92, "pageUp 3 pages" );
element.spinner( "pageUp" );
equal( element.val(), 100, "value close to max and pageUp 1 page" );
element.spinner( "pageUp", 10 );
equal( element.val(), 100, "value at max and pageUp 10 pages" );
});
test( "stepDown", function() {
expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner({
step: 2,
min: -15
});
element.spinner( "stepDown" );
equal( element.val(), "-1", "stepDown 1 step" );
element.spinner( "stepDown", 5 );
equal( element.val(), "-11", "stepDown 5 steps" );
element.spinner( "stepDown", 4 );
equal( element.val(), "-15", "close to min and stepDown 4 steps" );
element.spinner( "stepDown" );
equal( element.val(), "-15", "at min and stepDown 1 step" );
});
test( "stepUp", function() {
expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner({
step: 2,
max: 16
});
element.spinner( "stepUp" );
equal( element.val(), 2, "stepUp 1 step" );
element.spinner( "stepUp", 5 );
equal( element.val(), 12, "stepUp 5 steps" );
element.spinner( "stepUp", 4 );
equal( element.val(), 16, "close to max and stepUp 4 steps" );
element.spinner( "stepUp" );
equal( element.val(), 16, "at max and stepUp 1 step" );
});
test( "value", function() {
expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner({
step: 3
});
element.spinner( "value", 10 );
equal( element.val(), 9, "change value via value method" );
equal( element.spinner( "value" ), 9, "get value via value method" );
});
test( "widget", function() {
expect( 2 );
var element = $( "#spin" ).spinner(),
widgetElement = element.spinner( "widget" );
equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
});
} );
|