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,895 @@
|
|
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 <code>Ajax.InPlaceEditor</code> and <code>Ajax.InPlaceCollectionEditor</code> in controls.js
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<!-- Log output -->
|
19
|
+
<div id="testlog"> </div>
|
20
|
+
|
21
|
+
<h1 id="tobeedited">To be edited</h1>
|
22
|
+
<a id="tobeeditedEditControl" href="#">edit</a>
|
23
|
+
|
24
|
+
<p id="newtbe">New to be edited</p>
|
25
|
+
<p id="newtbe_external">External control for it</p>
|
26
|
+
|
27
|
+
<p id="contains_ampersand">Me & Myself</p>
|
28
|
+
|
29
|
+
<div id="tobeeditedMultiLine">First line<br/>
|
30
|
+
Second line<br/>
|
31
|
+
Third line</div>
|
32
|
+
|
33
|
+
<!-- Tests follow -->
|
34
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
35
|
+
// <![CDATA[
|
36
|
+
|
37
|
+
var IPCE_COLLECTION = [
|
38
|
+
['tbe', 'To be edited'],
|
39
|
+
['ntbe', 'New to be edited'],
|
40
|
+
['ntbe2', 'New to be edited 2'],
|
41
|
+
['ntbe3', 'New to be edited 3']
|
42
|
+
];
|
43
|
+
|
44
|
+
new Test.Unit.Runner({
|
45
|
+
|
46
|
+
setup: function() { with(this) {
|
47
|
+
inPlaceEditor = new Ajax.InPlaceEditor($('tobeedited'), '_ajax_inplaceeditor_result.html', {
|
48
|
+
externalControl: $('tobeeditedEditControl'),
|
49
|
+
ajaxOptions: {method: 'get'} //override so we can use a static for the result
|
50
|
+
});
|
51
|
+
inPlaceEditorMultiLine = new Ajax.InPlaceEditor($('tobeeditedMultiLine'), '_ajax_inplaceeditor_result.html', {
|
52
|
+
ajaxOptions: {method: 'get'} //override so we can use a static for the result
|
53
|
+
});
|
54
|
+
}},
|
55
|
+
|
56
|
+
teardown: function() { with(this) {
|
57
|
+
inPlaceEditor.dispose();
|
58
|
+
inPlaceEditorMultiLine.dispose();
|
59
|
+
}},
|
60
|
+
|
61
|
+
// Original-version tests, still pass thx to backward compatibility
|
62
|
+
|
63
|
+
// Integration test, tests the entire cycle
|
64
|
+
testInPlaceEditor: function() { with(this) {
|
65
|
+
Event.simulateMouse('tobeedited','click');
|
66
|
+
assertHidden($('tobeedited'));
|
67
|
+
assertNotNull(document.forms[0]);
|
68
|
+
assertEqual("cancel", document.forms[0].lastChild.innerHTML);
|
69
|
+
assertVisible(document.forms[0]);
|
70
|
+
|
71
|
+
Event.simulateMouse(document.forms[0].lastChild,'click');
|
72
|
+
assertNull(document.forms[0]);
|
73
|
+
assertVisible($('tobeedited'));
|
74
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
75
|
+
Event.simulateMouse('tobeedited','mouseover');
|
76
|
+
Event.simulateMouse('tobeedited','click');
|
77
|
+
|
78
|
+
assertEqual("INPUT", document.forms[0].firstChild.tagName);
|
79
|
+
assertEqual("To be edited", document.forms[0].firstChild.value);
|
80
|
+
assertEqual("INPUT", document.forms[0].childNodes[1].tagName);
|
81
|
+
assertEqual("submit", document.forms[0].childNodes[1].type);
|
82
|
+
assertEqual("To be edited", document.forms[0].firstChild.value);
|
83
|
+
assert(Element.hasClassName(document.forms[0], 'inplaceeditor-form'),
|
84
|
+
"form doesn't have proper class: " + document.forms[0].className);
|
85
|
+
|
86
|
+
Event.simulateMouse(document.forms[0].childNodes[1],'click');
|
87
|
+
|
88
|
+
assertVisible($('tobeedited'));
|
89
|
+
assertEqual("Saving...", $('tobeedited').innerHTML);
|
90
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
91
|
+
assert(Element.hasClassName($('tobeedited'), 'inplaceeditor-saving'),
|
92
|
+
"doesn't have saving class");
|
93
|
+
|
94
|
+
wait(1000, function() {
|
95
|
+
assertEqual("Server received: To be edited", $('tobeedited').innerHTML);
|
96
|
+
assertNull(document.forms[0]);
|
97
|
+
assertVisible($('tobeedited'));
|
98
|
+
assert(!Element.hasClassName($('tobeedited'), 'inplaceeditor-saving'));
|
99
|
+
});
|
100
|
+
}},
|
101
|
+
|
102
|
+
testHovering: function() { with(this) {
|
103
|
+
Event.simulateMouse('tobeedited','mouseover');
|
104
|
+
assertEqual("rgb(255, 255, 153)", Element.getStyle('tobeedited','background-color'));
|
105
|
+
|
106
|
+
Event.simulateMouse('tobeedited','mouseout');
|
107
|
+
wait(1100, function() {
|
108
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'),
|
109
|
+
"should be transparent after mouse leaves element");
|
110
|
+
|
111
|
+
Event.simulateMouse('tobeedited','click');
|
112
|
+
})
|
113
|
+
}},
|
114
|
+
|
115
|
+
testLoadsTextFromServer: function() { with(this) {
|
116
|
+
inPlaceEditor.options.loadTextURL = '_ajax_inplaceeditor_text.html';
|
117
|
+
inPlaceEditor.enterEditMode();
|
118
|
+
assertEqual('Loading...', inPlaceEditor._form.value.value);
|
119
|
+
assert(inPlaceEditor._form.value.disabled);
|
120
|
+
assert(Element.hasClassName(inPlaceEditor._form, 'inplaceeditor-loading'));
|
121
|
+
wait(1000, function() {
|
122
|
+
assertEqual('Text from server', inPlaceEditor._form.value.value);
|
123
|
+
assert(!inPlaceEditor._form.value.disabled);
|
124
|
+
});
|
125
|
+
}},
|
126
|
+
|
127
|
+
testDisposesProperly: function() { with(this) {
|
128
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
129
|
+
inPlaceEditor.dispose();
|
130
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
131
|
+
assertVisible($('tobeedited'));
|
132
|
+
Event.simulateMouse('tobeedited','click');
|
133
|
+
assertVisible($('tobeedited'));
|
134
|
+
}},
|
135
|
+
|
136
|
+
testUsesTextAreaWhenMoreThanOneRows: function() { with(this) {
|
137
|
+
inPlaceEditor.options.rows = 5;
|
138
|
+
inPlaceEditor.enterEditMode();
|
139
|
+
assertEqual("TEXTAREA", document.forms[0].firstChild.tagName);
|
140
|
+
assertEqual("BR", document.forms[0].childNodes[1].tagName);
|
141
|
+
}},
|
142
|
+
|
143
|
+
testCanSpecifyAllTextsThroughOptions: function() { with(this) {
|
144
|
+
// swedish translation ;-)
|
145
|
+
inPlaceEditor.options.okText = "spara";
|
146
|
+
inPlaceEditor.options.cancelText = "avbryt";
|
147
|
+
inPlaceEditor.options.savingText = "Sparar...";
|
148
|
+
inPlaceEditor.enterEditMode();
|
149
|
+
assertEqual("spara", document.forms[0].lastChild.previousSibling.value);
|
150
|
+
assertEqual("avbryt", document.forms[0].lastChild.innerHTML);
|
151
|
+
inPlaceEditor.showSaving();
|
152
|
+
assertEqual("Sparar...", $('tobeedited').innerHTML);
|
153
|
+
}},
|
154
|
+
|
155
|
+
testCanSpecifyFormIdThroughOptions: function() { with(this) {
|
156
|
+
inPlaceEditor.enterEditMode();
|
157
|
+
// default form id
|
158
|
+
assertEqual("tobeedited-inplaceeditor", document.forms[0].id);
|
159
|
+
inPlaceEditor.leaveEditMode();
|
160
|
+
inPlaceEditor.options.formId = "myFormId";
|
161
|
+
inPlaceEditor.enterEditMode();
|
162
|
+
assertEqual("myFormId", document.forms[0].id);
|
163
|
+
}},
|
164
|
+
|
165
|
+
testCantEditWhileSaving: function() { with(this) {
|
166
|
+
inPlaceEditor.prepareSubmission();
|
167
|
+
Event.simulateMouse('tobeedited','mouseover');
|
168
|
+
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
169
|
+
Event.simulateMouse('tobeedited','click');
|
170
|
+
assertVisible($('tobeedited'));
|
171
|
+
}},
|
172
|
+
|
173
|
+
testCallbackFunctionGetsCalled: function() { with(this) {
|
174
|
+
var called = false;
|
175
|
+
inPlaceEditor.options.callback = function(form) {
|
176
|
+
called = true;
|
177
|
+
}
|
178
|
+
Event.simulateMouse('tobeedited','click');
|
179
|
+
Event.simulateMouse(document.forms[0].childNodes[1],'click');
|
180
|
+
assert(called, "callback was not called");
|
181
|
+
}},
|
182
|
+
|
183
|
+
testCanUseExternalElementToGoIntoEditMode: function() { with(this) {
|
184
|
+
Event.simulateMouse('tobeeditedEditControl','click');
|
185
|
+
assertNotNull(document.forms[0], "external control didn't work");
|
186
|
+
// doesn't work if you click it again while in edit mode
|
187
|
+
Event.simulateMouse('tobeeditedEditControl','click');
|
188
|
+
assertNull(document.forms[1], "external control created two forms");
|
189
|
+
assertNotVisible($('tobeeditedEditControl'));
|
190
|
+
Event.simulateMouse(document.forms[0].childNodes[2],'click');
|
191
|
+
assertVisible($('tobeeditedEditControl'));
|
192
|
+
}},
|
193
|
+
|
194
|
+
// Rewritten-version tests
|
195
|
+
testControlOptions: function() {with(this) {
|
196
|
+
// Default, then explicit default-equivalent, settings
|
197
|
+
[{}, { okControl: 'button', cancelControl: 'link' }].each(function(opts) {
|
198
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '', opts);
|
199
|
+
Event.simulateMouse('newtbe', 'click');
|
200
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
201
|
+
assertEqual(1, submits.length, 'Not just one submit');
|
202
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, submits[0].value, 'Incorrect button label');
|
203
|
+
assert(submits[0].hasClassName('editor_ok_button'), 'Missing class name on ok button');
|
204
|
+
var links = $$('#newtbe-inplaceeditor a');
|
205
|
+
assertEqual(1, links.length, 'Not just one link');
|
206
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, links[0].firstChild.nodeValue, 'Incorrect cancel link text');
|
207
|
+
assert(links[0].href.endsWith('#'), 'Incorrect cancel link href');
|
208
|
+
assert(links[0].hasClassName('editor_cancel_link'), 'Missing class name on cancel link');
|
209
|
+
ipe.dispose();
|
210
|
+
});
|
211
|
+
// Reverse: ok link, cancel button
|
212
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: 'link', cancelControl: 'button' });
|
213
|
+
Event.simulateMouse('newtbe', 'click');
|
214
|
+
var links = $$('#newtbe-inplaceeditor a');
|
215
|
+
assertEqual(1, links.length, 'Not just one link');
|
216
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, links[0].firstChild.nodeValue, 'Incorrect ok link text');
|
217
|
+
assert(links[0].href.endsWith('#'), 'Incorrect ok link href');
|
218
|
+
assert(links[0].hasClassName('editor_ok_link'), 'Missing class name on ok link');
|
219
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
220
|
+
assertEqual(1, submits.length, 'Not just one submit');
|
221
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, submits[0].value, 'Incorrect button label');
|
222
|
+
assert(submits[0].hasClassName('editor_cancel_button'), 'Missing class name on cancel button');
|
223
|
+
ipe.dispose();
|
224
|
+
// Full links
|
225
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: 'link' });
|
226
|
+
Event.simulateMouse('newtbe', 'click');
|
227
|
+
var links = $$('#newtbe-inplaceeditor a');
|
228
|
+
assertEqual(2, links.length, 'There should be two links');
|
229
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, links[0].firstChild.nodeValue, 'Incorrect ok link text');
|
230
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, links[1].firstChild.nodeValue, 'Incorrect cancel link text');
|
231
|
+
assert(links[0].href.endsWith('#'), 'Incorrect ok link href');
|
232
|
+
assert(links[1].href.endsWith('#'), 'Incorrect cancel link href');
|
233
|
+
assert(links[0].hasClassName('editor_ok_link'), 'Missing class name on ok link');
|
234
|
+
assert(links[1].hasClassName('editor_cancel_link'), 'Missing class name on cancel link');
|
235
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
236
|
+
assertEqual(0, submits.length, 'There should be no submit');
|
237
|
+
ipe.dispose();
|
238
|
+
// Full buttons
|
239
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { cancelControl: 'button' });
|
240
|
+
Event.simulateMouse('newtbe', 'click');
|
241
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
242
|
+
assertEqual(2, submits.length, 'There should be two submits');
|
243
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, submits[0].value, 'Incorrect ok button text');
|
244
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, submits[1].value, 'Incorrect cancel button text');
|
245
|
+
assert(submits[0].hasClassName('editor_ok_button'), 'Missing class name on ok button');
|
246
|
+
assert(submits[1].hasClassName('editor_cancel_button'), 'Missing class name on cancel button');
|
247
|
+
var links = $$('#newtbe-inplaceeditor a');
|
248
|
+
assertEqual(0, links.length, 'There should be no link');
|
249
|
+
ipe.dispose();
|
250
|
+
// No cancel
|
251
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { cancelControl: false });
|
252
|
+
Event.simulateMouse('newtbe', 'click');
|
253
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
254
|
+
assertEqual(1, submits.length, 'Not just one submit');
|
255
|
+
var links = $$('#newtbe-inplaceeditor a');
|
256
|
+
assertEqual(0, links.length, 'There should be no link');
|
257
|
+
ipe.dispose();
|
258
|
+
// No OK
|
259
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false });
|
260
|
+
Event.simulateMouse('newtbe', 'click');
|
261
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
262
|
+
assertEqual(0, submits.length, 'There should be no submit');
|
263
|
+
var links = $$('#newtbe-inplaceeditor a');
|
264
|
+
assertEqual(1, links.length, 'Not just one link');
|
265
|
+
ipe.dispose();
|
266
|
+
// Nothing
|
267
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false, cancelControl: false });
|
268
|
+
Event.simulateMouse('newtbe', 'click');
|
269
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
270
|
+
assertEqual(0, submits.length, 'There should be no submit');
|
271
|
+
var links = $$('#newtbe-inplaceeditor a');
|
272
|
+
assertEqual(0, links.length, 'There should be no link');
|
273
|
+
ipe.dispose();
|
274
|
+
// Texts: default mode
|
275
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false, cancelControl: false });
|
276
|
+
Event.simulateMouse('newtbe', 'click');
|
277
|
+
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
278
|
+
assertEqual(0, submits.length, 'There should be no submit');
|
279
|
+
var links = $$('#newtbe-inplaceeditor a');
|
280
|
+
assertEqual(0, links.length, 'There should be no link');
|
281
|
+
ipe.dispose();
|
282
|
+
// Texts: before w/ controls
|
283
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBeforeControls: '[' });
|
284
|
+
Event.simulateMouse('newtbe', 'click');
|
285
|
+
var text = $('newtbe-inplaceeditor').childNodes[1];
|
286
|
+
assertEqual(3, text.nodeType, 'Missing/misplaced initial text');
|
287
|
+
assertEqual('[', text.nodeValue, 'Incorrect text');
|
288
|
+
ipe.dispose();
|
289
|
+
// Texts: after w/ controls
|
290
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textAfterControls: ']' });
|
291
|
+
Event.simulateMouse('newtbe', 'click');
|
292
|
+
var text = $('newtbe-inplaceeditor').childNodes[3];
|
293
|
+
assertEqual(3, text.nodeType, 'Missing/misplaced final text');
|
294
|
+
assertEqual(']', text.nodeValue, 'Incorrect text');
|
295
|
+
ipe.dispose();
|
296
|
+
// Texts: between w/ controls
|
297
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBetweenControls: ' ' });
|
298
|
+
Event.simulateMouse('newtbe', 'click');
|
299
|
+
var text = $('newtbe-inplaceeditor').childNodes[2];
|
300
|
+
assertEqual(3, text.nodeType, 'Missing/misplaced middle text');
|
301
|
+
assertEqual(' ', text.nodeValue, 'Incorrect text');
|
302
|
+
ipe.dispose();
|
303
|
+
// Texts: before w/ no control
|
304
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBeforeControls: '[', okControl: false, cancelControl: false });
|
305
|
+
Event.simulateMouse('newtbe', 'click');
|
306
|
+
var nodes = $('newtbe-inplaceeditor').childNodes;
|
307
|
+
assertEqual(1, nodes.length, 'Too many nodes in the form.');
|
308
|
+
ipe.dispose();
|
309
|
+
// Texts: after w/ no control
|
310
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textAfterControls: ']', okControl: false, cancelControl: false });
|
311
|
+
Event.simulateMouse('newtbe', 'click');
|
312
|
+
var nodes = $('newtbe-inplaceeditor').childNodes;
|
313
|
+
assertEqual(1, nodes.length, 'Too many nodes in the form.');
|
314
|
+
ipe.dispose();
|
315
|
+
// Texts: between w/ less than two controls
|
316
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBetweenControls: ' ', okControl: false });
|
317
|
+
Event.simulateMouse('newtbe', 'click');
|
318
|
+
var nodes = $('newtbe-inplaceeditor').childNodes;
|
319
|
+
assertEqual(2, nodes.length, 'The form should have only two nodes (edit+cancel)');
|
320
|
+
assertEnumEqual(['input', 'a'], $A(nodes).pluck('tagName').invoke('toLowerCase'), 'Incorrect nodes');
|
321
|
+
ipe.dispose();
|
322
|
+
}},
|
323
|
+
|
324
|
+
testExternalControlOnly: function() {with(this) {
|
325
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
326
|
+
externalControl: 'newtbe_external'
|
327
|
+
});
|
328
|
+
Event.simulateMouse('newtbe', 'click');
|
329
|
+
assert(ipe._editing, 'Clicking on the element should turn editable.');
|
330
|
+
ipe.leaveEditMode();
|
331
|
+
Event.simulateMouse('newtbe_external', 'click');
|
332
|
+
assert(ipe._editing, 'Clicking on the external control should turn editable.');
|
333
|
+
ipe.dispose();
|
334
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
335
|
+
externalControl: 'newtbe_external', externalControlOnly: true
|
336
|
+
});
|
337
|
+
Event.simulateMouse('newtbe', 'click');
|
338
|
+
assert(!ipe._editing, 'Clicking on the element should not turn editable.');
|
339
|
+
Event.simulateMouse('newtbe_external', 'click');
|
340
|
+
assert(ipe._editing, 'Clicking on the external control should turn editable.');
|
341
|
+
ipe.dispose();
|
342
|
+
}},
|
343
|
+
|
344
|
+
testNewCallbacks: function() {with(this) {
|
345
|
+
var called = [];
|
346
|
+
var opts = {
|
347
|
+
onEnterHover: function() { called.push('onEnterHover') },
|
348
|
+
onEnterEditMode: function() { called.push('onEnterEditMode') },
|
349
|
+
onLeaveEditMode: function() { called.push('onLeaveEditMode') },
|
350
|
+
callback: function(form) {
|
351
|
+
called.push('callback');
|
352
|
+
return form.serialize();
|
353
|
+
},
|
354
|
+
onFailure: function() { called.push('onFailure') },
|
355
|
+
onComplete: function() { called.push('onComplete') },
|
356
|
+
onLeaveEditMode: function() { called.push('onLeaveEditMode') }
|
357
|
+
}
|
358
|
+
// Proper success
|
359
|
+
$('newtbe').update('New to be edited');
|
360
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', opts);
|
361
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
362
|
+
Event.simulateMouse('newtbe', 'click');
|
363
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
364
|
+
var postUpdateHTML;
|
365
|
+
wait(1000, function() {
|
366
|
+
assertEnumEqual(['onEnterHover', 'onEnterEditMode', 'callback', 'onLeaveEditMode', 'onComplete'],
|
367
|
+
called.uniq(), 'Incorrect callback sequence');
|
368
|
+
postUpdateHTML = $('newtbe').innerHTML.strip();
|
369
|
+
assertEqual('New to be edited - edited', postUpdateHTML, 'Update trouble');
|
370
|
+
ipe.dispose();
|
371
|
+
// Failure
|
372
|
+
called.clear();
|
373
|
+
// Any ideas? Requesting file:// URLs on non-existent stuff doesn't trigger A.U's onFailure...
|
374
|
+
});
|
375
|
+
}},
|
376
|
+
|
377
|
+
testCallbackFunctionReturnTypes: function() { with(this) {
|
378
|
+
var params = [];
|
379
|
+
var responder = {
|
380
|
+
onCreate: function(req) {
|
381
|
+
params.push(req.options.parameters);
|
382
|
+
}
|
383
|
+
};
|
384
|
+
Ajax.Responders.register(responder);
|
385
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
386
|
+
callback: function(form) {
|
387
|
+
return 'foo=bar';
|
388
|
+
}
|
389
|
+
});
|
390
|
+
Event.simulateMouse('newtbe', 'click');
|
391
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
392
|
+
wait(200, function() {
|
393
|
+
assert(params[0] && params[0].foo == 'bar');
|
394
|
+
ipe.dispose();
|
395
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
396
|
+
callback: function(form) {
|
397
|
+
return { bar: '?', 'r&d': 42 };
|
398
|
+
}
|
399
|
+
});
|
400
|
+
Event.simulateMouse('newtbe', 'click');
|
401
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
402
|
+
wait(200, function() {
|
403
|
+
assert(params[1] && params[1].bar == '?' && params[1]['r&d'] == 42);
|
404
|
+
ipe.dispose();
|
405
|
+
Ajax.Responders.unregister(responder);
|
406
|
+
})
|
407
|
+
});
|
408
|
+
}},
|
409
|
+
|
410
|
+
testHtmlResponse: function() {with(this) {
|
411
|
+
// Default (true) -> A.U w/ evalScripts: true
|
412
|
+
$('newtbe').update('New to be edited');
|
413
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html');
|
414
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
415
|
+
Event.simulateMouse('newtbe', 'click');
|
416
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
417
|
+
var postUpdateHTML;
|
418
|
+
wait(1000, function() {
|
419
|
+
postUpdateHTML = $('newtbe').innerHTML.strip();
|
420
|
+
assertEqual('New to be edited - edited', postUpdateHTML, 'Should have updated contents');
|
421
|
+
ipe.dispose();
|
422
|
+
// Explicit htmlResponse: true -> A.U w/ evalScripts: true
|
423
|
+
$('newtbe').update('New to be edited');
|
424
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', { htmlResponse: true });
|
425
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
426
|
+
Event.simulateMouse('newtbe', 'click');
|
427
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
428
|
+
wait(1000, function() {
|
429
|
+
postUpdateHTML = $('newtbe').innerHTML.strip();
|
430
|
+
assertEqual('New to be edited - edited', postUpdateHTML, 'Should have updated contents');
|
431
|
+
ipe.dispose();
|
432
|
+
// Explicit htmlResponse: false -> A.R
|
433
|
+
$('newtbe').update('New to be edited');
|
434
|
+
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', { htmlResponse: false });
|
435
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
436
|
+
Event.simulateMouse('newtbe', 'click');
|
437
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
438
|
+
wait(1000, function() {
|
439
|
+
postUpdateHTML = $('newtbe').innerHTML.strip();
|
440
|
+
assertEqual(ipe.options.savingText, postUpdateHTML, 'Should not have updated contents');
|
441
|
+
ipe.dispose();
|
442
|
+
});
|
443
|
+
});
|
444
|
+
});
|
445
|
+
}},
|
446
|
+
|
447
|
+
testSingleOrMultipleRows: function() {with(this) {
|
448
|
+
// Single-line value, rows <= 1 -> 1
|
449
|
+
$('newtbe').update('New to be edited');
|
450
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
451
|
+
'_ajax_inplaceeditor_result2.html');
|
452
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
453
|
+
Event.simulateMouse('newtbe', 'click');
|
454
|
+
assertEqual('input', ipe._controls.editor.tagName.toLowerCase());
|
455
|
+
ipe.dispose();
|
456
|
+
// Single-line value, rows > 1 (2) -> 2
|
457
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
458
|
+
'_ajax_inplaceeditor_result2.html', { rows: 2 });
|
459
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
460
|
+
Event.simulateMouse('newtbe', 'click');
|
461
|
+
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
462
|
+
assertEqual(2, ipe._controls.editor.rows);
|
463
|
+
ipe.dispose();
|
464
|
+
// Multiple-line value, rows <= 1, autoRows default (3) -> 3
|
465
|
+
$('newtbe').update('Line 1\nLine 2\nLine 3');
|
466
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
467
|
+
'_ajax_inplaceeditor_result2.html');
|
468
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
469
|
+
Event.simulateMouse('newtbe', 'click');
|
470
|
+
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
471
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.autoRows, ipe._controls.editor.rows);
|
472
|
+
ipe.dispose();
|
473
|
+
// Multiple-line value, rows <= 1, autoRows custom (5) -> 5
|
474
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
475
|
+
'_ajax_inplaceeditor_result2.html', { autoRows: 5 });
|
476
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
477
|
+
Event.simulateMouse('newtbe', 'click');
|
478
|
+
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
479
|
+
assertEqual(5, ipe._controls.editor.rows);
|
480
|
+
ipe.dispose();
|
481
|
+
// Multiple-line value, rows > 1 (2), autoRows default (3) -> 2
|
482
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
483
|
+
'_ajax_inplaceeditor_result2.html', { rows: 2 });
|
484
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
485
|
+
Event.simulateMouse('newtbe', 'click');
|
486
|
+
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
487
|
+
assertEqual(2, ipe._controls.editor.rows);
|
488
|
+
ipe.dispose();
|
489
|
+
// Multiple-line value, rows > 1 (2), autoRows custom (5) -> 2
|
490
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
491
|
+
'_ajax_inplaceeditor_result2.html', { rows: 2, autoRows: 5 });
|
492
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
493
|
+
Event.simulateMouse('newtbe', 'click');
|
494
|
+
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
495
|
+
assertEqual(2, ipe._controls.editor.rows);
|
496
|
+
ipe.dispose();
|
497
|
+
}},
|
498
|
+
|
499
|
+
testFormCustomizationCallback: function() {with(this) {
|
500
|
+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
501
|
+
onFormCustomization: function(ipe, form) {
|
502
|
+
form.appendChild(new Element('input', { type: 'text', name: 'test', value: 'foobar' }));
|
503
|
+
}
|
504
|
+
});
|
505
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
506
|
+
Event.simulateMouse('newtbe', 'click');
|
507
|
+
assertEqual('foobar', Form.serialize(ipe._form, true).test, 'Custom field not present');
|
508
|
+
ipe.dispose();
|
509
|
+
}},
|
510
|
+
|
511
|
+
testPostCreationBehavior: function() {with(this) {
|
512
|
+
var focused = false, activated = false;
|
513
|
+
function override(name, fx) {
|
514
|
+
arguments.callee.backups[name] = Field.Methods[name];
|
515
|
+
Field.Methods[name] = fx;
|
516
|
+
};
|
517
|
+
override.backups = {};
|
518
|
+
function restore() {
|
519
|
+
$A(arguments).each(function(n) {
|
520
|
+
Field.Methods[name] = override.backups[name];
|
521
|
+
});
|
522
|
+
Element.addMethods();
|
523
|
+
};
|
524
|
+
override('activate', function(elt) {
|
525
|
+
override.backups['activate'](elt);
|
526
|
+
activated = true;
|
527
|
+
});
|
528
|
+
override('focus', function(elt) { focused = true; });
|
529
|
+
Element.addMethods();
|
530
|
+
// fieldPostCreation default (activate)
|
531
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
532
|
+
'_ajax_inplaceeditor_result2.html');
|
533
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
534
|
+
Event.simulateMouse('newtbe', 'click');
|
535
|
+
assert(focused && activated, "Should be focused and activated (resp. " + focused + " and " + activated + ')');
|
536
|
+
ipe.dispose();
|
537
|
+
// fieldPostCreation == 'focus'
|
538
|
+
focused = activated = false;
|
539
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
540
|
+
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: 'focus' });
|
541
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
542
|
+
Event.simulateMouse('newtbe', 'click');
|
543
|
+
assert(focused && !activated, "Should be focused, not activated (resp. " + focused + " and " + activated + ')');
|
544
|
+
ipe.dispose();
|
545
|
+
// fieldPostCreation == false
|
546
|
+
focused = activated = false;
|
547
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
548
|
+
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: false });
|
549
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
550
|
+
Event.simulateMouse('newtbe', 'click');
|
551
|
+
assert(!focused && !activated, "Should be neither focused nor activated (resp. " + focused + " and " + activated + ')');
|
552
|
+
ipe.dispose();
|
553
|
+
// fieldPostCreation == non-false yet neither activate nor focus -> default
|
554
|
+
focused = activated = false;
|
555
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
556
|
+
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: 'foobar' });
|
557
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
558
|
+
Event.simulateMouse('newtbe', 'click');
|
559
|
+
assert(focused && activated, "Should be focused and activated (resp. " + focused + " and " + activated + ')');
|
560
|
+
ipe.dispose();
|
561
|
+
restore('activate', 'focus');
|
562
|
+
}},
|
563
|
+
|
564
|
+
testResponseTagStripping: function() {with(this) {
|
565
|
+
// stripLoadedTextTags default (false)
|
566
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
567
|
+
'_ajax_inplaceeditor_result2.html',
|
568
|
+
{ loadTextURL: '_ajax_inplaceeditor_tagged.html' });
|
569
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
570
|
+
Event.simulateMouse('newtbe', 'click');
|
571
|
+
wait(1000, function() {
|
572
|
+
assertEqual('<span>New to be edited - edited</span>', ipe._controls.editor.value.strip());
|
573
|
+
ipe.dispose();
|
574
|
+
// stripLoadedTextTags == true
|
575
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
576
|
+
'_ajax_inplaceeditor_result2.html',
|
577
|
+
{ loadTextURL: '_ajax_inplaceeditor_tagged.html',
|
578
|
+
stripLoadedTextTags: true });
|
579
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
580
|
+
Event.simulateMouse('newtbe', 'click');
|
581
|
+
wait(1000, function() {
|
582
|
+
assertEqual('New to be edited - edited', ipe._controls.editor.value.strip());
|
583
|
+
ipe.dispose();
|
584
|
+
});
|
585
|
+
});
|
586
|
+
}},
|
587
|
+
|
588
|
+
testSubmitOnBlur: function() {with(this) {
|
589
|
+
// submitOnBlur default (false)
|
590
|
+
$('newtbe').update('To be edited');
|
591
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
592
|
+
'_ajax_inplaceeditor_result2.html');
|
593
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
594
|
+
Event.simulateMouse('newtbe', 'click');
|
595
|
+
ipe._controls.editor.blur();
|
596
|
+
wait(1000, function() {
|
597
|
+
assertEqual('To be edited', ipe._controls.editor ? ipe._controls.editor.value : '');
|
598
|
+
ipe.dispose();
|
599
|
+
// submitOnBlur == true
|
600
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
601
|
+
'_ajax_inplaceeditor_result2.html', { submitOnBlur: true });
|
602
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
603
|
+
Event.simulateMouse('newtbe', 'click');
|
604
|
+
ipe._controls.editor.blur();
|
605
|
+
wait(1200, function() {
|
606
|
+
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
607
|
+
ipe.dispose();
|
608
|
+
});
|
609
|
+
});
|
610
|
+
}},
|
611
|
+
|
612
|
+
testEscReturnKeys: function() {with(this) {
|
613
|
+
// No controls, Esc
|
614
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
615
|
+
'_ajax_inplaceeditor_result2.html', { okControl: false, cancelControl: false});
|
616
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
617
|
+
Event.simulateMouse('newtbe', 'click');
|
618
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
619
|
+
assert(!ipe._editing, 'Esc should have disabled IPE');
|
620
|
+
ipe.dispose();
|
621
|
+
// Cancel control, Esc
|
622
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
623
|
+
'_ajax_inplaceeditor_result2.html', { okControl: false });
|
624
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
625
|
+
Event.simulateMouse('newtbe', 'click');
|
626
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
627
|
+
assert(!ipe._editing, 'Esc should have disabled IPE');
|
628
|
+
ipe.dispose();
|
629
|
+
// OK control, Esc
|
630
|
+
var ipe = new Ajax.InPlaceEditor('newtbe',
|
631
|
+
'_ajax_inplaceeditor_result2.html', { cancelControl: false });
|
632
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
633
|
+
Event.simulateMouse('newtbe', 'click');
|
634
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
635
|
+
assert(!ipe._editing, 'Esc should have disabled IPE');
|
636
|
+
ipe.dispose();
|
637
|
+
// Both controls, Esc
|
638
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
639
|
+
'_ajax_inplaceeditor_result2.html');
|
640
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
641
|
+
Event.simulateMouse('newtbe', 'click');
|
642
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
643
|
+
assert(!ipe._editing, 'Esc should have disabled IPE');
|
644
|
+
ipe.dispose();
|
645
|
+
// No controls, Return
|
646
|
+
$('newtbe').update('New to be edited');
|
647
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
648
|
+
'_ajax_inplaceeditor_result2.html', { okControl: false, cancelControl: false });
|
649
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
650
|
+
Event.simulateMouse('newtbe', 'click');
|
651
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
652
|
+
wait(1000, function() {
|
653
|
+
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
654
|
+
ipe.dispose();
|
655
|
+
// Cancel control, Return
|
656
|
+
$('newtbe').update('New to be edited');
|
657
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
658
|
+
'_ajax_inplaceeditor_result2.html', { okControl: false });
|
659
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
660
|
+
Event.simulateMouse('newtbe', 'click');
|
661
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
662
|
+
wait(1000, function() {
|
663
|
+
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
664
|
+
ipe.dispose();
|
665
|
+
// OK control, Return
|
666
|
+
$('newtbe').update('New to be edited');
|
667
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
668
|
+
'_ajax_inplaceeditor_result2.html', { cancelControl: false });
|
669
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
670
|
+
Event.simulateMouse('newtbe', 'click');
|
671
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
672
|
+
wait(1000, function() {
|
673
|
+
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
674
|
+
ipe.dispose();
|
675
|
+
// Both controls, Return
|
676
|
+
$('newtbe').update('New to be edited');
|
677
|
+
ipe = new Ajax.InPlaceEditor('newtbe',
|
678
|
+
'_ajax_inplaceeditor_result2.html');
|
679
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
680
|
+
Event.simulateMouse('newtbe', 'click');
|
681
|
+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
682
|
+
wait(1000, function() {
|
683
|
+
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
684
|
+
ipe.dispose();
|
685
|
+
});
|
686
|
+
});
|
687
|
+
});
|
688
|
+
});
|
689
|
+
}},
|
690
|
+
|
691
|
+
testIPCEBasic: function() {with(this) {
|
692
|
+
// Basic creation, population and choice.
|
693
|
+
$('newtbe').update('ntbe');
|
694
|
+
var fieldValue = '';
|
695
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
696
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
697
|
+
collection: IPCE_COLLECTION, callback: function(f, value) {
|
698
|
+
fieldValue = value;
|
699
|
+
}, onComplete: Prototype.emptyFunction
|
700
|
+
});
|
701
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
702
|
+
Event.simulateMouse('newtbe', 'click');
|
703
|
+
var editor = ipe._controls.editor;
|
704
|
+
assertEqual('test', editor.name);
|
705
|
+
assertEqual('select', editor.tagName.toLowerCase());
|
706
|
+
assertEqual(IPCE_COLLECTION.length, editor.options.length, 'Incorrect amount of options');
|
707
|
+
for (var index = 0; index < IPCE_COLLECTION.length; ++index) {
|
708
|
+
var ref = IPCE_COLLECTION[index];
|
709
|
+
var item = editor.options[index];
|
710
|
+
assertEqual(ref[0], item.value, 'Incorrect OPTION value');
|
711
|
+
assertEqual(ref[1], item.text.strip(), 'Incorrect OPTION text');
|
712
|
+
};
|
713
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
714
|
+
editor.selectedIndex = 2;
|
715
|
+
Event.simulateMouse(ipe._controls.ok, 'click');
|
716
|
+
assertEqual('ntbe2', fieldValue);
|
717
|
+
ipe.dispose();
|
718
|
+
// Test the value option
|
719
|
+
$('newtbe').update('ntbe');
|
720
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
721
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
722
|
+
collection: IPCE_COLLECTION, onComplete: Prototype.emptyFunction,
|
723
|
+
value: 'ntbe2'
|
724
|
+
});
|
725
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
726
|
+
Event.simulateMouse('newtbe', 'click');
|
727
|
+
editor = ipe._controls.editor;
|
728
|
+
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
729
|
+
ipe.dispose();
|
730
|
+
}},
|
731
|
+
|
732
|
+
testIPCECollectionSyntaxes: function() {with(this) {
|
733
|
+
// Array of two-item arrays (0 = value, 1 = text)
|
734
|
+
$('newtbe').update('ntbe');
|
735
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
736
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
737
|
+
collection: IPCE_COLLECTION, onComplete: Prototype.emptyFunction
|
738
|
+
});
|
739
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
740
|
+
Event.simulateMouse('newtbe', 'click');
|
741
|
+
var editor = ipe._controls.editor;
|
742
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
743
|
+
// (further contents testing already done in Basic)
|
744
|
+
ipe.dispose();
|
745
|
+
// Array of one-item arrays
|
746
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
747
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
748
|
+
collection: [['tbe'], ['ntbe'], ['ntbe2'], ['ntbe3']],
|
749
|
+
onComplete: Prototype.emptyFunction
|
750
|
+
});
|
751
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
752
|
+
Event.simulateMouse('newtbe', 'click');
|
753
|
+
var editor = ipe._controls.editor;
|
754
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
755
|
+
assertEqual('ntbe', $F(editor).strip(), 'Did not properly define text');
|
756
|
+
ipe.dispose();
|
757
|
+
// Array of items
|
758
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
759
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
760
|
+
collection: ['tbe', 'ntbe', 'ntbe2', 'ntbe3'],
|
761
|
+
onComplete: Prototype.emptyFunction
|
762
|
+
});
|
763
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
764
|
+
Event.simulateMouse('newtbe', 'click');
|
765
|
+
var editor = ipe._controls.editor;
|
766
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
767
|
+
assertEqual('ntbe', $F(editor).strip(), 'Did not properly define text');
|
768
|
+
ipe.dispose();
|
769
|
+
}},
|
770
|
+
|
771
|
+
testIPCEAlternateTextOptions: function() {with(this) {
|
772
|
+
// loadTextURL (check loading text, verify alternate text eventually)
|
773
|
+
$('newtbe').update('New to be edited');
|
774
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
775
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
776
|
+
collection: IPCE_COLLECTION, loadTextURL: '_ajax_inplaceeditor_ipce_alt_text.html',
|
777
|
+
onComplete: Prototype.emptyFunction
|
778
|
+
});
|
779
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
780
|
+
Event.simulateMouse('newtbe', 'click');
|
781
|
+
var editor = ipe._controls.editor;
|
782
|
+
var text = editor.options[editor.selectedIndex].text.strip();
|
783
|
+
assertEqual(Ajax.InPlaceEditor.DefaultOptions.loadingText, text);
|
784
|
+
wait(1200, function() {
|
785
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item based on alternate text.');
|
786
|
+
ipe.dispose();
|
787
|
+
});
|
788
|
+
}},
|
789
|
+
|
790
|
+
testIPCEDynamicCollectionOptions: function() {with(this) {
|
791
|
+
// loadCollectionURL, default loadingCollectionText
|
792
|
+
$('newtbe').update('ntbe');
|
793
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
794
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
795
|
+
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
796
|
+
onComplete: Prototype.emptyFunction
|
797
|
+
});
|
798
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
799
|
+
Event.simulateMouse('newtbe', 'click');
|
800
|
+
var editor = ipe._controls.editor;
|
801
|
+
var text = editor.options[editor.selectedIndex].text.strip();
|
802
|
+
assertEqual(Ajax.InPlaceCollectionEditor.DefaultOptions.loadingCollectionText, text);
|
803
|
+
wait(1000, function() {
|
804
|
+
assertEqual(5, ipe._collection.length);
|
805
|
+
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
806
|
+
ipe.dispose();
|
807
|
+
// loadCollectionURL, custom loadingCollectionText
|
808
|
+
$('newtbe').update('bar');
|
809
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
810
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
811
|
+
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
812
|
+
loadingCollectionText: 'There we go...',
|
813
|
+
onComplete: Prototype.emptyFunction
|
814
|
+
});
|
815
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
816
|
+
Event.simulateMouse('newtbe', 'click');
|
817
|
+
editor = ipe._controls.editor;
|
818
|
+
text = editor.options[editor.selectedIndex].text.strip();
|
819
|
+
assertEqual('There we go...', text);
|
820
|
+
wait(1000, function() {
|
821
|
+
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
822
|
+
ipe.dispose();
|
823
|
+
});
|
824
|
+
});
|
825
|
+
}},
|
826
|
+
|
827
|
+
testIPCEATPlusDC: function() {with(this) {
|
828
|
+
// loadCollectionURL, loadTextURL
|
829
|
+
$('newtbe').update('Like I care');
|
830
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
831
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
832
|
+
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
833
|
+
loadingCollectionText: 'There we go...',
|
834
|
+
loadTextURL: '_ajax_inplaceeditor_ipce_alt_text.html',
|
835
|
+
loadingText: 'OK, so, the text...',
|
836
|
+
onComplete: Prototype.emptyFunction
|
837
|
+
});
|
838
|
+
ipe._regularCFET = ipe.checkForExternalText;
|
839
|
+
ipe.checkForExternalText = function() {
|
840
|
+
assert(5, ipe._collection.length);
|
841
|
+
ipe._regularCFET();
|
842
|
+
var editor = ipe._controls.editor;
|
843
|
+
var text = editor.options[editor.selectedIndex].text.strip();
|
844
|
+
assertEqual('OK, so, the text...', text);
|
845
|
+
};
|
846
|
+
Event.simulateMouse('newtbe', 'mouseover');
|
847
|
+
Event.simulateMouse('newtbe', 'click');
|
848
|
+
var editor = ipe._controls.editor;
|
849
|
+
var text = editor.options[editor.selectedIndex].text.strip();
|
850
|
+
assertEqual('There we go...', text);
|
851
|
+
wait(2000, function() {
|
852
|
+
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
853
|
+
ipe.dispose();
|
854
|
+
});
|
855
|
+
}},
|
856
|
+
|
857
|
+
testDeprecationLayer: function() {with(this) {
|
858
|
+
// FIXME: needs to be coded yet, doesn't it?
|
859
|
+
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
860
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
861
|
+
okButton: false, cancelLink: false
|
862
|
+
});
|
863
|
+
assertIdentical(false, ipe.options.okControl, 'OK control should be disabled');
|
864
|
+
assertIdentical(false, ipe.options.cancelControl, 'Cancel control should be disabled');
|
865
|
+
ipe.dispose();
|
866
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
867
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
868
|
+
okLink: true, cancelButton: true
|
869
|
+
});
|
870
|
+
assertEqual('link', ipe.options.okControl, 'OK control should be a link');
|
871
|
+
assertEqual('button', ipe.options.cancelControl, 'Cancel control should be a button');
|
872
|
+
ipe.dispose();
|
873
|
+
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
874
|
+
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
875
|
+
highlightcolor: '#ff0000', highlightendcolor: '#00ff00'
|
876
|
+
});
|
877
|
+
assertEqual('#ff0000', ipe.options.highlightColor, 'Highlight color was not migrated');
|
878
|
+
assertEqual('#00ff00', ipe.options.highlightEndColor, 'Highlight end color was not migrated');
|
879
|
+
ipe.dispose();
|
880
|
+
}},
|
881
|
+
|
882
|
+
|
883
|
+
testShouldShowAmpersandsProperly: function() {with(this) {
|
884
|
+
var ipe = new Ajax.InPlaceEditor('contains_ampersand', '', {});
|
885
|
+
Event.simulateMouse('contains_ampersand', 'click');
|
886
|
+
assertEqual("Me & Myself", $$('form#contains_ampersand-inplaceeditor input.editor_field')[0].value);
|
887
|
+
ipe.dispose();
|
888
|
+
}}
|
889
|
+
// FIXME: add AC w/o key conflicts?
|
890
|
+
// FIXME: doc w/ full details on what's new, what's changed, etc. + deprecation layer info.
|
891
|
+
});
|
892
|
+
// ]]>
|
893
|
+
</script>
|
894
|
+
</body>
|
895
|
+
</html>
|