Debian Codegraph @

dijit/tests/form/robot/MultiSelect.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>doh.robot MultiSelect Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <!-- required: dojo.js -->
12 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
13
14 <script type="text/javascript">
15 dojo.require("dijit.robotx");
16 dojo.require("dijit.tests.helpers"); // functions to help test
17
18 function testInverted(allOptions, selected, newSelected){
19 doh.is(allOptions.length, selected.length+newSelected.length); //newSelected + the no longer selected list size should be the same as the length of the whole list
20 dojo.forEach(allOptions, function(option){ //verify the selections were inverted
21 var found;
22 if(option.selected){
23 //it must be in the newSelectedList
24 found=false;
25 dojo.forEach(newSelected, function(ns){
26 if(option.value===ns){
27 found=true;
28 }
29 });
30 doh.t(found);
31 }else{
32 //it better be in the original selected list
33 found=false;
34 dojo.forEach(selected, function(s){
35 if(option.value===s){
36 found=true;
37 }
38 });
39 doh.t(found);
40 }
41 });
42 }
43
44 dojo.ready(function(){
45 doh.robot.initRobot('../test_MultiSelect.html');
46
47 doh.register("dijit.form.MultiSelect", [
48 {
49 name: "tabInSelect",
50 timeout: 6000,
51 runTest: function(){
52 var d = new doh.Deferred();
53
54 var changed = false;
55 dijit.byId("select").set("onChange", function(e){changed = true; });
56
57 dojo.global.scrollTo(0,0);
58 doh.robot.mouseMove(30,30);
59 doh.robot.mouseClick({left:true}, 1000); //tabbing in doesn't work in FF unless we first click on the page first
60
61 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
62 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {}); //Arrowing down will select the element for IE, FF, Safari, & chrome
63 doh.robot.keyPress(dojo.keys.SPACE, 1000, {}); //Space is needed to select the element in opera
64
65 doh.robot.sequence(d.getTestCallback(function(){
66 doh.t(changed);
67 }), 1000);
68 return d;
69 }
70 },
71 {
72 name: "switchRight",
73 timeout: 5000,
74 runTest: function(){
75 var d = new doh.Deferred();
76
77 doh.robot.sequence(function(){
78 dijit.byId('select').set('value', ['16']);
79 }, 500);
80
81 doh.robot.mouseMoveAt("right", 1000);
82 doh.robot.mouseClick({left:true}, 500);
83
84 var selectedValue2 = "";
85 doh.robot.sequence(function(){ selectedValue2 = dijit.byId('select2').get('value');}, 1000);
86
87 doh.robot.sequence(d.getTestCallback(function(){
88 doh.is("16", dijit.byId('select2').value.toString());
89 doh.is("16", selectedValue2[0]);
90 }), 1000);
91 return d;
92 }
93 },
94 {
95 name: "switchLeft",
96 timeout: 5000,
97 runTest: function(){
98 var d = new doh.Deferred();
99
100 doh.robot.sequence(function(){
101 dijit.byId('select2').set('value', ['3','7','19','47']);
102 }, 500);
103
104 doh.robot.mouseMoveAt("left", 1000);
105 doh.robot.mouseClick({left:true}, 500);
106
107 var selectedValue = "";
108 doh.robot.sequence(function(){ selectedValue = dijit.byId('select').get('value');}, 1000);
109
110 doh.robot.sequence(d.getTestCallback(function(){
111 doh.is("3", selectedValue[0]);
112 doh.is("7", selectedValue[1]);
113 doh.is("19", selectedValue[2]);
114 doh.is("47", selectedValue[3]);
115 doh.is("3 7 19 47", dijit.byId('select').value.join(' '));
116 }), 1000);
117 return d;
118 }
119 },
120 {
121 name: "invertSelected",
122 timeout: 8000,
123 runTest: function(){
124 var d = new doh.Deferred();
125
126 //select a block in the first list
127 doh.robot.sequence(function(){
128 dijit.byId('select').set('value', ['18','14','12','10']);
129 }, 500);
130
131 //get the selected list
132 var allOptions = "";
133 var selected = "";
134 var newSelected = "";
135 doh.robot.sequence(function(){
136 selected = dijit.byId('select').get('value');
137 allOptions = dijit.byId('select').domNode.options;
138 }, 1000);
139
140 doh.robot.mouseMoveAt("i1", 1000);
141 doh.robot.mouseClick({left:true}, 500);
142
143 doh.robot.sequence(function(){
144 newSelected = dijit.byId('select').get('value');
145 }, 1000);
146
147 doh.robot.sequence(d.getTestCallback(function(){
148 testInverted(allOptions, selected, newSelected);
149 }), 1000);
150 return d;
151 }
152 },
153 {
154 name: "invertSelected2",
155 timeout: 8000,
156 runTest: function(){
157 var d = new doh.Deferred();
158
159 //select random options
160 doh.robot.sequence(function(){
161 dijit.byId('select').set('value', ['2','8','14','20','22','32']);
162 }, 500);
163
164 //get the selected list
165 var allOptions = "";
166 var selected = "";
167 var newSelected = "";
168 doh.robot.sequence(function(){
169 selected = dijit.byId('select').get('value');
170 allOptions = dijit.byId('select').domNode.options;
171 }, 1000);
172
173 doh.robot.mouseMoveAt("i1", 1000);
174 doh.robot.mouseClick({left:true}, 500);
175
176 doh.robot.sequence(function(){
177 newSelected = dijit.byId('select').get('value');
178 }, 1000);
179
180 doh.robot.sequence(d.getTestCallback(function(){
181 testInverted(allOptions, selected, newSelected);
182 }), 1000);
183 return d;
184 }
185 },
186 {
187 name: "invertSelected3",
188 timeout: 8000,
189 runTest: function(){
190 var d = new doh.Deferred();
191
192 //Select the first thing in the list and then invert it
193 //select random options
194 doh.robot.sequence(function(){
195 dijit.byId('select3').set('value', ['TN']);
196 }, 500);
197
198 //get the selected list
199 var allOptions = "";
200 var selected = "";
201 var newSelected = "";
202 doh.robot.sequence(function(){
203 selected = dijit.byId('select3').get('value');
204 allOptions = dijit.byId('select3').domNode.options;
205 }, 1000);
206
207 doh.robot.mouseMoveAt("i3", 1000);
208 doh.robot.mouseClick({left:true}, 500);
209
210 doh.robot.sequence(function(){
211 newSelected = dijit.byId('select3').get('value');
212 }, 1000);
213
214 doh.robot.sequence(d.getTestCallback(function(){
215 testInverted(allOptions, selected, newSelected);
216 }), 1000);
217 return d;
218 }
219 },
220 {
221 name: "setValue",
222 timeout: 5000,
223 runTest: function(){
224 var d = new doh.Deferred();
225
226 //Select only one thing in the list to make sure we don't start with the values that we are going to select
227 doh.robot.sequence(function(){
228 dijit.byId('select3').set('value', ['CA']);
229 }, 500);
230
231 doh.robot.mouseMoveAt("s1", 1000);
232 doh.robot.mouseClick({left:true}, 500);
233
234 doh.robot.sequence(d.getTestCallback(function(){
235 var selected = dijit.byId('select3').get('value');
236 doh.is(2, selected.length);
237 doh.is(selected[0], 'VA');
238 doh.is(selected[1], 'WA');
239 doh.is("VA WA", dijit.byId('select3').value.join(' '));
240 }), 1000);
241 return d;
242 }
243 }
244
245 ]);
246
247 doh.run();
248 });
249 </script>
250 </head>
251 </html>