1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | |
---|
5 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
---|
6 | |
---|
7 | <title>Container</title> |
---|
8 | |
---|
9 | <script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="isDebug: true"></script> |
---|
10 | <script type="text/javascript"> |
---|
11 | require([ |
---|
12 | "doh/runner", |
---|
13 | "dojo/_base/declare", "dojo/dom", "dojo/parser", |
---|
14 | "dijit/a11y", "dijit/focus", "dijit/registry", "dijit/_WidgetBase", "dijit/_Container", "dijit/_Contained", |
---|
15 | "dijit/tests/helpers", "dojo/domReady!" |
---|
16 | ], function(doh, declare, dom, parser, a11y, focus, registry, _WidgetBase, _Container, _Contained, helpers){ |
---|
17 | |
---|
18 | declare("TestContainer", |
---|
19 | [_WidgetBase, _Container], { } |
---|
20 | ); |
---|
21 | |
---|
22 | declare("TestContained", |
---|
23 | [_WidgetBase, _Contained], {} |
---|
24 | ); |
---|
25 | |
---|
26 | doh.register("parse", function(){ |
---|
27 | parser.parse(); |
---|
28 | }); |
---|
29 | |
---|
30 | doh.register("basic tests", [ |
---|
31 | { |
---|
32 | name: "getChildren", |
---|
33 | runTest: function(t){ |
---|
34 | var c = registry.byId("container"); |
---|
35 | var children = c.getChildren(); |
---|
36 | t.is(4, children.length); |
---|
37 | t.is("zero", children[0].id); |
---|
38 | t.is("one", children[1].id); |
---|
39 | t.is("two", children[2].id); |
---|
40 | t.is("three", children[3].id); |
---|
41 | } |
---|
42 | }, |
---|
43 | { |
---|
44 | name: "_getSiblingOfChild", |
---|
45 | runTest: function(t){ |
---|
46 | var c = registry.byId("container"); |
---|
47 | var children = c.getChildren(); |
---|
48 | t.is("one", c._getSiblingOfChild(children[0], 1).id); |
---|
49 | t.is("two", c._getSiblingOfChild(children[1], 1).id); |
---|
50 | t.is("three", c._getSiblingOfChild(children[2], 1).id); |
---|
51 | t.is(null, c._getSiblingOfChild(children[3], 1)); |
---|
52 | t.is(null, c._getSiblingOfChild(children[0], -1)); |
---|
53 | t.is("zero", c._getSiblingOfChild(children[1], -1).id); |
---|
54 | t.is("one", c._getSiblingOfChild(children[2], -1).id); |
---|
55 | t.is("two", c._getSiblingOfChild(children[3], -1).id); |
---|
56 | } |
---|
57 | }, |
---|
58 | { |
---|
59 | name: "getIndexOfChild", |
---|
60 | runTest: function(t){ |
---|
61 | var c = registry.byId("container"); |
---|
62 | t.is(0, c.getIndexOfChild(registry.byId("zero"))); |
---|
63 | t.is(1, c.getIndexOfChild(registry.byId("one"))); |
---|
64 | t.is(2, c.getIndexOfChild(registry.byId("two"))); |
---|
65 | t.is(3, c.getIndexOfChild(registry.byId("three"))); |
---|
66 | t.is(-1, c.getIndexOfChild(registry.byId("outside"))); |
---|
67 | t.is(-1, c.getIndexOfChild(registry.byId("outsideCont"))); |
---|
68 | } |
---|
69 | }, |
---|
70 | { |
---|
71 | name: "getIndexInParent", |
---|
72 | runTest: function(t){ |
---|
73 | t.is(0, registry.byId("zero").getIndexInParent()); |
---|
74 | t.is(1, registry.byId("one").getIndexInParent()); |
---|
75 | t.is(2, registry.byId("two").getIndexInParent()); |
---|
76 | t.is(-1, registry.byId("outsideCont").getIndexInParent()); |
---|
77 | } |
---|
78 | }, |
---|
79 | { |
---|
80 | name: "removeChild", |
---|
81 | runTest: function(t){ |
---|
82 | var c = registry.byId("container"); |
---|
83 | var children = c.getChildren(); |
---|
84 | t.is(4, children.length); |
---|
85 | c.removeChild(registry.byId("zero")); |
---|
86 | c.removeChild(1); // should remove "two" - because zero is already removed |
---|
87 | children = c.getChildren(); |
---|
88 | t.is(2, children.length); |
---|
89 | t.is("one", children[0].id); |
---|
90 | t.is("three", children[1].id); |
---|
91 | } |
---|
92 | }, |
---|
93 | { |
---|
94 | name: "addChild", |
---|
95 | runTest: function(t){ |
---|
96 | var c = registry.byId("container"); |
---|
97 | |
---|
98 | // Add child at beginning |
---|
99 | c.addChild(registry.byId("zero"), 0); |
---|
100 | children = c.getChildren(); |
---|
101 | t.is(3, children.length); |
---|
102 | t.is("zero", children[0].id, "after addChild(zero), zero"); |
---|
103 | t.is("one", children[1].id, "after addChild(zero), one"); |
---|
104 | t.is("three", children[2].id, "after addChild(zero), three"); |
---|
105 | |
---|
106 | // Add child in middle |
---|
107 | c.addChild(registry.byId("two"), 2); |
---|
108 | children = c.getChildren(); |
---|
109 | t.is(4, children.length); |
---|
110 | t.is("zero", children[0].id, "after addChild(two), zero"); |
---|
111 | t.is("one", children[1].id, "after addChild(two), one"); |
---|
112 | t.is("two", children[2].id, "after addChild(two), two"); |
---|
113 | t.is("three", children[3].id, "after addChild(two), three"); |
---|
114 | |
---|
115 | // Add child at end |
---|
116 | c.addChild(new TestContained({id: "four"})); |
---|
117 | children = c.getChildren(); |
---|
118 | t.is(5, children.length); |
---|
119 | t.is("zero", children[0].id, "after addChild(four), zero"); |
---|
120 | t.is("one", children[1].id, "after addChild(four), one"); |
---|
121 | t.is("two", children[2].id, "after addChild(four), two"); |
---|
122 | t.is("three", children[3].id, "after addChild(four), three"); |
---|
123 | t.is("four", children[4].id, "after addChild(four), four"); |
---|
124 | |
---|
125 | // Add child at end with explicit position specified |
---|
126 | c.addChild(new TestContained({id: "five"}), 5); |
---|
127 | children = c.getChildren(); |
---|
128 | t.is(6, children.length); |
---|
129 | t.is("zero", children[0].id, "after addChild(five), zero"); |
---|
130 | t.is("one", children[1].id, "after addChild(five), one"); |
---|
131 | t.is("two", children[2].id, "after addChild(five), two"); |
---|
132 | t.is("three", children[3].id, "after addChild(five), three"); |
---|
133 | t.is("four", children[4].id, "after addChild(five), four"); |
---|
134 | t.is("five", children[5].id, "after addChild(five), five"); |
---|
135 | } |
---|
136 | } |
---|
137 | ]); |
---|
138 | |
---|
139 | doh.run(); |
---|
140 | }); |
---|
141 | |
---|
142 | </script> |
---|
143 | </head> |
---|
144 | <body class="claro"> |
---|
145 | |
---|
146 | <label for="input">before:</label><input id="input"/> |
---|
147 | <div id="container" data-dojo-type="TestContainer"> |
---|
148 | <!-- comment just to make sure that numbering isn't thrown off --> |
---|
149 | <div id="zero" data-dojo-type="TestContained"></div> |
---|
150 | <div id="one" data-dojo-type="TestContained"></div> |
---|
151 | <div id="two" data-dojo-type="TestContained"></div> |
---|
152 | <div id="three" data-dojo-type="dijit/_WidgetBase"></div> |
---|
153 | </div> |
---|
154 | <div id="outside" data-dojo-type="dijit/_WidgetBase"></div> |
---|
155 | <div id="outsideCont" data-dojo-type="TestContained"></div> |
---|
156 | </body> |
---|
157 | </html> |
---|