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,148 @@
|
|
1
|
+
var testObj = {
|
2
|
+
isNice: function() {
|
3
|
+
return true;
|
4
|
+
},
|
5
|
+
isBroken: function() {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
new Test.Unit.Runner({
|
11
|
+
|
12
|
+
testIsRunningFromRake: function() {
|
13
|
+
if (window.location.toString().startsWith('http')) {
|
14
|
+
this.assert(this.isRunningFromRake);
|
15
|
+
this.info('These tests are running from rake.')
|
16
|
+
} else {
|
17
|
+
this.assert(!this.isRunningFromRake);
|
18
|
+
this.info('These tests are *not* running from rake.')
|
19
|
+
}
|
20
|
+
},
|
21
|
+
|
22
|
+
testBuildMessage: function() {
|
23
|
+
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
|
24
|
+
},
|
25
|
+
|
26
|
+
testAssertEqual: function() {
|
27
|
+
this.assertEqual(0, 0);
|
28
|
+
this.assertEqual(0, 0, "test");
|
29
|
+
|
30
|
+
this.assertEqual(0,'0');
|
31
|
+
this.assertEqual(65.0, 65);
|
32
|
+
|
33
|
+
this.assertEqual("a", "a");
|
34
|
+
this.assertEqual("a", "a", "test");
|
35
|
+
|
36
|
+
this.assertNotEqual(0, 1);
|
37
|
+
this.assertNotEqual("a","b");
|
38
|
+
this.assertNotEqual({},{});
|
39
|
+
this.assertNotEqual([],[]);
|
40
|
+
this.assertNotEqual([],{});
|
41
|
+
},
|
42
|
+
|
43
|
+
testAssertEnumEqual: function() {
|
44
|
+
this.assertEnumEqual([], []);
|
45
|
+
this.assertEnumEqual(['a', 'b'], ['a', 'b']);
|
46
|
+
this.assertEnumEqual(['1', '2'], [1, 2]);
|
47
|
+
this.assertEnumNotEqual(['1', '2'], [1, 2, 3]);
|
48
|
+
},
|
49
|
+
|
50
|
+
testAssertHashEqual: function() {
|
51
|
+
this.assertHashEqual({}, {});
|
52
|
+
this.assertHashEqual({a:'b'}, {a:'b'});
|
53
|
+
this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
|
54
|
+
this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
|
55
|
+
},
|
56
|
+
|
57
|
+
testAssertRespondsTo: function() {
|
58
|
+
this.assertRespondsTo('isNice', testObj);
|
59
|
+
this.assertRespondsTo('isBroken', testObj);
|
60
|
+
},
|
61
|
+
|
62
|
+
testAssertIdentical: function() {
|
63
|
+
this.assertIdentical(0, 0);
|
64
|
+
this.assertIdentical(0, 0, "test");
|
65
|
+
this.assertIdentical(1, 1);
|
66
|
+
this.assertIdentical('a', 'a');
|
67
|
+
this.assertIdentical('a', 'a', "test");
|
68
|
+
this.assertIdentical('', '');
|
69
|
+
this.assertIdentical(undefined, undefined);
|
70
|
+
this.assertIdentical(null, null);
|
71
|
+
this.assertIdentical(true, true);
|
72
|
+
this.assertIdentical(false, false);
|
73
|
+
|
74
|
+
var obj = {a:'b'};
|
75
|
+
this.assertIdentical(obj, obj);
|
76
|
+
|
77
|
+
this.assertNotIdentical({1:2,3:4},{1:2,3:4});
|
78
|
+
|
79
|
+
this.assertIdentical(1, 1.0); // both are typeof == 'number'
|
80
|
+
|
81
|
+
this.assertNotIdentical(1, '1');
|
82
|
+
this.assertNotIdentical(1, '1.0');
|
83
|
+
},
|
84
|
+
|
85
|
+
testAssertNullAndAssertUndefined: function() {
|
86
|
+
this.assertNull(null);
|
87
|
+
this.assertNotNull(undefined);
|
88
|
+
this.assertNotNull(0);
|
89
|
+
this.assertNotNull('');
|
90
|
+
this.assertNotUndefined(null);
|
91
|
+
this.assertUndefined(undefined);
|
92
|
+
this.assertNotUndefined(0);
|
93
|
+
this.assertNotUndefined('');
|
94
|
+
this.assertNullOrUndefined(null);
|
95
|
+
this.assertNullOrUndefined(undefined);
|
96
|
+
this.assertNotNullOrUndefined(0);
|
97
|
+
this.assertNotNullOrUndefined('');
|
98
|
+
},
|
99
|
+
|
100
|
+
testAssertMatch: function() {
|
101
|
+
this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
|
102
|
+
this.assertMatch(/Fuc/, 'Thomas Fuchs');
|
103
|
+
this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
|
104
|
+
this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
|
105
|
+
this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
|
106
|
+
this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
|
107
|
+
this.assertNoMatch(/zubar/, 'foo bar');
|
108
|
+
},
|
109
|
+
|
110
|
+
testAssertInstanceOf: function() {
|
111
|
+
this.assertInstanceOf(String, new String);
|
112
|
+
this.assertInstanceOf(RegExp, /foo/);
|
113
|
+
this.assertNotInstanceOf(String, {});
|
114
|
+
},
|
115
|
+
|
116
|
+
testAssertVisible: function() {
|
117
|
+
this.assertVisible('testcss1');
|
118
|
+
this.assertNotVisible('testcss1_span');
|
119
|
+
//this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
|
120
|
+
|
121
|
+
Element.hide('testcss1');
|
122
|
+
this.assertNotVisible('testcss1');
|
123
|
+
this.assertNotVisible('testcss1_span');
|
124
|
+
Element.show('testcss1');
|
125
|
+
this.assertVisible('testcss1');
|
126
|
+
this.assertNotVisible('testcss1_span');
|
127
|
+
|
128
|
+
Element.show('testcss1_span');
|
129
|
+
this.assertVisible('testcss1_span');
|
130
|
+
Element.hide('testcss1');
|
131
|
+
this.assertNotVisible('testcss1_span'); // hidden by parent
|
132
|
+
},
|
133
|
+
|
134
|
+
testAssertElementsMatch: function() {
|
135
|
+
this.assertElementsMatch($$('#tlist'), '#tlist');
|
136
|
+
this.assertElementMatches($('tlist'), '#tlist');
|
137
|
+
}
|
138
|
+
});
|
139
|
+
|
140
|
+
new Test.Unit.Runner({
|
141
|
+
testDummy: function() {
|
142
|
+
this.assert(true);
|
143
|
+
},
|
144
|
+
|
145
|
+
testMultipleTestRunner: function() {
|
146
|
+
this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
|
147
|
+
}
|
148
|
+
}, {testLog: 'testlog_2'});
|
@@ -0,0 +1,45 @@
|
|
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>Unit test file | Unittest | default template | 2009-04-11 15:28</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
<script type="text/javascript" charset="utf-8">
|
8
|
+
var eventResults = {};
|
9
|
+
var originalElement = window.Element;
|
10
|
+
</script>
|
11
|
+
<script src="assets/prototype.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="assets/unittest.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
|
14
|
+
|
15
|
+
|
16
|
+
<script src="tests/unittest_test.js" type="text/javascript" charset="utf-8"></script>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
|
20
|
+
<div id="testlog"></div>
|
21
|
+
|
22
|
+
<div id="testlog_2"> </div>
|
23
|
+
|
24
|
+
<!-- Test elements follow -->
|
25
|
+
<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
|
26
|
+
|
27
|
+
<div id="test_2"> <span> </span>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
<div><div></div> </div><span> </span>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul>
|
35
|
+
<ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul>
|
36
|
+
|
37
|
+
<div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div>
|
38
|
+
|
39
|
+
<div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div>
|
40
|
+
|
41
|
+
</body>
|
42
|
+
</html>
|
43
|
+
<script type="text/javascript" charset="utf-8">
|
44
|
+
eventResults.endOfDocument = true;
|
45
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
37bdd117a0a57c3d39075bd2d972de8dde71520f
|
@@ -0,0 +1 @@
|
|
1
|
+
ntbe
|
@@ -0,0 +1 @@
|
|
1
|
+
[['foo', 'Foo'], ['bar', 'Bar'], ['ntbe', 'New to be edited'], ['ntbe2', 'New to be edited #2'], ['ntbe3', 'New to be edited #3']]
|
@@ -0,0 +1 @@
|
|
1
|
+
Server received: To be edited
|
@@ -0,0 +1 @@
|
|
1
|
+
New to be edited - edited
|
@@ -0,0 +1 @@
|
|
1
|
+
<span>New to be edited - edited</span>
|
@@ -0,0 +1 @@
|
|
1
|
+
Text from server
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Test text
|
2
|
+
|
3
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
4
|
+
// <![CDATA[
|
5
|
+
alert('fragment1 hit!');
|
6
|
+
// ]]>
|
7
|
+
</script>
|
8
|
+
|
9
|
+
more test text
|
10
|
+
|
11
|
+
|
12
|
+
<script>alert('fragment2 hit!')</script>
|
13
|
+
|
14
|
+
|
15
|
+
even more test text
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
alert('fragment3 hit!');
|
19
|
+
</script> some other test text
|
20
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<ul>
|
2
|
+
<li>test1</li><li>test2</li>
|
3
|
+
<li>test3</li>
|
4
|
+
<li><b>BOLD</b></li>
|
5
|
+
|
6
|
+
<li><span class="informal">(GET ME NOT)</span>(GET <ME> INSTEAD)</li>
|
7
|
+
|
8
|
+
<li>Here we have <a href="_autocomplete_result.html">a link</a> which should work</li>
|
9
|
+
|
10
|
+
<li>Here we have some international ©∏Á®Äç†∑rß</li>
|
11
|
+
</ul>
|
@@ -0,0 +1 @@
|
|
1
|
+
<ul><li>test1</li><li>test2</li><li>test3</li><li><b>BOLD</b></li><li><span class="informal">(GET ME NOT)</span>(GET <ME> INSTEAD)</li><li>Here we have <a href="_autocomplete_result.html">a link</a> which should work</li><li>Here we have some international ©∏Á®Äç†∑rß</li></ul>
|
@@ -0,0 +1,243 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<!-- vim:expandtab=on
|
4
|
+
-->
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
+
<head>
|
7
|
+
<title>script.aculo.us Unit test file</title>
|
8
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
9
|
+
<script src="assets/prototype.js" type="text/javascript"></script>
|
10
|
+
<script src="assets/scriptaculous.js" type="text/javascript"></script>
|
11
|
+
<script src="assets/unittest.js" type="text/javascript"></script>
|
12
|
+
<link rel="stylesheet" href="../test.css" type="text/css" />
|
13
|
+
<style>
|
14
|
+
.selected { background-color: #888; }
|
15
|
+
</style>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<h1>script.aculo.us Unit test file</h1>
|
19
|
+
<p>
|
20
|
+
Tests for Ajax.Autocompleter in controls.js.
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<!-- Log output -->
|
24
|
+
<div id="testlog"> </div>
|
25
|
+
|
26
|
+
<input id="ac_input" type="text" autocomplete="off" />
|
27
|
+
<div id="ac_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
28
|
+
|
29
|
+
<input id="ac_input_br" type="text" autocomplete="off" />
|
30
|
+
<div id="ac_update_br" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
31
|
+
|
32
|
+
<input id="ac2_input" type="text" autocomplete="off" />
|
33
|
+
<div id="ac2_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
34
|
+
|
35
|
+
<input id="actoken_input" type="text" autocomplete="off" />
|
36
|
+
<div id="actoken_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
37
|
+
|
38
|
+
<input id="dummy_element" type="text" autocomplete="off" />
|
39
|
+
|
40
|
+
<!-- Tests follow -->
|
41
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
42
|
+
// <![CDATA[
|
43
|
+
|
44
|
+
|
45
|
+
new Test.Unit.Runner({
|
46
|
+
|
47
|
+
// Integration test, tests the entire cycle
|
48
|
+
testAjaxAutocompleter: function() { with(this) {
|
49
|
+
var ac = new Ajax.Autocompleter('ac_input','ac_update','_autocomplete_result.html',
|
50
|
+
{ method: 'get' }); //override so we can use a static for the result
|
51
|
+
assertInstanceOf(Ajax.Autocompleter, ac);
|
52
|
+
|
53
|
+
// box not visible
|
54
|
+
assertNotVisible('ac_update');
|
55
|
+
|
56
|
+
// focus, but box not visible
|
57
|
+
Event.simulateMouse('ac_input', 'click');
|
58
|
+
assertNotVisible('ac_update');
|
59
|
+
|
60
|
+
Event.simulateKeys('ac_input','abcdefg');
|
61
|
+
assertEqual('abcdefg', $('ac_input').value);
|
62
|
+
|
63
|
+
// check box popping up on input
|
64
|
+
wait(1000, function() { with(this) {
|
65
|
+
assertVisible('ac_update');
|
66
|
+
assertEqual('test1', $('ac_update').firstChild.firstChild.innerHTML);
|
67
|
+
assertEqual('test2', $('ac_update').firstChild.firstChild.nextSibling.innerHTML);
|
68
|
+
|
69
|
+
// intl. characters return (UTF-8)
|
70
|
+
assertEqual('Here we have some international ©∏Á®Äç†∑rß', $('ac_update').firstChild.lastChild.innerHTML);
|
71
|
+
|
72
|
+
// first entry should be selected
|
73
|
+
assert(Element.hasClassName($('ac_update').firstChild.firstChild, 'selected'),'Selected item should have a className of: selected');
|
74
|
+
|
75
|
+
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_DOWN});
|
76
|
+
|
77
|
+
// second entry should be selected
|
78
|
+
assert(!Element.hasClassName($('ac_update').firstChild.firstChild),'Item shouldn\'t have a className of: selected');
|
79
|
+
assert(Element.hasClassName($('ac_update').firstChild.firstChild.nextSibling, 'selected'),'Second entry should have a className of: selected');
|
80
|
+
|
81
|
+
// check selecting with <TAB>
|
82
|
+
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_TAB});
|
83
|
+
assertEqual('test2',$('ac_input').value);
|
84
|
+
|
85
|
+
// check box going away
|
86
|
+
wait(500, function() { with(this) {
|
87
|
+
assertNotVisible('ac_update');
|
88
|
+
|
89
|
+
// check selecting with mouse click
|
90
|
+
Event.simulateKeys('ac_input','3');
|
91
|
+
assertEqual('test23', $('ac_input').value);
|
92
|
+
wait(1000, function() { with(this) {
|
93
|
+
assertVisible('ac_update');
|
94
|
+
Event.simulateMouse($('ac_update').firstChild.childNodes[4],'click');
|
95
|
+
|
96
|
+
wait(1000, function() { with(this) {
|
97
|
+
// tests if removal of 'informal' nodes and HTML escaping works
|
98
|
+
assertEqual('(GET <ME> INSTEAD)',$('ac_input').value);
|
99
|
+
assertNotVisible('ac_update');
|
100
|
+
|
101
|
+
// check cancelling with <ESC>
|
102
|
+
Event.simulateKeys('ac_input','abcdefg');
|
103
|
+
|
104
|
+
wait(1000, function() { with(this) {
|
105
|
+
assertVisible('ac_update');
|
106
|
+
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input').value);
|
107
|
+
|
108
|
+
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_DOWN});
|
109
|
+
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_ESC});
|
110
|
+
|
111
|
+
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input').value);
|
112
|
+
}});
|
113
|
+
}});
|
114
|
+
}});
|
115
|
+
}});
|
116
|
+
}});
|
117
|
+
}},
|
118
|
+
|
119
|
+
testAfterUpdateElement: function() { with(this) {
|
120
|
+
var ac = new Ajax.Autocompleter('ac2_input','ac2_update','_autocomplete_result.html',
|
121
|
+
{ method: 'get',
|
122
|
+
afterUpdateElement: function(element,selectedElement) {
|
123
|
+
element.value = 'afterupdate:' + selectedElement.tagName;
|
124
|
+
}
|
125
|
+
});
|
126
|
+
assertInstanceOf(Ajax.Autocompleter, ac);
|
127
|
+
|
128
|
+
Event.simulateMouse('ac2_input', 'click');
|
129
|
+
Event.simulateKeys('ac2_input','abcdefg');
|
130
|
+
|
131
|
+
wait(1000, function() { with(this) {
|
132
|
+
assertVisible('ac2_update');
|
133
|
+
Event.simulateKey('ac2_input','keypress',{keyCode:Event.KEY_TAB});
|
134
|
+
|
135
|
+
assertEqual('afterupdate:LI',$('ac2_input').value);
|
136
|
+
}});
|
137
|
+
}},
|
138
|
+
|
139
|
+
testTokenizing: function() { with(this) {
|
140
|
+
var actoken = new Ajax.Autocompleter('actoken_input','ac_update','_autocomplete_result.html',
|
141
|
+
{ tokens:',', method: 'get' });
|
142
|
+
assertInstanceOf(Ajax.Autocompleter, actoken);
|
143
|
+
|
144
|
+
Event.simulateKeys('actoken_input','abc');
|
145
|
+
|
146
|
+
wait(1000, function() { with(this) {
|
147
|
+
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_TAB});
|
148
|
+
assertEqual('test1',$('actoken_input').value);
|
149
|
+
Event.simulateKeys('actoken_input',',abc');
|
150
|
+
wait(1000, function() { with(this) {
|
151
|
+
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_DOWN});
|
152
|
+
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_TAB});
|
153
|
+
assertEqual('test1,test2',$('actoken_input').value);
|
154
|
+
// Simulating KEY_LEFT's prior to a 'b' doesn't work! So slightly ugly here...
|
155
|
+
$('actoken_input').value = 'test1b,test2';
|
156
|
+
actoken.onObserverEvent();
|
157
|
+
wait(1000, function() { with(this) {
|
158
|
+
for (var index = 0; index < 2; ++index)
|
159
|
+
Event.simulateKey('actoken_input', 'keypress', {keyCode: Event.KEY_DOWN});
|
160
|
+
Event.simulateKey('actoken_input', 'keypress', {keyCode: Event.KEY_TAB});
|
161
|
+
assertEqual('test3,test2', $('actoken_input').value);
|
162
|
+
}});
|
163
|
+
}});
|
164
|
+
}});
|
165
|
+
}},
|
166
|
+
|
167
|
+
// Same integration test, results has no linebreaks
|
168
|
+
testAjaxAutocompleterNoLinebreaksInResult: function() { with(this) {
|
169
|
+
var ac = new Ajax.Autocompleter('ac_input_br','ac_update_br','_autocomplete_result_nobr.html',
|
170
|
+
{ method: 'get' }); //override so we can use a static for the result
|
171
|
+
assertInstanceOf(Ajax.Autocompleter, ac);
|
172
|
+
|
173
|
+
// box not visible
|
174
|
+
assertNotVisible('ac_update_br');
|
175
|
+
|
176
|
+
// focus, but box not visible
|
177
|
+
Event.simulateMouse('ac_input_br', 'click');
|
178
|
+
assertNotVisible('ac_update_br');
|
179
|
+
|
180
|
+
Event.simulateKeys('ac_input_br','abcdefg');
|
181
|
+
assertEqual('abcdefg', $('ac_input_br').value);
|
182
|
+
|
183
|
+
// check box popping up on input
|
184
|
+
wait(1000, function() { with(this) {
|
185
|
+
assertVisible('ac_update_br');
|
186
|
+
assertEqual('test1', $('ac_update_br').firstChild.firstChild.innerHTML);
|
187
|
+
assertEqual('test2', $('ac_update_br').firstChild.firstChild.nextSibling.innerHTML);
|
188
|
+
|
189
|
+
// intl. characters return (UTF-8)
|
190
|
+
assertEqual('Here we have some international ©∏Á®Äç†∑rß', $('ac_update_br').firstChild.lastChild.innerHTML);
|
191
|
+
|
192
|
+
// first entry should be selected
|
193
|
+
assert(Element.hasClassName($('ac_update_br').firstChild.firstChild, 'selected'),'Selected item should have a className of: selected');
|
194
|
+
|
195
|
+
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_DOWN});
|
196
|
+
|
197
|
+
// second entry should be selected
|
198
|
+
assert(!Element.hasClassName($('ac_update_br').firstChild.firstChild),'Item shouldn\'t have a className of: selected');
|
199
|
+
assert(Element.hasClassName($('ac_update_br').firstChild.firstChild.nextSibling, 'selected'),'Second entry should have a className of: selected');
|
200
|
+
|
201
|
+
// check selecting with <TAB>
|
202
|
+
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_TAB});
|
203
|
+
assertEqual('test2',$('ac_input_br').value);
|
204
|
+
|
205
|
+
// check box going away
|
206
|
+
wait(500, function() { with(this) {
|
207
|
+
assertNotVisible('ac_update_br');
|
208
|
+
|
209
|
+
// check selecting with mouse click
|
210
|
+
Event.simulateKeys('ac_input_br','3');
|
211
|
+
assertEqual('test23', $('ac_input_br').value);
|
212
|
+
wait(1000, function() { with(this) {
|
213
|
+
assertVisible('ac_update_br');
|
214
|
+
Event.simulateMouse($('ac_update_br').firstChild.childNodes[4],'click');
|
215
|
+
|
216
|
+
wait(1000, function() { with(this) {
|
217
|
+
// tests if removal of 'informal' nodes and HTML escaping works
|
218
|
+
assertEqual('(GET <ME> INSTEAD)',$('ac_input_br').value);
|
219
|
+
assertNotVisible('ac_update_br');
|
220
|
+
|
221
|
+
// check cancelling with <ESC>
|
222
|
+
Event.simulateKeys('ac_input_br','abcdefg');
|
223
|
+
|
224
|
+
wait(1000, function() { with(this) {
|
225
|
+
assertVisible('ac_update_br');
|
226
|
+
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input_br').value);
|
227
|
+
|
228
|
+
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_DOWN});
|
229
|
+
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_ESC});
|
230
|
+
|
231
|
+
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input_br').value);
|
232
|
+
}});
|
233
|
+
}});
|
234
|
+
}});
|
235
|
+
}});
|
236
|
+
}});
|
237
|
+
}}
|
238
|
+
|
239
|
+
});
|
240
|
+
// ]]>
|
241
|
+
</script>
|
242
|
+
</body>
|
243
|
+
</html>
|