Debian Codegraph @

dijit/tests/layout/AccordionContainer.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Accordion Widget Automated Test</title>
6
7 <script src="../boilerplate.js"></script>
8
9 <script type="text/javascript">
10 require([
11 "doh/runner",
12 "dojo/_base/array", "dojo/data/ItemFileReadStore", "dojo/dom", "dojo/dom-geometry", "dojo/dom-style",
13 "dojo/parser", "dojo/query",
14 "dijit/registry", "dijit/layout/AccordionContainer", "dijit/layout/ContentPane", "dijit/_WidgetBase",
15 "dijit/Tree", "dijit/tree/ForestStoreModel", "dijit/form/Button", "dojo/domReady!"
16 ], function(doh, array, ItemFileReadStore, dom, domGeom, domStyle, parser, query,
17 registry, AccordionContainer, ContentPane, _WidgetBase){
18
19 // Data used by Tree in markup test
20 data = {
21 identifier: 'id',
22 label: 'name',
23 items: [
24 { id: 'AF', name:'Africa', type:'continent', population:'900 million', area: '30,221,532 sq km',
25 timezone: '-1 UTC to +4 UTC'},
26 { id: 'AS', name:'Asia', type:'continent' },
27 { id: 'OC', name:'Oceania', type:'continent', population:'21 million'},
28 { id: 'AU', name:'Australia', type:'country', population:'21 million'},
29 { id: 'EU', name:'Europe', type:'continent' },
30 { id: 'NA', name:'North America', type:'continent' },
31 { id: 'SA', name:'South America', type:'continent' }
32 ]
33 };
34
35 var accordion;
36
37 doh.register("basic",
38 [
39 {
40 name: "create",
41 runTest: function(t){
42 accordion = new AccordionContainer({style: "width: 400px; height: 400px;"}).placeAt(document.body);
43
44 array.forEach([ "pane 1", "pane 2", "pane 3" ], function(title, i){
45 var content = new ContentPane({id: title, title: title, selected: i==1});
46 content.containerNode.innerHTML = "this is " + title;
47 accordion.addChild(content);
48 });
49 accordion.startup();
50 var titles = query(".dijitAccordionText", accordion.domNode);
51 t.is(3, titles.length, "number of titles");
52 t.is("pane 3", titles[2].innerHTML);
53
54 var children = accordion.getChildren();
55 t.is(3, children.length, "number of children (ie, contentpanes)");
56 }
57 },
58 {
59 name: "initially open pane",
60 runTest: function(t){
61 // Pane 2 is initially open
62 var openPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
63 return node.parentNode.style.display != "none";
64 });
65 t.is(1, openPanes.length, "exactly one open pane");
66 t.is("pane 2", registry.byNode(openPanes[0]).title, "pane 2 is initially open");
67
68 // And others are closed
69 var closedPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
70 return node.parentNode.style.display == "none";
71 });
72 t.is(2, closedPanes.length, "n-1 closed panes");
73 }
74 },
75 {
76 name: "addChild at end",
77 runTest: function(t){
78 var pane4 = new ContentPane({title: "pane 4", content: "this is pane 4"});
79 accordion.addChild(pane4);
80
81 var titles = query(".dijitAccordionText", accordion.domNode);
82 t.is(4, titles.length, "number of titles");
83 t.is("pane 4", titles[3].innerHTML);
84
85 var children = accordion.getChildren();
86 t.is(4, children.length, "number of children (ie, contentpanes)");
87 t.is(pane4, children[3], "last child is the newly inserted one");
88 }
89 },
90 {
91 name: "addChild after pane 1",
92 runTest: function(t){
93 pane1half = new ContentPane({id: "pane1half", title: "pane 1.5", content: "this is pane 1.5"});
94 accordion.addChild(pane1half, 1);
95
96 var titles = query(".dijitAccordionText", accordion.domNode);
97 t.is(5, titles.length, "number of titles");
98 t.is("pane 1.5", titles[1].innerHTML);
99
100 var children = accordion.getChildren();
101 t.is(5, children.length, "number of children (ie, contentpanes)");
102 t.is(pane1half, children[1], "second child is the newly inserted one");
103 }
104 },
105 {
106 name: "removeChild(pane 1.5)",
107 runTest: function(t){
108 accordion.removeChild(registry.byId('pane1half'));
109
110 var titles = query(".dijitAccordionText", accordion.domNode);
111 t.is(4, titles.length, "number of titles");
112 t.is("pane 2", titles[1].innerHTML);
113
114 var children = accordion.getChildren();
115 t.is(4, children.length, "number of children (ie, contentpanes)");
116 t.is("pane 2", children[1].title, "second child is again 'pane 2'");
117
118 // spec is that removing a child shouldn't delete it
119 t.t(registry.byId("pane1half"), "child removed but still exists");
120 }
121 },
122 {
123 name: "initially open pane (checking again)",
124 runTest: function(t){
125 // Pane 2 is initially open
126 var openPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
127 return node.parentNode.style.display != "none";
128 });
129 t.is(1, openPanes.length, "exactly one open pane");
130 t.is("pane 2", registry.byNode(openPanes[0]).title, "pane 2 is initially open");
131
132 // And others are closed
133 var closedPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
134 return node.parentNode.style.display == "none";
135 });
136 t.is(3, closedPanes.length, "n-1 closed panes");
137 }
138 },
139 {
140 name: "select new pane",
141 runTest: function(t){
142 // Selecting pane 3 should open it and close pane 1
143
144 // select w/out animation
145 accordion.selectChild(registry.byId('pane 3'));
146
147 // Pane 3 is now open
148 var openPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
149 return node.parentNode.style.display != "none";
150 });
151 t.is(1, openPanes.length, "exactly one open pane");
152 t.is("pane 3", registry.byNode(openPanes[0]).title, "pane 3 is now open");
153
154 // And others are closed
155 var closedPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
156 return node.parentNode.style.display == "none";
157 });
158 t.is(3, closedPanes.length, "n-1 closed panes");
159 }
160 },
161 {
162 name: "select new pane with animation",
163 timeout: 3000,
164 setUp: function(t){
165 // Note that this kicks off an animation so it might be a while before the
166 // bottom setTimeout() fires, likely longer than the 300ms specified
167 accordion.selectChild(registry.byId('pane 2'), true);
168 },
169 runTest: function(t){
170 // Selecting pane 2 should open it and close pane 3
171 var d = new doh.Deferred();
172 setTimeout(d.getTestCallback(function(){
173 // Pane 2 is now open
174 var openPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
175 return node.parentNode.style.display != "none";
176 });
177 t.is(1, openPanes.length, "exactly one open pane");
178 t.is("pane 2", registry.byNode(openPanes[0]).title, "pane 3 is now open");
179
180 // And others are closed
181 var closedPanes = query(".dijitAccordionChildWrapper > *", accordion.containerNode).filter(function(node){
182 return node.parentNode.style.display == "none";
183 });
184 t.is(3, closedPanes.length, "n-1 closed panes");
185 }), 300);
186 return d;
187 }
188 },
189 {
190 name: "destroy recursive",
191 runTest: function(t){
192 accordion.destroyRecursive();
193 t.is(1, registry.toArray().length, "accordion and subwidgets destroyed, pane1half remains");
194 }
195 }
196 ]
197 );
198
199 doh.register("child events", function childEvents(t){
200 accordion = new AccordionContainer({style: "width: 400px; height: 400px;"}).placeAt(document.body);
201
202 array.forEach([ "a", "b", "c" ], function(title, i){
203 var content = new ContentPane({id: title, title: title, selected: i==1});
204 content.containerNode.innerHTML = "this is " + title;
205 accordion.addChild(content);
206 });
207 accordion.startup();
208
209 // Change title of a pane, should change corresponding button label
210 registry.byId("b").set("title", "b changed");
211 var titles = query(".dijitAccordionText", accordion.domNode);
212 t.is(3, titles.length, "number of titles");
213 t.is("b changed", titles[1].innerHTML);
214
215 // Change tooltip of a pane, should change corresponding button tooltip
216 registry.byId("c").set("tooltip", "c tooltip changed");
217 titles = query(".dijitAccordionText", accordion.domNode);
218 t.is(3, titles.length, "number of titles");
219 t.is("c tooltip changed", titles[2].title);
220 });
221
222 doh.register("zero children",
223 [
224 {
225 name: "create w/no children",
226 runTest: function(t){
227 accordion = new AccordionContainer({style: "width: 400px; height: 400px;"}).placeAt(document.body);
228 accordion.startup();
229 var children = accordion.getChildren();
230 t.is(0, children.length, "no children");
231 accordion.resize();
232 t.t(true, "resize ran w/out exception");
233 }
234 },
235 {
236 name: "add children",
237 runTest: function(t){
238 array.forEach([ "pane 10", "pane 11"], function(title, i){
239 var content = new ContentPane({id: title, title: title});
240 content.containerNode.innerHTML = "this is " + title;
241 accordion.addChild(content);
242 });
243 var children = accordion.getChildren();
244 t.is(2, children.length, "2 children");
245 }
246 },
247 {
248 name: "remove all children",
249 runTest: function(t){
250 var pane10 = registry.byId("pane 10"),
251 pane11 = registry.byId("pane 11");
252
253 t.is(pane10, accordion.selectedChildWidget, "pane 10 initially selected");
254
255 accordion.removeChild(pane10);
256 t.is(pane11, accordion.selectedChildWidget, "after pane 10 removed, pane 11 selected");
257
258 accordion.removeChild(pane11);
259 t.f(accordion.selectedChildWidget, "after pane 11 removed, no pane selected");
260 var children = accordion.getChildren();
261 t.is(0, children.length, "all children removed");
262 }
263 },
264 {
265 name: "add back children",
266 runTest: function(t){
267 array.forEach([ "pane 12", "pane 13"], function(title, i){
268 var content = new ContentPane({id: title, title: title});
269 content.containerNode.innerHTML = "this is " + title;
270 accordion.addChild(content);
271 });
272
273 var children = accordion.getChildren();
274 t.is(2, children.length, "two new children");
275 t.is(registry.byId("pane 12"), accordion.selectedChildWidget, "pane 12 selected");
276 }
277 }
278 ]
279 );
280
281 // This section tests that the animation doesn't leave residual height=... settings on the
282 // node that interfere with future operations
283 doh.register("animation",
284 [
285 {
286 name: "create",
287 runTest: function(t){
288 accordion = new AccordionContainer({style: "width: 400px; height: 400px;"}).placeAt(document.body);
289
290 array.forEach([ "pane 1", "pane 2", "pane 3" ], function(title, i){
291 var content = new ContentPane({id: title, title: title, selected: i==1});
292 content.containerNode.innerHTML = "this is " + title;
293 accordion.addChild(content);
294 });
295 accordion.startup();
296
297 // make sure size of selected child is correct
298 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h > 300, "child height > 300");
299 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h < 400, "child height < 400");
300 doh.is(domGeom.getMarginBox(accordion.selectedChildWidget.domNode).h,
301 domGeom.getContentBox(accordion.selectedChildWidget._wrapperWidget.containerNode).h, "child height vs. wrapper height")
302 }
303 },
304 {
305 name: "select new pane with animation",
306 timeout: 3000,
307 setUp: function(t){
308 // Note that this kicks off an animation so it might be a while before the
309 // bottom setTimeout() fires, likely longer than the 300ms specified
310 accordion.selectChild(registry.byId('pane 2'), true);
311 },
312 runTest: function(t){
313 // Selecting pane 2 should open it and close pane 3
314 var d = new doh.Deferred();
315 setTimeout(d.getTestCallback(function(){
316 doh.is("pane 2", accordion.selectedChildWidget.title);
317
318 // make sure size of selected child is correct
319 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h > 300, "child height > 300");
320 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h < 400, "child height < 400");
321 doh.is(domGeom.getMarginBox(accordion.selectedChildWidget.domNode).h, domGeom.getContentBox(accordion.selectedChildWidget._wrapperWidget.containerNode).h, "child height vs. wrapper height")
322 }), 300);
323 return d;
324 }
325 },
326
327 // Make sure that the animation didn't leave a residual height: 1px that affect
328 // pane #1 when it is reselected w/out an animation
329 {
330 name: "remove pane #2, reselecting pane #1",
331 runTest: function(t){
332 accordion.removeChild(registry.byId("pane 2"));
333
334 doh.is("pane 1", accordion.selectedChildWidget.title);
335
336 // make sure size of selected child is correct
337 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h > 300, "child height > 300");
338 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h < 400, "child height < 400");
339 doh.is(domGeom.getMarginBox(accordion.selectedChildWidget.domNode).h, domGeom.getContentBox(accordion.selectedChildWidget._wrapperWidget.containerNode).h, "child height vs. wrapper height")
340 }
341 },
342 {
343 name: "select pane #3 with animation",
344 timeout: 3000,
345 setUp: function(t){
346 // Note that this kicks off an animation so it might be a while before the
347 // bottom setTimeout() fires, likely longer than the 300ms specified
348 accordion.selectChild(registry.byId('pane 3'), true);
349 },
350 runTest: function(t){
351 // Selecting pane 2 should open it and close pane 3
352 var d = new doh.Deferred();
353 setTimeout(d.getTestCallback(function(){
354 doh.is("pane 3", accordion.selectedChildWidget.title);
355
356 // make sure size of selected child is correct
357 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h > 300, "child height > 300");
358 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h < 400, "child height < 400");
359 doh.is(domGeom.getMarginBox(accordion.selectedChildWidget.domNode).h, domGeom.getContentBox(accordion.selectedChildWidget._wrapperWidget.containerNode).h, "child height vs. wrapper height")
360 }), 300);
361 return d;
362 }
363 },
364
365 // Make sure that the wipe-in animation didn't leave a residual height: 300px type
366 // setting that will interfere with resizing
367 {
368 name: "resize",
369 timeout: 3000,
370 runTest: function(t){
371 accordion.resize({h: 200});
372
373 // make sure size of selected child is correct
374 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h > 100, "child height > 150");
375 doh.t(domGeom.position(accordion.selectedChildWidget.domNode).h < 200, "child height < 200");
376 doh.is(domGeom.getMarginBox(accordion.selectedChildWidget.domNode).h, domGeom.getContentBox(accordion.selectedChildWidget._wrapperWidget.containerNode).h, "child height vs. wrapper height")
377 }
378 }
379 ]
380 );
381
382 doh.register("destroy", [
383 function setUp(){
384 accPane = new ContentPane({
385 id: "accPane",
386 onContentError: function(msg){
387 throw new Error(msg);
388 }
389 });
390 accPane.placeAt(document.body);
391 html='<div data-dojo-type="dijit/layout/AccordionContainer" id="Accordion" style="height: 300px;">' +
392 '<div data-dojo-type="dijit/layout/ContentPane" title="first" id="first">' +
393 '<div data-dojo-type=dijit/form/Button id=myButton>hello world</div></div>' +
394 '<div data-dojo-type="dijit/layout/ContentPane" title="second" id="second">second</div>' +
395 '</div>';
396 },
397
398 function destroyUnstarted(){
399 // Since the wrapper ContentPane hasn't been started yet, the Accordion won't be started, and wrapper
400 // (AccordionInnerContainer) widgets won't be created...
401 accPane.set("content", html);
402 doh.t(dom.byId("Accordion"), "accordion created #1");
403 accPane.set("content", html); //setting the content twice will initiate a destroy
404 registry.byId("Accordion").destroy();
405 doh.is(undefined, dom.byId("Accordion"), "accordion destroyed #1");
406 },
407
408 function destroyStarted(){
409 // Try same tests again when wrapper ContentPane is started
410 accPane.startup();
411
412 accPane.set("content", html);
413 doh.t(dom.byId("Accordion"), "accordion created #2");
414 accPane.set("content", html); //setting the content twice will initiate a destroy
415 registry.byId("Accordion").destroy();
416 doh.is(undefined, dom.byId("Accordion"), "accordion destroyed #2");
417 }
418 ]);
419
420 doh.register("markup", [
421 {
422 name: "create",
423 runTest: function(t){
424 parser.parse();
425
426 accordion = registry.byId("markupAccordion");
427
428 var titles = query(".dijitAccordionText", accordion.domNode);
429 t.is(3, titles.length, "number of titles");
430 t.is("Other Lazy Load Pane", titles[2].innerHTML);
431
432 var children = accordion.getChildren();
433 t.is(3, children.length, "number of children (ie, contentpanes)");
434 }
435 },
436 {
437 name: "addChild after pane 1",
438 runTest: function(t){
439 pane1half = new ContentPane({id: "otherPane1half", title: "pane 1.5", content: "this is pane 1.5"});
440 accordion.addChild(pane1half, 1);
441
442 var titles = query(".dijitAccordionText", accordion.domNode);
443 t.is(4, titles.length, "number of titles");
444 t.is("pane 1.5", titles[1].innerHTML);
445
446 var children = accordion.getChildren();
447 t.is(4, children.length, "number of children (ie, contentpanes)");
448 t.is(pane1half, children[1], "second child is the newly inserted one");
449 }
450 }
451 ]);
452
453 doh.register("resize", [
454 {
455 name: "no resize() method",
456 runTest: function(t){
457 accordion = new AccordionContainer({style: "width: 400px; height: 400px;"}).placeAt(document.body);
458
459 var child = new _WidgetBase({
460 id: "no resize",
461 title: "No Resize"
462 });
463 accordion.addChild(child);
464 accordion.startup();
465 t.t(domStyle.get(child.domNode, "height") > 300, "child resized");
466 }
467 }
468 ]);
469
470 doh.run();
471 });
472 </script>
473 </head>
474 <body class="claro" style="padding: 50px;" role="main">
475
476 <h1 class="testTitle">AccordionContainer Automated Tests</h1>
477
478 <h2 class="testTitle">Markup Accordion</h2>
479
480 <div data-dojo-type="dojo/data/ItemFileReadStore" data-dojo-id="continentStore" data="data"></div>
481 <div data-dojo-type="dijit/tree/ForestStoreModel" data-dojo-id="continentModel"
482 store="continentStore" query="{type:'continent'}"
483 rootId="continentRoot" rootLabel="Continents" childrenAttrs="children">
484 </div>
485
486
487 <div id="markupAccordion" data-dojo-type="dijit/layout/AccordionContainer"
488 data-dojo-props='style:"width: 400px; height: 300px; overflow: hidden"'>
489 <div id="pane1" data-dojo-type="dijit/Tree" model="continentModel" data-dojo-props='selected:true,
490 title:"Tree Pane", iconClass:"dijitEditorIcon dijitEditorIconSave", tooltip:"tooltip for simple pane"'>
491 </div>
492
493 <!-- test lazy loading. margin style for testing size calculations. -->
494 <div id="lazyLoadPane1" data-dojo-type="dijit/layout/ContentPane"
495 data-dojo-props='title:"Lazy Load Pane", href:"doc1.html"'></div>
496
497 <!-- test lazy loading. margin style for testing size calculations. -->
498 <div id="lazyLoadPane2" data-dojo-type="dijit/layout/ContentPane"
499 data-dojo-props='title:"Other Lazy Load Pane", href:"doc1.html"'></div>
500
501 </div>
502
503 <h2 class="testTitle">Programmatic Accordions</h2>
504
505 </body>
506 </html>