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,382 @@
|
|
1
|
+
// sweet sweet additional assertions
|
2
|
+
Object.extend(Test.Unit.Testcase.prototype, {
|
3
|
+
assertEnabled: function() {
|
4
|
+
for (var i = 0, element; element = arguments[i]; i++) {
|
5
|
+
this.assert(!$(element).disabled, Test.Unit.inspect(element) + ' was disabled');
|
6
|
+
}
|
7
|
+
},
|
8
|
+
assertDisabled: function() {
|
9
|
+
for (var i = 0, element; element = arguments[i]; i++) {
|
10
|
+
this.assert($(element).disabled, Test.Unit.inspect(element) + ' was enabled');
|
11
|
+
}
|
12
|
+
}
|
13
|
+
});
|
14
|
+
|
15
|
+
new Test.Unit.Runner({
|
16
|
+
|
17
|
+
// Make sure to set defaults in the test forms, as some browsers override this
|
18
|
+
// with previously entered values on page reload
|
19
|
+
setup: function(){
|
20
|
+
$$('form').each(function(f){ f.reset() });
|
21
|
+
// hidden value does not reset (for some reason)
|
22
|
+
$('bigform')['tf_hidden'].value = '';
|
23
|
+
},
|
24
|
+
|
25
|
+
testDollarF: function(){
|
26
|
+
this.assertEqual("4", $F("input_enabled"));
|
27
|
+
},
|
28
|
+
|
29
|
+
testFormReset: function() {
|
30
|
+
this.assert(!Object.isUndefined(Form.reset('form').reset));
|
31
|
+
},
|
32
|
+
|
33
|
+
testFormElementEventObserver: function(){
|
34
|
+
var callbackCounter = 0;
|
35
|
+
var observer = new Form.Element.EventObserver('input_enabled', function(){
|
36
|
+
callbackCounter++;
|
37
|
+
});
|
38
|
+
|
39
|
+
this.assertEqual(0, callbackCounter);
|
40
|
+
$('input_enabled').value = 'boo!';
|
41
|
+
observer.onElementEvent(); // can't test the event directly, simulating
|
42
|
+
this.assertEqual(1, callbackCounter);
|
43
|
+
},
|
44
|
+
|
45
|
+
testFormElementObserver: function(){
|
46
|
+
var timedCounter = 0;
|
47
|
+
// First part: regular field
|
48
|
+
var observer = new Form.Element.Observer('input_enabled', 0.5, function() {
|
49
|
+
++timedCounter;
|
50
|
+
});
|
51
|
+
|
52
|
+
// Test it's unchanged yet
|
53
|
+
this.assertEqual(0, timedCounter);
|
54
|
+
// Test it doesn't change on first check
|
55
|
+
this.wait(550, function() {
|
56
|
+
this.assertEqual(0, timedCounter);
|
57
|
+
// Change, test it doesn't immediately change
|
58
|
+
$('input_enabled').value = 'yowza!';
|
59
|
+
this.assertEqual(0, timedCounter);
|
60
|
+
// Test it changes on next check, but not again on the next
|
61
|
+
this.wait(550, function() {
|
62
|
+
this.assertEqual(1, timedCounter);
|
63
|
+
this.wait(550, function() {
|
64
|
+
this.assertEqual(1, timedCounter);
|
65
|
+
observer.stop();
|
66
|
+
});
|
67
|
+
});
|
68
|
+
});
|
69
|
+
|
70
|
+
// Second part: multiple-select
|
71
|
+
[1, 2, 3].each(function(index) {
|
72
|
+
$('multiSel1_opt' + index).selected = (1 == index);
|
73
|
+
});
|
74
|
+
timedCounter = 0;
|
75
|
+
observer = new Form.Element.Observer('multiSel1', 0.5, function() {
|
76
|
+
++timedCounter;
|
77
|
+
});
|
78
|
+
|
79
|
+
// Test it's unchanged yet
|
80
|
+
this.assertEqual(0, timedCounter);
|
81
|
+
// Test it doesn't change on first check
|
82
|
+
this.wait(550, function() {
|
83
|
+
this.assertEqual(0, timedCounter);
|
84
|
+
// Change, test it doesn't immediately change
|
85
|
+
// NOTE: it is important that the 3rd be re-selected, for the
|
86
|
+
// serialize form to obtain the expected value :-)
|
87
|
+
$('multiSel1_opt3').selected = true;
|
88
|
+
this.assertEqual(0, timedCounter);
|
89
|
+
// Test it changes on next check, but not again on the next
|
90
|
+
this.wait(550, function() {
|
91
|
+
this.assertEqual(1, timedCounter);
|
92
|
+
this.wait(550, function() {
|
93
|
+
this.assertEqual(1, timedCounter);
|
94
|
+
observer.stop();
|
95
|
+
});
|
96
|
+
});
|
97
|
+
});
|
98
|
+
},
|
99
|
+
|
100
|
+
testFormObserver: function(){
|
101
|
+
var timedCounter = 0;
|
102
|
+
// should work the same way was Form.Element.Observer
|
103
|
+
var observer = new Form.Observer('form', 0.5, function(form, value) {
|
104
|
+
++timedCounter;
|
105
|
+
});
|
106
|
+
|
107
|
+
// Test it's unchanged yet
|
108
|
+
this.assertEqual(0, timedCounter);
|
109
|
+
// Test it doesn't change on first check
|
110
|
+
this.wait(550, function() {
|
111
|
+
this.assertEqual(0, timedCounter);
|
112
|
+
// Change, test it doesn't immediately change
|
113
|
+
$('input_enabled').value = 'yowza!';
|
114
|
+
this.assertEqual(0, timedCounter);
|
115
|
+
// Test it changes on next check, but not again on the next
|
116
|
+
this.wait(550, function() {
|
117
|
+
this.assertEqual(1, timedCounter);
|
118
|
+
this.wait(550, function() {
|
119
|
+
this.assertEqual(1, timedCounter);
|
120
|
+
observer.stop();
|
121
|
+
});
|
122
|
+
});
|
123
|
+
});
|
124
|
+
},
|
125
|
+
|
126
|
+
testFormEnabling: function(){
|
127
|
+
var form = $('bigform')
|
128
|
+
var input1 = $('dummy_disabled');
|
129
|
+
var input2 = $('focus_text');
|
130
|
+
|
131
|
+
this.assertDisabled(input1);
|
132
|
+
this.assertEnabled(input2);
|
133
|
+
|
134
|
+
form.disable();
|
135
|
+
this.assertDisabled(input1, input2);
|
136
|
+
form.enable();
|
137
|
+
this.assertEnabled(input1, input2);
|
138
|
+
input1.disable();
|
139
|
+
this.assertDisabled(input1);
|
140
|
+
|
141
|
+
// non-form elements:
|
142
|
+
var fieldset = $('selects_fieldset');
|
143
|
+
var fields = fieldset.immediateDescendants();
|
144
|
+
fields.each(function(select) { this.assertEnabled(select) }, this);
|
145
|
+
|
146
|
+
Form.disable(fieldset)
|
147
|
+
fields.each(function(select) { this.assertDisabled(select) }, this);
|
148
|
+
|
149
|
+
Form.enable(fieldset)
|
150
|
+
fields.each(function(select) { this.assertEnabled(select) }, this);
|
151
|
+
},
|
152
|
+
|
153
|
+
testFormElementEnabling: function(){
|
154
|
+
var field = $('input_disabled');
|
155
|
+
field.enable();
|
156
|
+
this.assertEnabled(field);
|
157
|
+
field.disable();
|
158
|
+
this.assertDisabled(field);
|
159
|
+
|
160
|
+
var field = $('input_enabled');
|
161
|
+
this.assertEnabled(field);
|
162
|
+
field.disable();
|
163
|
+
this.assertDisabled(field);
|
164
|
+
field.enable();
|
165
|
+
this.assertEnabled(field);
|
166
|
+
},
|
167
|
+
|
168
|
+
// due to the lack of a DOM hasFocus() API method,
|
169
|
+
// we're simulating things here a little bit
|
170
|
+
testFormActivating: function(){
|
171
|
+
// Firefox, IE, and Safari 2+
|
172
|
+
function getSelection(element){
|
173
|
+
try {
|
174
|
+
if (typeof element.selectionStart == 'number') {
|
175
|
+
return element.value.substring(element.selectionStart, element.selectionEnd);
|
176
|
+
} else if (document.selection && document.selection.createRange) {
|
177
|
+
return document.selection.createRange().text;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
catch(e){ return null }
|
181
|
+
}
|
182
|
+
|
183
|
+
// Form.focusFirstElement shouldn't focus disabled elements
|
184
|
+
var element = Form.findFirstElement('bigform');
|
185
|
+
this.assertEqual('submit', element.id);
|
186
|
+
|
187
|
+
// Test IE doesn't select text on buttons
|
188
|
+
Form.focusFirstElement('bigform');
|
189
|
+
if(document.selection) this.assertEqual('', getSelection(element));
|
190
|
+
|
191
|
+
// Form.Element.activate shouldn't select text on buttons
|
192
|
+
element = $('focus_text');
|
193
|
+
this.assertEqual('', getSelection(element));
|
194
|
+
|
195
|
+
// Form.Element.activate should select text on text input elements
|
196
|
+
element.activate();
|
197
|
+
this.assertEqual('Hello', getSelection(element));
|
198
|
+
|
199
|
+
// Form.Element.activate shouldn't raise an exception when the form or field is hidden
|
200
|
+
this.assertNothingRaised(function() {
|
201
|
+
$('form_focus_hidden').focusFirstElement();
|
202
|
+
});
|
203
|
+
},
|
204
|
+
|
205
|
+
testFormGetElements: function() {
|
206
|
+
var elements = Form.getElements('various'),
|
207
|
+
names = $w('tf_selectOne tf_textarea tf_checkbox tf_selectMany tf_text tf_radio tf_hidden tf_password');
|
208
|
+
this.assertEnumEqual(names, elements.pluck('name'))
|
209
|
+
},
|
210
|
+
|
211
|
+
testFormGetInputs: function() {
|
212
|
+
var form = $('form');
|
213
|
+
[form.getInputs(), Form.getInputs(form)].each(function(inputs){
|
214
|
+
this.assertEqual(inputs.length, 5);
|
215
|
+
this.assert(inputs instanceof Array);
|
216
|
+
this.assert(inputs.all(function(input) { return (input.tagName == "INPUT"); }));
|
217
|
+
}, this);
|
218
|
+
},
|
219
|
+
|
220
|
+
testFormFindFirstElement: function() {
|
221
|
+
this.assertEqual($('ffe_checkbox'), $('ffe').findFirstElement());
|
222
|
+
this.assertEqual($('ffe_ti_submit'), $('ffe_ti').findFirstElement());
|
223
|
+
this.assertEqual($('ffe_ti2_checkbox'), $('ffe_ti2').findFirstElement());
|
224
|
+
},
|
225
|
+
|
226
|
+
testFormSerialize: function() {
|
227
|
+
// form is initially empty
|
228
|
+
var form = $('bigform');
|
229
|
+
var expected = { tf_selectOne:'', tf_textarea:'', tf_text:'', tf_hidden:'', tf_password:'' };
|
230
|
+
this.assertHashEqual(expected, Form.serialize('various', true));
|
231
|
+
|
232
|
+
// set up some stuff
|
233
|
+
form['tf_selectOne'].selectedIndex = 1;
|
234
|
+
form['tf_textarea'].value = "boo hoo!";
|
235
|
+
form['tf_text'].value = "123öäü";
|
236
|
+
form['tf_hidden'].value = "moo%hoo&test";
|
237
|
+
form['tf_password'].value = 'sekrit code';
|
238
|
+
form['tf_checkbox'].checked = true;
|
239
|
+
form['tf_radio'].checked = true;
|
240
|
+
var expected = { tf_selectOne:1, tf_textarea:"boo hoo!", tf_text:"123öäü",
|
241
|
+
tf_hidden:"moo%hoo&test", tf_password:'sekrit code', tf_checkbox:'on', tf_radio:'on' }
|
242
|
+
|
243
|
+
// return params
|
244
|
+
this.assertHashEqual(expected, Form.serialize('various', true));
|
245
|
+
// return string
|
246
|
+
this.assertEnumEqual(Object.toQueryString(expected).split('&').sort(),
|
247
|
+
Form.serialize('various').split('&').sort());
|
248
|
+
this.assertEqual('string', typeof $('form').serialize({ hash:false }));
|
249
|
+
|
250
|
+
// Checks that disabled element is not included in serialized form.
|
251
|
+
$('input_enabled').enable();
|
252
|
+
this.assertHashEqual({ val1:4, action:'blah', first_submit:'Commit it!' },
|
253
|
+
$('form').serialize(true));
|
254
|
+
|
255
|
+
// should not eat empty values for duplicate names
|
256
|
+
$('checkbox_hack').checked = false;
|
257
|
+
var data = Form.serialize('value_checks', true);
|
258
|
+
this.assertEnumEqual(['', 'siamese'], data['twin']);
|
259
|
+
this.assertEqual('0', data['checky']);
|
260
|
+
|
261
|
+
$('checkbox_hack').checked = true;
|
262
|
+
this.assertEnumEqual($w('1 0'), Form.serialize('value_checks', true)['checky']);
|
263
|
+
|
264
|
+
// all kinds of SELECT controls
|
265
|
+
var params = Form.serialize('selects_fieldset', true);
|
266
|
+
var expected = { 'nvm[]':['One', 'Three'], evu:'', 'evm[]':['', 'Three'] };
|
267
|
+
this.assertHashEqual(expected, params);
|
268
|
+
params = Form.serialize('selects_wrapper', true);
|
269
|
+
this.assertHashEqual(Object.extend(expected, { vu:1, 'vm[]':[1, 3], nvu:'One' }), params);
|
270
|
+
|
271
|
+
// explicit submit button
|
272
|
+
this.assertHashEqual({ val1:4, action:'blah', second_submit:'Delete it!' },
|
273
|
+
$('form').serialize({ submit: 'second_submit' }));
|
274
|
+
this.assertHashEqual({ val1:4, action:'blah' },
|
275
|
+
$('form').serialize({ submit: false }));
|
276
|
+
this.assertHashEqual({ val1:4, action:'blah' },
|
277
|
+
$('form').serialize({ submit: 'inexistent' }));
|
278
|
+
|
279
|
+
// file input should not be serialized
|
280
|
+
this.assertEqual('', $('form_with_file_input').serialize());
|
281
|
+
},
|
282
|
+
|
283
|
+
testFormMethodsOnExtendedElements: function() {
|
284
|
+
var form = $('form');
|
285
|
+
this.assertEqual(Form.serialize('form'), form.serialize());
|
286
|
+
this.assertEqual(Form.Element.serialize('input_enabled'), $('input_enabled').serialize());
|
287
|
+
this.assertNotEqual(form.serialize, $('input_enabled').serialize);
|
288
|
+
|
289
|
+
Element.addMethods('INPUT', { anInputMethod: function(input) { return 'input' } });
|
290
|
+
Element.addMethods('SELECT', { aSelectMethod: function(select) { return 'select' } });
|
291
|
+
|
292
|
+
form = $('bigform');
|
293
|
+
var input = form['tf_text'], select = form['tf_selectOne'];
|
294
|
+
input._extendedByPrototype = select._extendedByPrototype = void 0;
|
295
|
+
|
296
|
+
this.assert($(input).anInputMethod);
|
297
|
+
this.assert(!input.aSelectMethod);
|
298
|
+
this.assertEqual('input', input.anInputMethod());
|
299
|
+
|
300
|
+
this.assert($(select).aSelectMethod);
|
301
|
+
this.assert(!select.anInputMethod);
|
302
|
+
this.assertEqual('select', select.aSelectMethod());
|
303
|
+
},
|
304
|
+
|
305
|
+
testFormRequest: function() {
|
306
|
+
var request = $("form").request();
|
307
|
+
this.assert($("form").hasAttribute("method"));
|
308
|
+
this.assert(request.url.include("fixtures/empty.js?val1=4"));
|
309
|
+
this.assertEqual("get", request.method);
|
310
|
+
|
311
|
+
request = $("form").request({ method: "put", parameters: {val2: "hello"} });
|
312
|
+
this.assert(request.url.endsWith("fixtures/empty.js"));
|
313
|
+
this.assertEqual(4, request.options.parameters['val1']);
|
314
|
+
this.assertEqual('hello', request.options.parameters['val2']);
|
315
|
+
this.assertEqual("post", request.method);
|
316
|
+
this.assertEqual("put", request.parameters['_method']);
|
317
|
+
|
318
|
+
// with empty action attribute
|
319
|
+
request = $("ffe").request({ method: 'post' });
|
320
|
+
this.assert(request.url.include("/form_test.html"),
|
321
|
+
'wrong default action for form element with empty action attribute');
|
322
|
+
},
|
323
|
+
|
324
|
+
testFormElementMethodsChaining: function(){
|
325
|
+
var methods = $w('clear activate disable enable'),
|
326
|
+
formElements = $('form').getElements();
|
327
|
+
methods.each(function(method){
|
328
|
+
formElements.each(function(element){
|
329
|
+
var returned = element[method]();
|
330
|
+
this.assertIdentical(element, returned);
|
331
|
+
}, this);
|
332
|
+
}, this);
|
333
|
+
},
|
334
|
+
|
335
|
+
testSetValue: function(){
|
336
|
+
// text input
|
337
|
+
var input = $('input_enabled'), oldValue = input.getValue();
|
338
|
+
this.assertEqual(input, input.setValue('foo'), 'setValue chaining is broken');
|
339
|
+
this.assertEqual('foo', input.getValue(), 'value improperly set');
|
340
|
+
input.setValue(oldValue);
|
341
|
+
this.assertEqual(oldValue, input.getValue(), 'value improperly restored to original');
|
342
|
+
|
343
|
+
// checkbox
|
344
|
+
input = $('checkbox_hack');
|
345
|
+
input.setValue(false);
|
346
|
+
this.assertEqual(null, input.getValue(), 'checkbox should be unchecked');
|
347
|
+
input.setValue(true);
|
348
|
+
this.assertEqual("1", input.getValue(), 'checkbox should be checked');
|
349
|
+
// selectbox
|
350
|
+
input = $('bigform')['vu'];
|
351
|
+
input.setValue('3');
|
352
|
+
this.assertEqual('3', input.getValue(), 'single select option improperly set');
|
353
|
+
input.setValue('1');
|
354
|
+
this.assertEqual('1', input.getValue());
|
355
|
+
// multiple select
|
356
|
+
input = $('bigform')['vm[]'];
|
357
|
+
input.setValue(['2', '3']);
|
358
|
+
this.assertEnumEqual(['2', '3'], input.getValue(),
|
359
|
+
'multiple select options improperly set');
|
360
|
+
input.setValue(['1', '3']);
|
361
|
+
this.assertEnumEqual(['1', '3'], input.getValue());
|
362
|
+
},
|
363
|
+
|
364
|
+
testSerializeFormTroublesomeNames: function() {
|
365
|
+
var el = new Element('form', {
|
366
|
+
action: '/'
|
367
|
+
});
|
368
|
+
var input = new Element('input', {
|
369
|
+
type: 'text',
|
370
|
+
name: 'length',
|
371
|
+
value: 'foo'
|
372
|
+
});
|
373
|
+
var input2 = new Element('input', {
|
374
|
+
type: 'text',
|
375
|
+
name: 'bar',
|
376
|
+
value: 'baz'
|
377
|
+
});
|
378
|
+
el.appendChild(input);
|
379
|
+
el.appendChild(input2);
|
380
|
+
this.assertHashEqual({ length: 'foo', bar: 'baz' }, el.serialize(true));
|
381
|
+
}
|
382
|
+
});
|
@@ -0,0 +1,133 @@
|
|
1
|
+
new Test.Unit.Runner({
|
2
|
+
testFunctionArgumentNames: function() {
|
3
|
+
this.assertEnumEqual([], (function() {}).argumentNames());
|
4
|
+
this.assertEnumEqual(["one"], (function(one) {}).argumentNames());
|
5
|
+
this.assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
|
6
|
+
this.assertEnumEqual(["one", "two", "three"], (function( one , two
|
7
|
+
, three ) {}).argumentNames());
|
8
|
+
this.assertEqual("$super", (function($super) {}).argumentNames().first());
|
9
|
+
|
10
|
+
function named1() {};
|
11
|
+
this.assertEnumEqual([], named1.argumentNames());
|
12
|
+
function named2(one) {};
|
13
|
+
this.assertEnumEqual(["one"], named2.argumentNames());
|
14
|
+
function named3(one, two, three) {};
|
15
|
+
this.assertEnumEqual(["one", "two", "three"], named3.argumentNames());
|
16
|
+
function named4(one,
|
17
|
+
two,
|
18
|
+
|
19
|
+
three) {}
|
20
|
+
this.assertEnumEqual($w('one two three'), named4.argumentNames());
|
21
|
+
function named5(/*foo*/ foo, /* bar */ bar, /*****/ baz) {}
|
22
|
+
this.assertEnumEqual($w("foo bar baz"), named5.argumentNames());
|
23
|
+
function named6(
|
24
|
+
/*foo*/ foo,
|
25
|
+
/**/bar,
|
26
|
+
/* baz */ /* baz */ baz,
|
27
|
+
// Skip a line just to screw with the regex...
|
28
|
+
/* thud */ thud) {}
|
29
|
+
this.assertEnumEqual($w("foo bar baz thud"), named6.argumentNames());
|
30
|
+
},
|
31
|
+
|
32
|
+
testFunctionBind: function() {
|
33
|
+
function methodWithoutArguments() { return this.hi };
|
34
|
+
function methodWithArguments() { return this.hi + ',' + $A(arguments).join(',') };
|
35
|
+
var func = Prototype.emptyFunction;
|
36
|
+
|
37
|
+
this.assertIdentical(func, func.bind());
|
38
|
+
this.assertIdentical(func, func.bind(undefined));
|
39
|
+
this.assertNotIdentical(func, func.bind(null));
|
40
|
+
|
41
|
+
this.assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })());
|
42
|
+
this.assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2'));
|
43
|
+
this.assertEqual('withBindArgs,arg1,arg2',
|
44
|
+
methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')());
|
45
|
+
this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
|
46
|
+
methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4'));
|
47
|
+
},
|
48
|
+
|
49
|
+
testFunctionCurry: function() {
|
50
|
+
var split = function(delimiter, string) { return string.split(delimiter); };
|
51
|
+
var splitOnColons = split.curry(":");
|
52
|
+
this.assertNotIdentical(split, splitOnColons);
|
53
|
+
this.assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5"));
|
54
|
+
this.assertIdentical(split, split.curry());
|
55
|
+
},
|
56
|
+
|
57
|
+
testFunctionDelay: function() {
|
58
|
+
window.delayed = undefined;
|
59
|
+
var delayedFunction = function() { window.delayed = true; };
|
60
|
+
var delayedFunctionWithArgs = function() { window.delayedWithArgs = $A(arguments).join(' '); };
|
61
|
+
delayedFunction.delay(0.8);
|
62
|
+
delayedFunctionWithArgs.delay(0.8, 'hello', 'world');
|
63
|
+
this.assertUndefined(window.delayed);
|
64
|
+
this.wait(1000, function() {
|
65
|
+
this.assert(window.delayed);
|
66
|
+
this.assertEqual('hello world', window.delayedWithArgs);
|
67
|
+
});
|
68
|
+
},
|
69
|
+
|
70
|
+
testFunctionWrap: function() {
|
71
|
+
function sayHello(){
|
72
|
+
return 'hello world';
|
73
|
+
};
|
74
|
+
|
75
|
+
this.assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) {
|
76
|
+
return proceed().toUpperCase();
|
77
|
+
})());
|
78
|
+
|
79
|
+
var temp = String.prototype.capitalize;
|
80
|
+
String.prototype.capitalize = String.prototype.capitalize.wrap(function(proceed, eachWord) {
|
81
|
+
if(eachWord && this.include(' ')) return this.split(' ').map(function(str){
|
82
|
+
return str.capitalize();
|
83
|
+
}).join(' ');
|
84
|
+
return proceed();
|
85
|
+
});
|
86
|
+
this.assertEqual('Hello world', 'hello world'.capitalize());
|
87
|
+
this.assertEqual('Hello World', 'hello world'.capitalize(true));
|
88
|
+
this.assertEqual('Hello', 'hello'.capitalize());
|
89
|
+
String.prototype.capitalize = temp;
|
90
|
+
},
|
91
|
+
|
92
|
+
testFunctionDefer: function() {
|
93
|
+
window.deferred = undefined;
|
94
|
+
var deferredFunction = function() { window.deferred = true; };
|
95
|
+
deferredFunction.defer();
|
96
|
+
this.assertUndefined(window.deferred);
|
97
|
+
this.wait(50, function() {
|
98
|
+
this.assert(window.deferred);
|
99
|
+
|
100
|
+
window.deferredValue = 0;
|
101
|
+
var deferredFunction2 = function(arg) { window.deferredValue = arg; };
|
102
|
+
deferredFunction2.defer('test');
|
103
|
+
this.wait(50, function() {
|
104
|
+
this.assertEqual('test', window.deferredValue);
|
105
|
+
});
|
106
|
+
});
|
107
|
+
},
|
108
|
+
|
109
|
+
testFunctionMethodize: function() {
|
110
|
+
var Foo = { bar: function(baz) { return baz } };
|
111
|
+
var baz = { quux: Foo.bar.methodize() };
|
112
|
+
|
113
|
+
this.assertEqual(Foo.bar.methodize(), baz.quux);
|
114
|
+
this.assertEqual(baz, Foo.bar(baz));
|
115
|
+
this.assertEqual(baz, baz.quux());
|
116
|
+
},
|
117
|
+
|
118
|
+
testBindAsEventListener: function() {
|
119
|
+
for( var i = 0; i < 10; ++i ){
|
120
|
+
var div = document.createElement('div');
|
121
|
+
div.setAttribute('id','test-'+i);
|
122
|
+
document.body.appendChild(div);
|
123
|
+
var tobj = new TestObj();
|
124
|
+
var eventTest = { test: true };
|
125
|
+
var call = tobj.assertingEventHandler.bindAsEventListener(tobj,
|
126
|
+
this.assertEqual.bind(this, eventTest),
|
127
|
+
this.assertEqual.bind(this, arg1),
|
128
|
+
this.assertEqual.bind(this, arg2),
|
129
|
+
this.assertEqual.bind(this, arg3), arg1, arg2, arg3 );
|
130
|
+
call(eventTest);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
});
|