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