Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 274 lines (235 sloc) 10.395 kb
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
1 <html>
2 <head>
3 <script type="text/javascript" src="Test/Builder.js"></script>
4 <script type="text/javascript" src="Test/More.js"></script>
5 <script type="text/javascript" src="../MochiKit/Base.js"></script>
6 <script type="text/javascript" src="../MochiKit/Iter.js"></script>
7 <script type="text/javascript" src="../MochiKit/DOM.js"></script>
8 </head>
9 <body>
10
a5e2ee4 Bob Ippolito fix radio
etrepum authored
11 <div style="display: none;">
12 <form id="form_test">
13 <select name="select">
a8f9d43 Bob Ippolito #33 fix test
etrepum authored
14 <option value="foo" selected="selected">foo</option>
a5e2ee4 Bob Ippolito fix radio
etrepum authored
15 <option value="bar">bar</option>
16 <option value="baz">baz</option>
17 </select>
18 <input type="hidden" name="hidden" value="test" />
19 <input type="radio" name="radio_off" value="1" />
20 <input type="radio" name="radio_off" value="2" />
21 <input type="radio" name="radio_off" value="3" />
22 <input type="radio" name="radio_on" value="1" />
23 <input type="radio" name="radio_on" value="2" checked="checked" />
24 <input type="radio" name="radio_on" value="3" />
25 </form>
26 </div>
27
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
28 <pre id="test">
29 <script type="text/javascript">
30 try {
31
32 // Counting the number of tests is really lame
e17cfa8 Bob Ippolito fix #15 (in-order scrapeText walk, STRONG)
etrepum authored
33 plan({'tests': 66});
4e87513 Bob Ippolito add an array fast-path to forEach
etrepum authored
34
35 lst = [];
36 o = {"blah": function () { lst.push("original"); }};
37 addToCallStack(o, "blah", function () { lst.push("new"); }, true);
292b21f Bob Ippolito add sortable tables example
etrepum authored
38 addToCallStack(o, "blah", function () { lst.push("stuff"); }, true);
4e87513 Bob Ippolito add an array fast-path to forEach
etrepum authored
39 is( typeof(o.blah), 'function', 'addToCallStack has a function' );
40 is( o.blah.callStack.length, 3, 'callStack length 3' );
41 o.blah();
292b21f Bob Ippolito add sortable tables example
etrepum authored
42 is( lst.join(" "), "original new stuff", "callStack in correct order" );
4e87513 Bob Ippolito add an array fast-path to forEach
etrepum authored
43 is( o.blah, null, "set to null" );
4e77133 Bob Ippolito add "false" to break out of call stacks
etrepum authored
44 lst = [];
45 o = {"blah": function () { lst.push("original"); }};
46 addToCallStack(o, "blah",
47 function () { lst.push("new"); return false;}, false);
48 addToCallStack(o, "blah", function () { lst.push("stuff"); }, false);
49 o.blah();
50 is( lst.join(" "), "original new", "callStack in correct order (abort)" );
51 o.blah();
52 is( lst.join(" "), "original new original new", "callStack in correct order (again)" );
53
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
54
0db1108 Bob Ippolito actually fix the test
etrepum authored
55 is( escapeHTML("<>\"&bar"), "&lt;&gt;&quot;&amp;bar", "escapeHTML" ); // for emacs highlighting: "
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
56
a06c083 Bob Ippolito add arg checking for reduce, attribute filter for emitHTML
etrepum authored
57 var isDOM = function (value, expected, message) {
58 is( escapeHTML(toHTML(value)), escapeHTML(expected), message );
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
59 }
60
6ba9bc9 Bob Ippolito Added updateNodeAttributes, appendChildNodes, replaceChildNodes to
etrepum authored
61 var d = document.createElement('span');
62 updateNodeAttributes(d, {"foo": "bar", "baz": "wibble"});
63 isDOM( d, '<span baz="wibble" foo="bar"/>', "updateNodeAttributes" );
64
65 var d = document.createElement('span');
68f57cc Bob Ippolito copout
etrepum authored
66 appendChildNodes(d, 'word up', [document.createElement('span')]);
67 isDOM( d, '<span>word up<span/></span>', 'appendChildNodes' );
6ba9bc9 Bob Ippolito Added updateNodeAttributes, appendChildNodes, replaceChildNodes to
etrepum authored
68
69 replaceChildNodes(d, 'Think Different');
70 isDOM( d, '<span>Think Different</span>', 'replaceChildNodes' );
71
72 d = createDOM("span");
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
73 isDOM( d, "<span/>", "createDOM empty" );
74
75
76 d = createDOM("span", {"foo": "bar", "baz": "wibble"});
77 isDOM( d, '<span baz="wibble" foo="bar"/>', "createDOM attributes" );
78
79 d = createDOM("span", {"foo": "bar", "baz": "wibble"}, "one", "two", "three");
4e87513 Bob Ippolito add an array fast-path to forEach
etrepum authored
80 toHTML(d);
81
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
82 isDOM( d, '<span baz="wibble" foo="bar">onetwothree</span>', "createDOM contents" );
83
84 var d = {"taco": "pork"};
85 registerDOMConverter("taco",
86 function (o) { return !isUndefinedOrNull(o.taco); },
87 function (o) { return "Goddamn, I like " + o.taco + " tacos"; }
88 );
89 d = createDOM("span", null, d);
03938b3 Bob Ippolito JSAN/namespace action
etrepum authored
90 // not yet public API
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
91 domConverters.unregister("taco");
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
92
93 isDOM( d, "<span>Goddamn, I like pork tacos</span>", "createDOM with custom converter" );
292b21f Bob Ippolito add sortable tables example
etrepum authored
94
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
95 is(
96 escapeHTML(toHTML(SPAN(null))),
97 escapeHTML(toHTML(createDOM("span", null))),
98 "createDOMFunc vs createDOM"
99 );
100
1509507 Bob Ippolito - sendXMLHttpRequest and functions that use it (loadJSONDoc, etc.) no lo...
etrepum authored
101 is( scrapeText(d), "Goddamn, I like pork tacos", "scrape OK" );
102 is( scrapeText(d, true).join(""), "Goddamn, I like pork tacos", "scrape Array OK" );
292b21f Bob Ippolito add sortable tables example
etrepum authored
103
e17cfa8 Bob Ippolito fix #15 (in-order scrapeText walk, STRONG)
etrepum authored
104 var st = DIV(null, STRONG(null, "d"), "oor ", STRONG(null, "f", SPAN(null, "r"), "a"), "me");
105 is( scrapeText(st), "door frame", "scrape in-order" );
106
107
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
108 ok( !isUndefinedOrNull(getElement("test")), "getElement might work" );
109 ok( !isUndefinedOrNull($("test")), "$alias$$ CASH MONEY alias might work" );
110
111 d = createDOM("span", null, "one", "two");
112 swapDOM(d.childNodes[0], document.createTextNode("uno"));
113 isDOM( d, "<span>unotwo</span>", "swapDOM" );
114
1509507 Bob Ippolito - sendXMLHttpRequest and functions that use it (loadJSONDoc, etc.) no lo...
etrepum authored
115 is( scrapeText(d, true).join(" "), "uno two", "multi-node scrapeText" );
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
116 /*
117
118 TODO:
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
119 addLoadEvent (async test?)
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
120
121 */
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
122
123 d = createDOM("span", {"class": "foo"});
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
124 setElementClass(d, "bar baz");
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
125 ok( d.className == "bar baz", "setElementClass");
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
126 toggleElementClass("bar", d);
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
127 ok( d.className == "baz", "toggleElementClass: " + d.className);
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
128 toggleElementClass("bar", d);
129 ok( hasElementClass(d, "baz", "bar"),
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
130 "toggleElementClass 2: " + d.className);
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
131 addElementClass(d, "bar");
132 ok( hasElementClass(d, "baz", "bar"),
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
133 "toggleElementClass 3: " + d.className);
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
134 ok( addElementClass(d, "blah"), "addElementClass return");
135 ok( hasElementClass(d, "baz", "bar", "blah"), "addElementClass action");
136 ok( !hasElementClass(d, "not"), "hasElementClass single");
137 ok( !hasElementClass(d, "baz", "not"), "hasElementClass multiple");
138 ok( removeElementClass(d, "blah"), "removeElementClass" );
139 ok( !removeElementClass(d, "blah"), "removeElementClass again" );
140 ok( !hasElementClass(d, "blah"), "removeElementClass again (hasElement)" );
141 removeElementClass(d, "baz");
142 ok( !swapElementClass(d, "blah", "baz"), "false swapElementClass" );
143 ok( !hasElementClass(d, "baz"), "false swapElementClass from" );
144 ok( !hasElementClass(d, "blah"), "false swapElementClass to" );
145 addElementClass(d, "blah");
146 ok( swapElementClass(d, "blah", "baz"), "swapElementClass" );
147 ok( hasElementClass(d, "baz"), "swapElementClass has toClass" );
148 ok( !hasElementClass(d, "blah"), "swapElementClass !has fromClass" );
149 ok( !swapElementClass(d, "blah", "baz"), "swapElementClass twice" );
150 ok( hasElementClass(d, "baz"), "swapElementClass has toClass" );
151 ok( !hasElementClass(d, "blah"), "swapElementClass !has fromClass" );
152
153 TABLE;
154 TBODY;
155 TR;
156 var t = TABLE(null,
157 TBODY({"class": "foo bar", "id":"tbody0"},
158 TR({"class": "foo", "id":"tr0"}),
159 TR({"class": "bar", "id":"tr1"})
160 )
161 );
daebb56 Bob Ippolito addElementClass fix, tests and new hasElementClass from Ian Bicking.
etrepum authored
162
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
163 var matchElements = getElementsByTagAndClassName;
164 is(
165 map(itemgetter("id"), matchElements(null, "foo", t)).join(" "),
166 "tbody0 tr0",
167 "getElementsByTagAndClassName found all tags with foo class"
168 );
169 is(
170 map(itemgetter("id"), matchElements("tr", "foo", t)).join(" "),
171 "tr0",
172 "getElementsByTagAndClassName found all tr tags with foo class"
173 );
174 is(
175 map(itemgetter("id"), matchElements("tr", null, t)).join(" "),
176 "tr0 tr1",
177 "getElementsByTagAndClassName found all tr tags"
178 );
179
1d56b7f Bob Ippolito DOM context
etrepum authored
180 var MockElement = function (name, data) {
181 this.nodeName = name.toUpperCase();
182 if (typeof(data) == "string") {
183 this.nodeValue = data;
184 this.nodeType = 3;
185 } else {
186 this.nodeType = 1;
9d1db18 Bob Ippolito formContents and queryString enhancements
etrepum authored
187 this.childNodes = [];
1d56b7f Bob Ippolito DOM context
etrepum authored
188 }
189 }
190 MockElement.prototype = {
191 createElement: function (nodeName) { return new MockElement(nodeName); },
192 createTextNode: function (text) { return new MockElement("text", text); },
9d1db18 Bob Ippolito formContents and queryString enhancements
etrepum authored
193 setAttribute: function (name, value) { this[name] = value; },
194 getAttribute: function (name) { return this[name]; },
195 appendChild: function (child) { this.childNodes.push(child); },
1d56b7f Bob Ippolito DOM context
etrepum authored
196 toString: function () { return "MockElement(" + this.nodeName + ")"; }
197 };
198
199 var oldDoc = document;
200 var doc = new MockElement("DOCUMENT");
201 doc.body = new MockElement("BODY");
202 doc.appendChild(doc.body);
203 is( currentDocument(), document, "currentDocument() correct" );
204 withDocument(doc, function () {
205 ok( document != doc, "global doc unchanged" );
206 is( currentDocument(), doc, "currentDocument() correct" );
207 var h1 = H1();
208 var span = SPAN(null, "foo", h1);
209 appendChildNodes(currentDocument().body, span);
210 });
211 is( document, oldDoc, "doc restored" );
9d1db18 Bob Ippolito formContents and queryString enhancements
etrepum authored
212 is( doc.childNodes.length, 1, "doc has one child" );
213 is( doc.body.childNodes.length, 1, "body has one child" );
214 var sp = doc.body.childNodes[0];
1d56b7f Bob Ippolito DOM context
etrepum authored
215 is( sp.nodeName, "SPAN", "only child is SPAN" );
9d1db18 Bob Ippolito formContents and queryString enhancements
etrepum authored
216 is( sp.childNodes.length, 2, "SPAN has two childNodes" );
217 is( sp.childNodes[0].nodeValue, "foo", "first node is text" );
218 is( sp.childNodes[1].nodeName, "H1", "second child is H1" );
1d56b7f Bob Ippolito DOM context
etrepum authored
219
220 is( currentDocument(), document, "currentDocument() correct" );
221 try {
222 withDocument(doc, function () {
223 ok( document != doc, "global doc unchanged" );
224 is( currentDocument(), doc, "currentDocument() correct" );
ea9ef0b Bob Ippolito IE tweak?
etrepum authored
225 throw new Error("foo");
1d56b7f Bob Ippolito DOM context
etrepum authored
226 });
227 ok( false, "didn't throw" );
228 } catch (e) {
229 ok( true, "threw" );
230 }
9d1db18 Bob Ippolito formContents and queryString enhancements
etrepum authored
231
232 doc = new MockElement("DOCUMENT");
233 doc.body = new MockElement("BODY");
234 doc.appendChild(doc.body);
235 var frm;
236 withDocument(doc, function () {
237 frm = FORM(null,
238 INPUT({name:"foo", value:"bar"}),
239 INPUT({name:"foo", value:"bar"}),
240 INPUT({name:"baz", value:"bar"})
241 );
242 });
243 var kv = formContents(frm);
a5e2ee4 Bob Ippolito fix radio
etrepum authored
244 is( kv[0].join(","), "foo,foo,baz", "mock formContents names" );
245 is( kv[1].join(","), "bar,bar,bar", "mock formContents values" );
246 is( queryString(frm), "foo=bar&foo=bar&baz=bar", "mock queryString hook" );
247
248 var kv = formContents("form_test");
249 is( kv[0].join(","), "select,hidden,radio_on", "formContents names" );
250 is( kv[1].join(","), "foo,test,2", "formContents values" );
251 is( queryString("form_test"), "select=foo&hidden=test&radio_on=2", "queryString hook" );
9742f53 Bob Ippolito - Beefed up the MochiKit.DOM test suite
etrepum authored
252
fd638aa SVM: skipping changes 0-2 for http://svn.red-bean.com/mochikit
svm authored
253 ok( true, "test suite finished!");
254
255 } catch (err) {
256
257 var s = "test suite failure!\n";
258 var o = {};
259 var k = null;
260 for (k in err) {
261 // ensure unique keys?!
262 if (!o[k]) {
263 s += k + ": " + err[k] + "\n";
264 o[k] = err[k];
265 }
266 }
267 ok ( false, s );
268
269 }
270 </script>
271 </pre>
272 </body>
273 </html>
Something went wrong with that request. Please try again.