Debian Codegraph @

dijit/tests/tree/robot/Tree_mouse.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>robot Tree Mouse Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
12
13 <script type="text/javascript">
14 require([
15 "doh/runner", "dojo/robotx",
16 "dojo/aspect", "dojo/query",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, aspect, query, helpers){
19
20 robot.initRobot('../test_Tree.html');
21
22 var registry, focus, mytree, africa, asia;
23
24 doh.register("_setup", [
25 {
26 name: "wait for widgets to load",
27 timeout: 20000,
28 runTest: helpers.waitForLoad
29 },
30 function setVars(){
31 registry = robot.window.require("dijit/registry");
32 focus = robot.window.require("dijit/focus");
33 mytree = registry.byId("mytree");
34
35 // find TreeNodes for Africa, Asia (this assumes that we haven't loaded any of mytree's
36 // grandchild TreeNodes yet)
37 var nodes = query(".dijitTreeLabel");
38 africa = registry.getEnclosingWidget(nodes[1]);
39 asia = registry.getEnclosingWidget(nodes[2]);
40 }
41 ]);
42
43 function toggle(func, expanded){
44 return function(){
45 var d = new doh.Deferred();
46
47 doh.is(expanded, africa.isExpanded, "original state");
48
49 func(d);
50
51 robot.sequence(d.getTestCallback(function(){
52 doh.is(!expanded, africa.isExpanded, "after state");
53 }), 500);
54
55 return d;
56 };
57 }
58
59 doh.register("label click", [
60 {
61 name: "click to open",
62 timeout: 8000,
63 runTest: toggle(function(d){
64 robot.mouseMoveAt(africa.labelNode);
65 robot.mouseClick({left:true}, 100);
66 robot.sequence(d.getTestErrback(function(){
67 doh.is(1, robot.window.mouseDowns, "mouse down reported");
68 }), 500);
69 }, false)
70 },
71
72 {
73 name: "click to close",
74 timeout: 8000,
75 runTest: toggle(function(){
76 robot.mouseClick({left:true}, 100);
77 }, true)
78 },
79
80 {
81 name: "double click to open",
82 timeout: 8000,
83 setUp: function(){
84 mytree.openOnClick = false;
85 mytree.openOnDblClick = true;
86 },
87 runTest: toggle(function(){
88 robot.mouseClick({left:true}, 100);
89 robot.mouseClick({left:true}, 100);
90 }, false)
91 },
92
93 {
94 name: "double click to close",
95 timeout: 8000,
96 runTest: toggle(function(){
97 robot.mouseClick({left:true}, 100);
98 robot.mouseClick({left:true}, 100);
99 }, true)
100 }
101 ]);
102
103 doh.register("not a click", [
104 {
105 name: "setup",
106 timeout: 8000,
107 runTest: function(){
108 mytree.set("openOnClick", true);
109 return mytree.collapseAll().then(function(){
110 return mytree.set("path", ["continentRoot", "EU", "FR"]);
111 });
112 }
113 },
114
115 {
116 name: "mouse down france, up on italy",
117 timeout: 8000,
118 runTest: function(){
119 var labels = query(".dijitTreeLabel"),
120 europe = labels.filter(function(node){
121 return node.innerHTML == "Europe";
122 })[0],
123 france = labels.filter(function(node){
124 return node.innerHTML == "France";
125 })[0],
126 italy = labels.filter(function(node){
127 return node.innerHTML == "Italy";
128 })[0];
129
130 var d = new doh.Deferred();
131
132 robot.mouseMoveAt(france, 500, 0);
133 robot.mousePress({left:true}, 500);
134 robot.mouseMoveAt(italy, 500, 0);
135 robot.mouseRelease({left:true}, 500);
136 robot.sequence(d.getTestCallback(function(){
137 var europeNode = registry.getEnclosingWidget(europe);
138 doh.t(europeNode.isExpanded, "europe node still expanded");
139 doh.isNot("Europe", mytree.focusedChild.label, "focus didn't shift to Europe");
140 }), 500);
141
142 return d;
143 }
144 }
145 ]);
146
147 doh.register("focus", [
148 {
149 name: "setup",
150 runTest: function(){
151 // prevent TreeNodes from moving around as we are moving the mouse to find them
152 mytree.set("openOnClick", false);
153 }
154 },
155 {
156 name: "focus africa",
157 timeout: 8000,
158 runTest: function(){
159 var d = new doh.Deferred();
160 robot.mouseMoveAt(africa.labelNode);
161 robot.mouseClick({left:true}, 100);
162 robot.sequence(d.getTestCallback(function(){
163 doh.is("Africa", helpers.innerText(focus.curNode));
164 }), 500);
165 return d;
166 }
167 },
168
169 {
170 name: "blur tree",
171 timeout: 8000,
172 runTest: function(){
173 var d = new doh.Deferred();
174 robot.mouseMoveAt("mytree_before");
175 robot.mouseClick({left:true}, 100);
176 robot.sequence(d.getTestCallback(function(){
177 doh.is("mytree_before", focus.curNode.id);
178 }), 500);
179 return d;
180 }
181 },
182
183 {
184 name: "click on asia's expando",
185 timeout: 8000,
186 runTest: function(){
187 var d = new doh.Deferred(),
188 africaGotFocus;
189 aspect.after(africa, "focus", function(){
190 africaGotFocus = true;
191 });
192 robot.mouseMoveAt(asia.expandoNode);
193 robot.mouseClick({left:true}, 100);
194 robot.sequence(d.getTestCallback(function(){
195 // Clicking the expando or anywhere on the row should focus that row.
196 // In addition, there shouldn't even be a momentary (possibly scroll inducing) focus on
197 // the previously focused row.
198 doh.is("Asia", helpers.innerText(focus.curNode));
199 doh.f(africaGotFocus, "africa didn't get momentary focus");
200 }), 500);
201 return d;
202 }
203 },
204
205 {
206 name: "focus long label",
207 timeout: 8000,
208 runTest: function(){
209 var d = new doh.Deferred();
210 var thinTree = registry.byId('thinTree');
211 var rootNode = thinTree.rootNode;
212
213 robot.mouseMoveAt(rootNode.expandoNode);
214 robot.mouseClick({left: true}, 100);
215 robot.sequence(d.getTestCallback(function(){
216 doh.f(rootNode.isExpanded, 'Clicking expando of node with long label should collapse node');
217 doh.is(0, thinTree.domNode.scrollLeft, 'Focusing node with long label should not scroll container');
218 }), 500);
219 return d;
220 }
221 }
222 ]);
223
224 doh.run();
225 });
226
227 </script>
228 </head>
229 </html>
230