headless-squirrel 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +55 -0
- data/Rakefile +27 -0
- data/bin/jstest +10 -0
- data/lib/headless_squirrel.rb +2 -0
- data/lib/headless_squirrel/console.rb +24 -0
- data/lib/headless_squirrel/runner.rb +70 -0
- data/lib/headless_squirrel/test.rb +17 -0
- data/lib/headless_squirrel/test_case.rb +158 -0
- data/test/fixtures/a_unit_test.html +27 -0
- data/test/fixtures/a_unit_test.js +22 -0
- data/test/fixtures/syntax_error.html +27 -0
- data/test/fixtures/syntax_error.js +5 -0
- data/test/fixtures/type_error.html +27 -0
- data/test/fixtures/type_error.js +1 -0
- data/test/regression/prototype/unit/ajax_test.html +29 -0
- data/test/regression/prototype/unit/array_test.html +28 -0
- data/test/regression/prototype/unit/assets/prototype.js +4900 -0
- data/test/regression/prototype/unit/assets/unittest.css +50 -0
- data/test/regression/prototype/unit/assets/unittest.js +615 -0
- data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
- data/test/regression/prototype/unit/base_test.html +27 -0
- data/test/regression/prototype/unit/class_test.html +27 -0
- data/test/regression/prototype/unit/date_test.html +27 -0
- data/test/regression/prototype/unit/dom_test.html +304 -0
- data/test/regression/prototype/unit/element_mixins_test.html +30 -0
- data/test/regression/prototype/unit/enumerable_test.html +35 -0
- data/test/regression/prototype/unit/event_test.html +31 -0
- data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
- data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
- data/test/regression/prototype/unit/fixtures/array.html +1 -0
- data/test/regression/prototype/unit/fixtures/class.js +83 -0
- data/test/regression/prototype/unit/fixtures/content.html +1 -0
- data/test/regression/prototype/unit/fixtures/data.json +1 -0
- data/test/regression/prototype/unit/fixtures/dom.css +84 -0
- data/test/regression/prototype/unit/fixtures/dom.html +278 -0
- data/test/regression/prototype/unit/fixtures/dom.js +17 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
- data/test/regression/prototype/unit/fixtures/empty.html +0 -0
- data/test/regression/prototype/unit/fixtures/empty.js +1 -0
- data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
- data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
- data/test/regression/prototype/unit/fixtures/event.html +4 -0
- data/test/regression/prototype/unit/fixtures/form.html +108 -0
- data/test/regression/prototype/unit/fixtures/function.js +13 -0
- data/test/regression/prototype/unit/fixtures/hash.js +25 -0
- data/test/regression/prototype/unit/fixtures/hello.js +1 -0
- data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
- data/test/regression/prototype/unit/fixtures/object.html +6 -0
- data/test/regression/prototype/unit/fixtures/object.js +7 -0
- data/test/regression/prototype/unit/fixtures/position.html +9 -0
- data/test/regression/prototype/unit/fixtures/selector.html +71 -0
- data/test/regression/prototype/unit/fixtures/string.js +8 -0
- data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
- data/test/regression/prototype/unit/form_test.html +135 -0
- data/test/regression/prototype/unit/function_test.html +27 -0
- data/test/regression/prototype/unit/hash_test.html +27 -0
- data/test/regression/prototype/unit/number_test.html +27 -0
- data/test/regression/prototype/unit/object_test.html +32 -0
- data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
- data/test/regression/prototype/unit/position_test.html +36 -0
- data/test/regression/prototype/unit/prototype_test.html +27 -0
- data/test/regression/prototype/unit/range_test.html +27 -0
- data/test/regression/prototype/unit/regexp_test.html +27 -0
- data/test/regression/prototype/unit/selector_test.html +98 -0
- data/test/regression/prototype/unit/string_test.html +27 -0
- data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
- data/test/regression/prototype/unit/tests/array_test.js +186 -0
- data/test/regression/prototype/unit/tests/base_test.js +43 -0
- data/test/regression/prototype/unit/tests/class_test.js +136 -0
- data/test/regression/prototype/unit/tests/date_test.js +5 -0
- data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
- data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
- data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
- data/test/regression/prototype/unit/tests/event_test.js +235 -0
- data/test/regression/prototype/unit/tests/form_test.js +382 -0
- data/test/regression/prototype/unit/tests/function_test.js +133 -0
- data/test/regression/prototype/unit/tests/hash_test.js +178 -0
- data/test/regression/prototype/unit/tests/number_test.js +44 -0
- data/test/regression/prototype/unit/tests/object_test.js +180 -0
- data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
- data/test/regression/prototype/unit/tests/position_test.js +44 -0
- data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
- data/test/regression/prototype/unit/tests/range_test.js +58 -0
- data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
- data/test/regression/prototype/unit/tests/selector_test.js +408 -0
- data/test/regression/prototype/unit/tests/string_test.js +548 -0
- data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
- data/test/regression/prototype/unit/unittest_test.html +45 -0
- data/test/regression/prototype/upstream +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_alt_text.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_collection.js +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result2.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_tagged.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_text.html +1 -0
- data/test/regression/scriptaculous/unit/_ajax_updater_result.html +20 -0
- data/test/regression/scriptaculous/unit/_autocomplete_result.html +11 -0
- data/test/regression/scriptaculous/unit/_autocomplete_result_nobr.html +1 -0
- data/test/regression/scriptaculous/unit/ajax_autocompleter_test.html +243 -0
- data/test/regression/scriptaculous/unit/ajax_inplaceeditor_test.html +895 -0
- data/test/regression/scriptaculous/unit/assets/builder.js +134 -0
- data/test/regression/scriptaculous/unit/assets/controls.js +963 -0
- data/test/regression/scriptaculous/unit/assets/dragdrop.js +973 -0
- data/test/regression/scriptaculous/unit/assets/effects.js +1122 -0
- data/test/regression/scriptaculous/unit/assets/javascripttest.rb +203 -0
- data/test/regression/scriptaculous/unit/assets/prototype.js +4320 -0
- data/test/regression/scriptaculous/unit/assets/scriptaculous.js +66 -0
- data/test/regression/scriptaculous/unit/assets/slider.js +273 -0
- data/test/regression/scriptaculous/unit/assets/sound.js +57 -0
- data/test/regression/scriptaculous/unit/assets/unittest.js +566 -0
- data/test/regression/scriptaculous/unit/bdd_test.html +150 -0
- data/test/regression/scriptaculous/unit/builder_test.html +262 -0
- data/test/regression/scriptaculous/unit/dragdrop_test.html +131 -0
- data/test/regression/scriptaculous/unit/effects_test.html +547 -0
- data/test/regression/scriptaculous/unit/element_test.html +116 -0
- data/test/regression/scriptaculous/unit/icon.png +0 -0
- data/test/regression/scriptaculous/unit/index.html +70 -0
- data/test/regression/scriptaculous/unit/loading_test.html +41 -0
- data/test/regression/scriptaculous/unit/position_clone_test.html +312 -0
- data/test/regression/scriptaculous/unit/slider_test.html +437 -0
- data/test/regression/scriptaculous/unit/sortable_test.html +205 -0
- data/test/regression/scriptaculous/unit/string_test.html +71 -0
- data/test/regression/scriptaculous/unit/unittest_test.html +154 -0
- data/test/regression/scriptaculous/upstream +1 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/runner_test.rb +165 -0
- data/test/unit/test_case_test.rb +207 -0
- data/test/unit/test_test.rb +24 -0
- metadata +209 -0
@@ -0,0 +1,437 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<title>script.aculo.us Unit test file</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
<script src="assets/prototype.js" type="text/javascript"></script>
|
8
|
+
<script src="assets/scriptaculous.js" type="text/javascript"></script>
|
9
|
+
<script src="assets/unittest.js" type="text/javascript"></script>
|
10
|
+
<link rel="stylesheet" href="../test.css" type="text/css" />
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>script.aculo.us Unit test file</h1>
|
14
|
+
<p>
|
15
|
+
Tests for slider.js
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<div id="track1" style="width:200px;background-color:#aaa;height:5px;">
|
19
|
+
<div id="handle1" style="width:15px;height:25px;background-color:#f00;"> </div>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div id="track2-vertical" style="height:100px;background-color:#aaa;width:5px;">
|
23
|
+
<div id="handle2-vertical" style="width:25px;height:10px;background-color:#f00;"> </div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div id="track2-horizontal" style="height:5px;background-color:#aaa;width:100px;">
|
27
|
+
<div id="handle2-horizontal" style="width:10px;height:25px;background-color:#f00;"> </div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div id="track3" style="width:300px;background-color:#cfb;height:30px;">
|
31
|
+
<span id="handle3-1">1</span>
|
32
|
+
<span id="handle3-2">2</span>
|
33
|
+
<span id="handle3-3">3</span>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="track4" style="width:300px;position:relative;background-color:#cbf;height:30px;">
|
37
|
+
<span id="handle4-1" style="top:0;left:0;position:absolute;background-color:#f00;">1</span>
|
38
|
+
<span id="handle4-2" style="top:0;left:0;position:absolute;background-color:#0f0;">2</span>
|
39
|
+
<span id="handle4-3" style="top:0;left:0;position:absolute;background-color:#00f;">3</span>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<div id="track5" style="width:300px;background-color:#cbf;height:30px;position:relative;z-index:0;">
|
43
|
+
<div id="handle5-1" style="top:0;left:0;position:absolute;background-color:#f00;z-index:2">1</div>
|
44
|
+
<div id="handle5-2" style="top:0;left:0;position:absolute;background-color:#0f0;z-index:2">2</div>
|
45
|
+
<div id="handle5-3" style="top:0;left:0;position:absolute;background-color:#00f;z-index:2">3</div>
|
46
|
+
|
47
|
+
<div id="span5-1" style="top:0;left:0;position:absolute;background-color:#000;height:20px;z-index:1;"> </div>
|
48
|
+
<div id="span5-2" style="top:0;left:0;position:absolute;background-color:#444;height:20px;z-index:1;"> </div>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="track6" style="width:20px;background-color:#cbf;height:100px;position:relative;z-index:0;">
|
52
|
+
<div id="handle6-1" style="top:0;left:0;height:13px;position:absolute;background-color:#f00;z-index:2">1</div>
|
53
|
+
<div id="handle6-2" style="top:0;left:0;height:13px;position:absolute;background-color:#0f0;z-index:2">2</div>
|
54
|
+
<div id="handle6-3" style="top:0;left:0;height:13px;position:absolute;background-color:#00f;z-index:2">3</div>
|
55
|
+
|
56
|
+
<div id="span6-1" style="top:0;left:0;position:absolute;background-color:#000;width:20px;z-index:1;"> </div>
|
57
|
+
<div id="span6-2" style="top:0;left:0;position:absolute;background-color:#444;width:20px;z-index:1;"> </div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="track7" style="width:200px;background-color:#cbf;height:30px;position:relative;z-index:0;">
|
61
|
+
<div id="handle7-1" style="top:0;left:0;position:absolute;background-color:#f88;z-index:2">1</div>
|
62
|
+
<div id="handle7-2" style="top:0;left:0;position:absolute;background-color:#8f8;z-index:2">2</div>
|
63
|
+
<div id="handle7-3" style="top:0;left:0;position:absolute;background-color:#88f;z-index:2">3</div>
|
64
|
+
|
65
|
+
<div id="span7-1" style="top:0;left:0;position:absolute;background-color:#000;height:20px;z-index:1;"> </div>
|
66
|
+
<div id="span7-2" style="top:0;left:0;position:absolute;background-color:#444;height:20px;z-index:1;"> </div>
|
67
|
+
|
68
|
+
<div id="span7-start" style="top:0;left:0;position:absolute;background-color:#f00;height:20px;z-index:1;"> </div>
|
69
|
+
<div id="span7-end" style="top:0;left:0;position:absolute;background-color:#00f;height:20px;z-index:1;"> </div>
|
70
|
+
</div>
|
71
|
+
|
72
|
+
|
73
|
+
<div id="debug"> </div>
|
74
|
+
|
75
|
+
<!-- Log output -->
|
76
|
+
<div id="testlog"> </div>
|
77
|
+
|
78
|
+
<!-- Tests follow -->
|
79
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
80
|
+
// <![CDATA[
|
81
|
+
var globalValue;
|
82
|
+
|
83
|
+
new Test.Unit.Runner({
|
84
|
+
|
85
|
+
testSliderBasics: function() { with(this) {
|
86
|
+
var slider = new Control.Slider('handle1', 'track1');
|
87
|
+
assertInstanceOf(Control.Slider, slider);
|
88
|
+
|
89
|
+
assertEqual('horizontal', slider.axis);
|
90
|
+
assertEqual(false, slider.disabled);
|
91
|
+
assertEqual(0, slider.value);
|
92
|
+
|
93
|
+
slider.dispose();
|
94
|
+
}},
|
95
|
+
|
96
|
+
testSliderValues: function() { with(this) {
|
97
|
+
['horizontal', 'vertical'].each( function(axis) {
|
98
|
+
var slider = new Control.Slider('handle2-'+axis, 'track2-'+axis, {values:[0.2,0.4,0.6,0.8,1],axis:axis});
|
99
|
+
assertEqual(axis, slider.axis);
|
100
|
+
assertEqual(0.2, slider.value);
|
101
|
+
|
102
|
+
slider.setValue(0.35);
|
103
|
+
assertEqual(0.4, slider.value);
|
104
|
+
|
105
|
+
slider.setValueBy(0.1);
|
106
|
+
assertEqual(0.6, slider.value);
|
107
|
+
slider.setValueBy(-0.6);
|
108
|
+
assertEqual(0.2, slider.value);
|
109
|
+
|
110
|
+
slider.setValue(1);
|
111
|
+
assertEqual(1, slider.value);
|
112
|
+
|
113
|
+
slider.setValue(-2);
|
114
|
+
assertEqual(0.2, slider.value);
|
115
|
+
|
116
|
+
slider.setValue(55555);
|
117
|
+
assertEqual(1, slider.value);
|
118
|
+
|
119
|
+
// leave active to be able to play around with the sliders
|
120
|
+
// slider.dispose();
|
121
|
+
});
|
122
|
+
assertEqual("90px", $('handle2-horizontal').style.left);
|
123
|
+
assertEqual("90px", $('handle2-vertical').style.top);
|
124
|
+
}},
|
125
|
+
|
126
|
+
testSliderInitialValues: function() { with(this) {
|
127
|
+
var slider = new Control.Slider('handle1', 'track1',{sliderValue:0.5});
|
128
|
+
assertEqual(0.5, slider.value);
|
129
|
+
|
130
|
+
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
131
|
+
sliderValue:[50,145,170],
|
132
|
+
values:[50,150,160,170,180],
|
133
|
+
range:$R(50,180)
|
134
|
+
});
|
135
|
+
assertEqual(50, slider.value);
|
136
|
+
assertEqual(50, slider.values[0]);
|
137
|
+
assertEqual(150, slider.values[1]);
|
138
|
+
assertEqual(170, slider.values[2]);
|
139
|
+
slider.dispose();
|
140
|
+
|
141
|
+
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
142
|
+
sliderValue:[50,145,170],
|
143
|
+
values:[50,150,160,170,180]
|
144
|
+
});
|
145
|
+
assertEqual(50, slider.value);
|
146
|
+
assertEqual(50, slider.values[0]);
|
147
|
+
assertEqual(150, slider.values[1]);
|
148
|
+
assertEqual(170, slider.values[2]);
|
149
|
+
slider.dispose();
|
150
|
+
|
151
|
+
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
152
|
+
restricted:true,
|
153
|
+
sliderValue:[50,145,170],
|
154
|
+
values:[50,150,160,170,180]
|
155
|
+
});
|
156
|
+
assertEqual(50, slider.value);
|
157
|
+
assertEqual(50, slider.values[0]);
|
158
|
+
assertEqual(150, slider.values[1]);
|
159
|
+
assertEqual(170, slider.values[2]);
|
160
|
+
slider.dispose();
|
161
|
+
}},
|
162
|
+
|
163
|
+
testSliderOnChange: function() { with(this) {
|
164
|
+
var slider = new Control.Slider('handle1', 'track1', { onChange:function(v){ globalValue = v; } });
|
165
|
+
slider.setValue(1);
|
166
|
+
assert(1, globalValue);
|
167
|
+
assert(1, slider.value);
|
168
|
+
|
169
|
+
slider.setDisabled();
|
170
|
+
slider.setValue(0.5);
|
171
|
+
assert(1, globalValue);
|
172
|
+
assert(1, slider.value);
|
173
|
+
|
174
|
+
slider.setEnabled();
|
175
|
+
slider.setValue(0.2);
|
176
|
+
assert(0.2, globalValue);
|
177
|
+
assert(0.2, slider.value);
|
178
|
+
|
179
|
+
// s.event should be null if setValue is called from script
|
180
|
+
var slider = new Control.Slider(['handle3-1','handle3-2','handle3-3'], 'track3', {
|
181
|
+
onChange:function(v, s){ if(!s.event) globalValue = v; } });
|
182
|
+
|
183
|
+
slider.setValue(0.5,1);
|
184
|
+
assertEqual([0,0.5,0].inspect(), globalValue.inspect());
|
185
|
+
assert(!slider.event);
|
186
|
+
|
187
|
+
slider.dispose();
|
188
|
+
}},
|
189
|
+
|
190
|
+
testMultipleHandles: function() { with(this) {
|
191
|
+
var slider = new Control.Slider(['handle3-1','handle3-2','handle3-3'], 'track3', {range:$R(0,300)});
|
192
|
+
assertInstanceOf(Control.Slider, slider);
|
193
|
+
|
194
|
+
slider.setValue(20, 0);
|
195
|
+
slider.setValue(50, 1);
|
196
|
+
slider.setValue(70, 2);
|
197
|
+
assertEqual(20, slider.values[0]);
|
198
|
+
assertEqual(50, slider.values[1]);
|
199
|
+
assertEqual(70, slider.values[2]);
|
200
|
+
assertEqual("20px", slider.handles[0].style.left);
|
201
|
+
assertEqual("49px", slider.handles[1].style.left);
|
202
|
+
assertEqual("68px", slider.handles[2].style.left);
|
203
|
+
|
204
|
+
// should change last manipulated handled by -10,
|
205
|
+
// so check for handle with idx 2
|
206
|
+
slider.setValueBy(-10);
|
207
|
+
assertEqual(60, slider.values[2]);
|
208
|
+
|
209
|
+
slider.setValueBy(10, 0);
|
210
|
+
assertEqual(20, slider.values[0]);
|
211
|
+
slider.setValueBy(10, 1);
|
212
|
+
assertEqual(60, slider.values[1]);
|
213
|
+
slider.setValueBy(20, slider.activeHandleIdx);
|
214
|
+
assertEqual(80, slider.values[1]);
|
215
|
+
}},
|
216
|
+
|
217
|
+
testMultipleHandlesValues: function() { with(this) {
|
218
|
+
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {values:[50,150,160,170,180],range:$R(50,180)});
|
219
|
+
assertInstanceOf(Control.Slider, slider);
|
220
|
+
|
221
|
+
slider.setValue(20, 0);
|
222
|
+
slider.setValue(150, 2);
|
223
|
+
slider.setValue(179, 1);
|
224
|
+
|
225
|
+
assertEqual(50, slider.values[0]);
|
226
|
+
assertEqual(150, slider.values[2]);
|
227
|
+
assertEqual(180, slider.values[1]);
|
228
|
+
|
229
|
+
assertEqual("0px", slider.handles[0].style.left);
|
230
|
+
assertEqual("225px", slider.handles[2].style.left);
|
231
|
+
assertEqual("293px", slider.handles[1].style.left);
|
232
|
+
|
233
|
+
assertEqual($R(50,150).inspect(), slider.getRange().inspect());
|
234
|
+
assertEqual(30, slider.getRange(1).end-slider.getRange(1).start);
|
235
|
+
}},
|
236
|
+
|
237
|
+
testMultipleHandlesSpans: function() { with(this) {
|
238
|
+
var slider = new Control.Slider(['handle5-1','handle5-2','handle5-3'], 'track5',
|
239
|
+
{spans:['span5-1','span5-2'],range:$R(0,300)});
|
240
|
+
assertInstanceOf(Control.Slider, slider);
|
241
|
+
|
242
|
+
slider.setValue(20, 0);
|
243
|
+
slider.setValue(100, 1);
|
244
|
+
slider.setValue(150, 2);
|
245
|
+
|
246
|
+
assertEqual("20px", $('span5-1').style.left);
|
247
|
+
assertEqual("78px", $('span5-1').style.width);
|
248
|
+
assertEqual("98px", $('span5-2').style.left);
|
249
|
+
assertEqual("49px", $('span5-2').style.width);
|
250
|
+
|
251
|
+
slider.setValue(30, 0);
|
252
|
+
slider.setValue(110, 1);
|
253
|
+
slider.setValue(90, 2);
|
254
|
+
|
255
|
+
assertEqual("29px", $('span5-1').style.left);
|
256
|
+
assertEqual("59px", $('span5-1').style.width);
|
257
|
+
assertEqual("88px", $('span5-2').style.left);
|
258
|
+
assertEqual("20px", $('span5-2').style.width);
|
259
|
+
|
260
|
+
slider.dispose();
|
261
|
+
}},
|
262
|
+
|
263
|
+
testMultipleHandlesSpansStartEnd: function() { with(this) {
|
264
|
+
var slider = new Control.Slider(['handle7-1','handle7-2','handle7-3'], 'track7',
|
265
|
+
{ spans:['span7-1','span7-2'],
|
266
|
+
startSpan:'span7-start',
|
267
|
+
endSpan:'span7-end',
|
268
|
+
range:$R(0,200) });
|
269
|
+
assertInstanceOf(Control.Slider, slider);
|
270
|
+
|
271
|
+
slider.setValue(20, 0);
|
272
|
+
slider.setValue(100, 1);
|
273
|
+
slider.setValue(150, 2);
|
274
|
+
assertEqual("0px", $('span7-start').style.left);
|
275
|
+
assertEqual("19px", $('span7-start').style.width);
|
276
|
+
assertEqual("145px", $('span7-end').style.left);
|
277
|
+
assertEqual("48px", $('span7-end').style.width);
|
278
|
+
|
279
|
+
slider.dispose();
|
280
|
+
}},
|
281
|
+
|
282
|
+
testSingleHandleSpansStartEnd: function() { with(this) {
|
283
|
+
var slider = new Control.Slider('handle7-1', 'track7',
|
284
|
+
{ spans:['span7-1','span7-2'],
|
285
|
+
startSpan:'span7-start',
|
286
|
+
endSpan:'span7-end',
|
287
|
+
range:$R(0,200) });
|
288
|
+
assertInstanceOf(Control.Slider, slider);
|
289
|
+
|
290
|
+
slider.setValue(20, 0);
|
291
|
+
assertEqual("0px", $('span7-start').style.left);
|
292
|
+
assertEqual("19px", $('span7-start').style.width);
|
293
|
+
assertEqual("19px", $('span7-end').style.left);
|
294
|
+
assertEqual("174px", $('span7-end').style.width);
|
295
|
+
|
296
|
+
slider.dispose();
|
297
|
+
}},
|
298
|
+
|
299
|
+
testMultipleHandlesStyles: function() { with(this) {
|
300
|
+
var slider = new Control.Slider(['handle7-1','handle7-2','handle7-3'], 'track7',
|
301
|
+
{ spans:['span7-1','span7-2'],
|
302
|
+
startSpan:'span7-start',
|
303
|
+
endSpan:'span7-end',
|
304
|
+
range:$R(0,200) });
|
305
|
+
assertInstanceOf(Control.Slider, slider);
|
306
|
+
assert(Element.hasClassName('handle7-1','selected'));
|
307
|
+
assert(!Element.hasClassName('handle7-2','selected'));
|
308
|
+
assert(!Element.hasClassName('handle7-3','selected'));
|
309
|
+
|
310
|
+
slider.setValue(20, 0);
|
311
|
+
assert(Element.hasClassName('handle7-1','selected'));
|
312
|
+
assert(!Element.hasClassName('handle7-2','selected'));
|
313
|
+
assert(!Element.hasClassName('handle7-3','selected'));
|
314
|
+
|
315
|
+
slider.setValue(100, 1);
|
316
|
+
assert(!Element.hasClassName('handle7-1','selected'));
|
317
|
+
assert(Element.hasClassName('handle7-2','selected'));
|
318
|
+
assert(!Element.hasClassName('handle7-3','selected'));
|
319
|
+
|
320
|
+
slider.setValue(150, 2);
|
321
|
+
assert(!Element.hasClassName('handle7-1','selected'));
|
322
|
+
assert(!Element.hasClassName('handle7-2','selected'));
|
323
|
+
assert(Element.hasClassName('handle7-3','selected'));
|
324
|
+
|
325
|
+
slider.dispose();
|
326
|
+
}},
|
327
|
+
|
328
|
+
testMultipleHandlesSpansRestricted: function() { with(this) {
|
329
|
+
var slider = new Control.Slider(['handle5-1','handle5-2','handle5-3'], 'track5',
|
330
|
+
{restricted:true,spans:['span5-1','span5-2'],range:$R(0,300)});
|
331
|
+
assertInstanceOf(Control.Slider, slider);
|
332
|
+
|
333
|
+
slider.setValue(20, 0);
|
334
|
+
slider.setValue(100, 1);
|
335
|
+
slider.setValue(150, 2);
|
336
|
+
assertEqual(0, slider.values[0]);
|
337
|
+
assertEqual(0, slider.values[1]);
|
338
|
+
assertEqual(150, slider.values[2]);
|
339
|
+
|
340
|
+
slider.setValue(150, 2);
|
341
|
+
slider.setValue(100, 1);
|
342
|
+
slider.setValue(20, 0);
|
343
|
+
assertEqual(20, slider.values[0]);
|
344
|
+
assertEqual(100, slider.values[1]);
|
345
|
+
assertEqual(150, slider.values[2]);
|
346
|
+
assertEqual("20px", $('span5-1').style.left);
|
347
|
+
assertEqual("78px", $('span5-1').style.width);
|
348
|
+
assertEqual("98px", $('span5-2').style.left);
|
349
|
+
assertEqual("49px", $('span5-2').style.width);
|
350
|
+
|
351
|
+
slider.setValue(30, 0);
|
352
|
+
slider.setValue(110, 1);
|
353
|
+
slider.setValue(90, 2);
|
354
|
+
assertEqual(30, slider.values[0]);
|
355
|
+
assertEqual(110, slider.values[1]);
|
356
|
+
assertEqual(110, slider.values[2], '???');
|
357
|
+
|
358
|
+
assertEqual("29px", $('span5-1').style.left);
|
359
|
+
assertEqual("78px", $('span5-1').style.width);
|
360
|
+
assertEqual("107px", $('span5-2').style.left);
|
361
|
+
assertEqual("0px", $('span5-2').style.width);
|
362
|
+
|
363
|
+
slider.dispose();
|
364
|
+
}},
|
365
|
+
|
366
|
+
testMultipleHandlesSpansVertical: function() { with(this) {
|
367
|
+
var slider = new Control.Slider(['handle6-1','handle6-2','handle6-3'], 'track6', {axis:'vertical',spans:['span6-1','span6-2'],range:$R(0,100)});
|
368
|
+
assertInstanceOf(Control.Slider, slider);
|
369
|
+
|
370
|
+
slider.setValue(20, 0);
|
371
|
+
slider.setValue(80, 1);
|
372
|
+
slider.setValue(90, 2);
|
373
|
+
|
374
|
+
assertEqual("17px", $('span6-1').style.top);
|
375
|
+
assertEqual("52px", $('span6-1').style.height);
|
376
|
+
assertEqual("70px", $('span6-2').style.top);
|
377
|
+
assertEqual("9px", $('span6-2').style.height);
|
378
|
+
|
379
|
+
slider.setValue(30, 0);
|
380
|
+
slider.setValue(20, 1);
|
381
|
+
slider.setValue(95, 2);
|
382
|
+
|
383
|
+
assertEqual("17px", $('span6-1').style.top);
|
384
|
+
assertEqual("9px", $('span6-1').style.height);
|
385
|
+
assertEqual("26px", $('span6-2').style.top);
|
386
|
+
assertEqual("57px", $('span6-2').style.height);
|
387
|
+
}},
|
388
|
+
|
389
|
+
testRange: function() { with(this) {
|
390
|
+
var slider = new Control.Slider('handle1','track1');
|
391
|
+
assertEqual(0, slider.value);
|
392
|
+
slider.setValue(1);
|
393
|
+
assertEqual("185px", $('handle1').style.left);
|
394
|
+
slider.dispose();
|
395
|
+
|
396
|
+
var slider = new Control.Slider('handle1','track1',{range:$R(10,20)});
|
397
|
+
assertEqual(10, slider.value);
|
398
|
+
assertEqual("0px", $('handle1').style.left);
|
399
|
+
slider.setValue(15);
|
400
|
+
assertEqual("93px", $('handle1').style.left);
|
401
|
+
slider.setValue(20);
|
402
|
+
assertEqual("185px", $('handle1').style.left);
|
403
|
+
slider.dispose();
|
404
|
+
}},
|
405
|
+
|
406
|
+
// test for #3732
|
407
|
+
testRangeValues: function() { with(this) {
|
408
|
+
// test for non-zero starting range
|
409
|
+
var slider = new Control.Slider('handle1','track1',{
|
410
|
+
range:$R(1,3), values:[1,2,3]
|
411
|
+
});
|
412
|
+
assertEqual(1, slider.value);
|
413
|
+
assertEqual("0px", $('handle1').style.left);
|
414
|
+
slider.setValue(2);
|
415
|
+
assertEqual("93px", $('handle1').style.left);
|
416
|
+
slider.setValue(3);
|
417
|
+
assertEqual("185px", $('handle1').style.left);
|
418
|
+
slider.dispose();
|
419
|
+
|
420
|
+
// test zero-starting range
|
421
|
+
var slider = new Control.Slider('handle1','track1',{
|
422
|
+
range:$R(0,2), values:[0,1,2]
|
423
|
+
});
|
424
|
+
assertEqual(0, slider.value);
|
425
|
+
assertEqual("0px", $('handle1').style.left);
|
426
|
+
slider.setValue(1);
|
427
|
+
assertEqual("93px", $('handle1').style.left);
|
428
|
+
slider.setValue(2);
|
429
|
+
assertEqual("185px", $('handle1').style.left);
|
430
|
+
slider.dispose();
|
431
|
+
}}
|
432
|
+
|
433
|
+
}, "testlog");
|
434
|
+
// ]]>
|
435
|
+
</script>
|
436
|
+
</body>
|
437
|
+
</html>
|
@@ -0,0 +1,205 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<title>script.aculo.us Unit test file</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
<script src="assets/prototype.js" type="text/javascript"></script>
|
8
|
+
<script src="assets/scriptaculous.js" type="text/javascript"></script>
|
9
|
+
<script src="assets/unittest.js" type="text/javascript"></script>
|
10
|
+
<link rel="stylesheet" href="../test.css" type="text/css" />
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>script.aculo.us Unit test file</h1>
|
14
|
+
<p>
|
15
|
+
Test of sortable functions in dragdrop.js
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<!-- Log output -->
|
19
|
+
<div id="testlog"> </div>
|
20
|
+
|
21
|
+
|
22
|
+
<ul id="sortable1">
|
23
|
+
<li id="item_1" class="a">item 1</li>
|
24
|
+
<li id="item_2" class="c b">item 1<ul><li id="item_99">!!!</li></ul></li>
|
25
|
+
<li id="item_3" class="b">item 1</li>
|
26
|
+
<li id="item_xy" class="x y">item 1</li>
|
27
|
+
<!-- a comment -->
|
28
|
+
</ul>
|
29
|
+
|
30
|
+
<div id="sortable2">
|
31
|
+
<div id="item_4">item 4</div> <div id="item_5">item 5</div>
|
32
|
+
<img src="icon.png" alt="img"/>
|
33
|
+
<!-- a comment -->
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="sortable3">
|
37
|
+
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<!--
|
41
|
+
By default, _ is the only valid seperator
|
42
|
+
for the DOM ids. Complex element ids as in
|
43
|
+
the form of "some_element_id_1" should also
|
44
|
+
be parsed correctly (only the last part should
|
45
|
+
be serialized)
|
46
|
+
-->
|
47
|
+
<ul id="sortable_complex">
|
48
|
+
<li id="a_b_item_1" class="a">item 1</li>
|
49
|
+
<li id="ab_item_2" class="c b">item 1
|
50
|
+
<ul>
|
51
|
+
<li id="item_99">!!!</li>
|
52
|
+
</ul>
|
53
|
+
</li>
|
54
|
+
<li id="a-b-item_3z_33" class="b">item 1</li>
|
55
|
+
<li id="a-item-xy" class="x y">item 1</li>
|
56
|
+
<!-- a comment -->
|
57
|
+
</ul>
|
58
|
+
|
59
|
+
|
60
|
+
<ul id="sortable_specialcreate">
|
61
|
+
<li id="y1item">item 1</li>
|
62
|
+
<li id="y2item">item 1<ul><li id="yyyy9928282hjhd">!!!</li></ul></li>
|
63
|
+
</ul>
|
64
|
+
|
65
|
+
<ul id="sortable_specialformat">
|
66
|
+
<li id="x1item">item 1</li>
|
67
|
+
<li id="x2item">item 1<ul><li id="xxxxx88888item">!!!</li></ul></li>
|
68
|
+
</ul>
|
69
|
+
|
70
|
+
<!-- Tests follow -->
|
71
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
72
|
+
// <![CDATA[
|
73
|
+
|
74
|
+
new Test.Unit.Runner({
|
75
|
+
|
76
|
+
setup: function() { with(this) {
|
77
|
+
Sortable.create('sortable1',{only:['a','b']});
|
78
|
+
Sortable.create('sortable2',{tag:'div'});
|
79
|
+
Sortable.create('sortable3');
|
80
|
+
Sortable.create('sortable_specialcreate',{ format:/(\d+)/ });
|
81
|
+
Sortable.create('sortable_specialformat');
|
82
|
+
Sortable.create('sortable_complex');
|
83
|
+
}},
|
84
|
+
|
85
|
+
teardown: function() { with(this) {
|
86
|
+
Sortable.destroy('sortable1');
|
87
|
+
Sortable.destroy('sortable2');
|
88
|
+
Sortable.destroy('sortable3');
|
89
|
+
Sortable.destroy('sortable_specialformat');
|
90
|
+
Sortable.destroy('sortable_specialcreate');
|
91
|
+
Sortable.destroy('sortable_complex');
|
92
|
+
}},
|
93
|
+
|
94
|
+
testSortableSerializeSequenceBasics: function() { with(this) {
|
95
|
+
assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3', Sortable.serialize('sortable1'));
|
96
|
+
|
97
|
+
// test empty sortable
|
98
|
+
assertEqual('', Sortable.serialize('sortable3'));
|
99
|
+
assertEnumEqual([], Sortable.sequence('sortable3'));
|
100
|
+
|
101
|
+
Element.remove('item_4');
|
102
|
+
assertEqual('sortable2[]=5', Sortable.serialize('sortable2'));
|
103
|
+
assertEnumEqual(['5'], Sortable.sequence('sortable2'));
|
104
|
+
}},
|
105
|
+
|
106
|
+
testSortableSerializeFormat: function() { with(this) {
|
107
|
+
// should correctly serialize from option given to Sortable.create()
|
108
|
+
assertEqual('sortable_specialcreate[]=1&sortable_specialcreate[]=2',
|
109
|
+
Sortable.serialize('sortable_specialcreate'));
|
110
|
+
|
111
|
+
benchmark(function(){
|
112
|
+
Sortable.serialize('sortable_specialcreate')
|
113
|
+
},1,'Sortable.serialize');
|
114
|
+
|
115
|
+
// test special format given explicitly
|
116
|
+
assertEqual('sortable_specialformat[]=1&sortable_specialformat[]=2',
|
117
|
+
Sortable.serialize('sortable_specialformat', {format:/(\d+)/}));
|
118
|
+
|
119
|
+
// return full id
|
120
|
+
assertEqual('sortable_specialformat[]=x1item&sortable_specialformat[]=x2item',
|
121
|
+
Sortable.serialize('sortable_specialformat', {format:/(.*)/}));
|
122
|
+
|
123
|
+
// test default format given explicitly
|
124
|
+
assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3',
|
125
|
+
Sortable.serialize('sortable1',{format:/^[^_]*_(.*)$/}));
|
126
|
+
|
127
|
+
// Ensure default options.format handles longer, more complex list
|
128
|
+
// item IDs
|
129
|
+
assertEqual('sortable_complex[]=1&sortable_complex[]=2&sortable_complex[]=33&sortable_complex[]=',
|
130
|
+
Sortable.serialize('sortable_complex'));
|
131
|
+
}},
|
132
|
+
|
133
|
+
testSortableSerializeRule: function() { with(this) {
|
134
|
+
var ids = ['x','x-y','test_test','x_y_z','x_y-x_z'];
|
135
|
+
ids.each(function(id){
|
136
|
+
assertEqual('1',
|
137
|
+
(id+'_1').match(Sortable.SERIALIZE_RULE)[1]);
|
138
|
+
});
|
139
|
+
|
140
|
+
assertNull('x'.match(Sortable.SERIALIZE_RULE));
|
141
|
+
}},
|
142
|
+
|
143
|
+
testSortableSerializeName: function() { with(this) {
|
144
|
+
assertEqual('dumdidu[]=1&dumdidu[]=2',
|
145
|
+
Sortable.serialize('sortable_specialcreate',{name:'dumdidu'}));
|
146
|
+
}},
|
147
|
+
|
148
|
+
testSortableSequenceFormat: function() { with(this) {
|
149
|
+
// shauld correctly serialize from option given to Sortable.create()
|
150
|
+
assertEnumEqual(['1','2'],
|
151
|
+
Sortable.sequence('sortable_specialcreate'));
|
152
|
+
|
153
|
+
// test special format given explicitly
|
154
|
+
assertEnumEqual(['1','2'],
|
155
|
+
Sortable.sequence('sortable_specialformat', {format:/(\d+)/}));
|
156
|
+
|
157
|
+
// return full id
|
158
|
+
assertEnumEqual(['x1item','x2item'],
|
159
|
+
Sortable.sequence('sortable_specialformat', {format:/(.*)/}));
|
160
|
+
|
161
|
+
// test default format given explicitly
|
162
|
+
assertEnumEqual(['1','2','3'],
|
163
|
+
Sortable.sequence('sortable1',{format:/^[^_]*_(.*)$/}));
|
164
|
+
}},
|
165
|
+
|
166
|
+
testSortableFindElements: function() { with(this) {
|
167
|
+
assertEqual(3, Sortable.findElements($('sortable1'),{tag:'li',only:['a','b']}).length);
|
168
|
+
benchmark(function(){
|
169
|
+
Sortable.findElements($('sortable1'),{tag:'li',only:['a','b']})
|
170
|
+
},1,'Sortable.findElements/1');
|
171
|
+
|
172
|
+
assertEqual(1, Sortable.findElements($('sortable1'),{tag:'li',only:['x']}).length);
|
173
|
+
assertEqual(1, Sortable.findElements($('sortable1'),{tag:'li',only:'a'}).length);
|
174
|
+
assertEqual(2, Sortable.findElements($('sortable1'),{tag:'li',only:'b'}).length);
|
175
|
+
assertEqual(4, Sortable.findElements($('sortable1'),{tag:'li',only:['a','b','x']}).length);
|
176
|
+
}},
|
177
|
+
|
178
|
+
testSortableSetSequence: function() { with(this) {
|
179
|
+
// make sure assigning current sequence is a no-op
|
180
|
+
var o = Sortable.sequence('sortable1');
|
181
|
+
Sortable.setSequence('sortable1', ['1','2','3']);
|
182
|
+
assertEnumEqual(o, Sortable.sequence('sortable1'));
|
183
|
+
|
184
|
+
// check new sequence
|
185
|
+
Sortable.setSequence('sortable1', ['3','2','1']);
|
186
|
+
assertEnumEqual(['3','2','1'], Sortable.sequence('sortable1'));
|
187
|
+
|
188
|
+
// non-default format
|
189
|
+
Sortable.setSequence('sortable_specialformat', ['2','1'], { format:/(\d+)/ });
|
190
|
+
assertEnumEqual(['2','1'], Sortable.sequence('sortable_specialformat'));
|
191
|
+
|
192
|
+
// invalid sequence ids should be ignored
|
193
|
+
Sortable.setSequence('sortable1', ['x', '1', 'y', '2', '3', 'z']);
|
194
|
+
assertEnumEqual(['1', '2', '3'], Sortable.sequence('sortable1'));
|
195
|
+
|
196
|
+
// elements omitted in new sequence should be cropped
|
197
|
+
Sortable.setSequence('sortable1', ['1', '3']);
|
198
|
+
assertEnumEqual(['1', '3'], Sortable.sequence('sortable1'));
|
199
|
+
}}
|
200
|
+
|
201
|
+
}, "testlog");
|
202
|
+
// ]]>
|
203
|
+
</script>
|
204
|
+
</body>
|
205
|
+
</html>
|