Debian Codegraph @

dojox/grid/tests/robot/DataGrid_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>doh.robot DataGrid tests</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"
13 data-dojo-config="isDebug: true"></script>
14 <script type="text/javascript">
15 dojo.require("dijit.robotx");
16
17 dojo.addOnLoad(function(){
18
19 doh.robot.initRobot('_DataGrid.html');
20
21 doh.register("dojo.data integration",
22 [
23 {
24 name: "set the store of a new DataGrid",
25 grid: null,
26 timeout:5000,
27 setUp: function(){
28 var params = new dojo.global.Object();
29 params.id = 'prog_grid_1';
30 params.structure = dojo.global.structure1;
31 this.grid = new dojo.global.dojox.grid.DataGrid(params, dojo.byId('prog_grid_1'));
32 this.grid.startup();
33 },
34 runTest: function(){
35 // need async test or tearDown will not fire on failure (assertion failed == don't tear down)
36 var d = new doh.Deferred();
37 var _this=this;
38 doh.robot.sequence(d.getTestCallback(function(){
39 // assuming exception == doh error
40 console.log("Setting store, if there is an error then it failed.");
41 _this.grid.setStore(dojo.global.structure1_store1, {}, {});
42 console.log("Done setting store and rendering.");
43 // last row should have something
44 doh.t(_this.grid.getItem(0),"0th row should have been not null");
45 }),500);
46 return d;
47 },
48 tearDown: function(){
49 var node = dojo.create('div',{id:this.grid.domNode.id, rowSelector:"20px"});
50 dojo.style(node,{width: "100%",height:"100px"});
51 var parent = this.grid.domNode.parentNode;
52 this.grid.destroyRecursive();
53 parent.appendChild(node);
54 this.grid = null;
55 }
56 },
57 {
58 name: "set the query of a new DataGrid",
59 grid: null,
60 timeout:5000,
61 setUp: function(){
62 var params = new dojo.global.Object();
63 params.id = 'prog_grid_1';
64 params.structure = dojo.global.structure1;
65 params.store = dojo.global.structure1_store1;
66 this.grid = new dojo.global.dojox.grid.DataGrid(params, dojo.byId('prog_grid_1'));
67 this.grid.startup();
68 },
69 runTest: function(){
70 // need async test or tearDown will not fire on failure (assertion failed == don't tear down)
71 var d = new doh.Deferred();
72 var _this=this;
73 doh.robot.sequence(d.getTestCallback(function(){
74 // assuming exception == doh error
75 console.log("Setting query, if there is an error then it failed.");
76 _this.grid.setQuery({ id: '1' },{});
77 console.log("Done setting query and rendering.");
78 // 0th row should have something
79 var item = _this.grid.getItem(0);
80 doh.t(item,"0th row should have been not null");
81 // 1st row should not
82 doh.f(_this.grid.getItem(1),"1st row should have been null");
83 }),500);
84 return d;
85 },
86 tearDown: function(){
87 var node = dojo.create('div',{id:this.grid.domNode.id, rowSelector:"20px"});
88 dojo.style(node,{width: "100%",height:"100px"});
89 var parent = this.grid.domNode.parentNode;
90 this.grid.destroyRecursive();
91 parent.appendChild(node);
92 this.grid = null;
93 }
94 },
95 {
96 name: "set sortFields",
97 grid: null,
98 changedItem: null,
99 timeout:5000,
100 setUp: function(){
101 this.grid = dijit.byId('markup_grid_1');
102 },
103 runTest: function(){
104 var d = new doh.Deferred();
105 var _this=this;
106 doh.robot.sequence(d.getTestCallback(function(){
107 _this.grid.set("sortFields",[{attribute:"col3",descending:true},{attribute:"id",descending:true}]);
108 dojo.global.structure1_store1.setValue(dojo.global.structure1_store1._getItemByIdentity(1),"col3","read");
109 // must force refresh to resort
110 _this.grid.render();
111 var item=_this.grid.getItem(0);
112 doh.is("read",item.col3,"first item should have had status==read after sort");
113 doh.is(1,item.id,"first item should have had id==1");
114 item=_this.grid.getItem(1);
115 doh.is("new",item.col3,"second item should have had status==new after sort");
116 doh.is(99,item.id,"second item should have had id==99");
117 }),500);
118 return d;
119 },
120 tearDown: function(){
121 this.grid.set("sortFields",[{attribute:"id",descending:false}]);
122 dojo.global.structure1_store1.setValue(dojo.global.structure1_store1._getItemByIdentity(1),"col3","new");
123 this.grid.render();
124 this.grid = null;
125 }
126 },
127 {
128 name: "onNew,onSet,onDelete",
129 grid: null,
130 timeout:5000,
131 connects: [],
132 onNew: null,
133 onSet: null,
134 onDelete: null,
135 setUp: function(){
136 this.grid = dijit.byId('markup_grid_2');
137 var _this=this;
138 this.connects.push(dojo.connect(this.grid,"_onNew",this,function(item){
139 _this.onNew = arguments;
140 }));
141 this.connects.push(dojo.connect(this.grid,"_onSet",this,function(item,attribute,oldvalue,newvalue){
142 _this.onSet = arguments;
143 }));
144 this.connects.push(dojo.connect(this.grid,"_onDelete",this,function(item){
145 _this.onDelete = arguments;
146 }));
147 },
148 runTest: function(){
149 var d = new doh.Deferred();
150 var _this=this;
151 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_1',500);
152 doh.robot.mouseClick({left:true},500);
153 doh.robot.sequence(d.getTestCallback(function(){
154 // onNew
155 var item = dojo.global.structure1_store2.newItem({
156 id: 100,
157 col1: 'note',
158 col2: true,
159 col3: 'read',
160 col4: 'New text',
161 col5: 1,
162 col6: 2,
163 col7: false,
164 col8: new Date()
165 });
166 doh.isNot(null,_this.onNew,"onNew did not fire");
167 doh.is(item,_this.onNew[0],"unexpected item passed to onNew");
168 // onSet
169 var attribute = "col5";
170 var oldvalue = item[attribute];
171 var newvalue = 30;
172 dojo.global.structure1_store2.setValue(item,attribute,newvalue);
173 doh.isNot(null,_this.onSet,"onSet did not fire");
174 doh.is(attribute,_this.onSet[1],"unexpected attribute set");
175 doh.is(oldvalue,_this.onSet[2],"unexpected old value");
176 doh.is(newvalue,_this.onSet[3],"wrong new value");
177 // onDelete
178 var success = dojo.global.structure1_store2.deleteItem(item);
179 doh.isNot(null,_this.onDelete,"onDelete did not fire");
180 doh.t(success,"item not deleted");
181 }),500);
182 return d;
183 },
184 tearDown: function(){
185 dojo.forEach(this.connects, function(c){
186 dojo.disconnect(c);
187 });
188 this.onNew = null;
189 this.onSet = null;
190 this.onDelete = null;
191 this.grid = null;
192 }
193 },
194 {
195 name: "user sort",
196 grid: null,
197 timeout:15000,
198 setUp: function(){
199 var params = new dojo.global.Object();
200 params.id = 'prog_grid_1';
201 params.structure = dojo.global.structure1;
202 params.store = dojo.global.structure1_store1;
203 params.query = { id: '*' };
204 this.grid = new dojo.global.dojox.grid.DataGrid(params,dojo.byId('prog_grid_1'));
205 this.grid.startup();
206 },
207 runTest: function(){
208 var d = new doh.Deferred();
209 var _this=this;
210 var columns = dojo.query('div.dojoxGridSortNode',_this.grid.domNode);
211 doh.robot.mouseMoveAt(columns[0]);
212 doh.robot.mouseClick({left:true},500);
213 doh.robot.mouseClick({left:true},500);
214 doh.robot.sequence(d.getTestCallback(function(){
215 var item=_this.grid.getItem(0);
216 doh.is(99,item.id,"first item should have had id==99 due to reverse sort");
217 }),7000);
218 return d;
219 },
220 tearDown: function(){
221 var node = dojo.create('div',{id:this.grid.domNode.id, rowSelector:"20px"});
222 dojo.style(node,{width: "100%",height:"100px"});
223 var parent = this.grid.domNode.parentNode;
224 //this.grid.destroyRecursive();
225 //parent.appendChild(node);
226 this.grid = null;
227 }
228 }
229 ]);
230 doh.register("UI verification",[
231 {
232 name: "identical grids",
233 timeout:10000,
234 runTest: function(){
235 var d = new doh.Deferred();
236 // these grids are identical except for y position, their components should have the same styles when rendered
237 var grids=[dijit.byId('markup_grid_1'),dijit.byId('markup_grid_2'),dijit.byId('markup_grid_3'),dijit.byId('markup_grid_markup_structure')];
238 // render all grids and collect widths from them
239 var gridData=[];
240 for(var i=0; i<grids.length; i++){
241 gridData.push({});
242 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_'+i,500);
243 doh.robot.mouseClick({left:true},500);
244 // i == gridData.length when the following sequence executes so use dojo.hitch to pass i along
245 doh.robot.sequence(dojo.hitch(this,function(i){
246 // copy style data from the now visible grid
247 gridData[i].cellBoxes=[];
248 var cells=dojo.query("td.dojoxGridCell",grids[i].views.views[1].scrollboxNode);
249 for(var j=0; j<dojo.global.structure1[0].rows.length; j++){
250 var box = dojo.marginBox(cells[j]);
251 gridData[i].cellBoxes[j]={w:box.w,h:box.h};
252 }
253 gridData[i].height = dojo.marginBox(grids[i].domNode).h;
254 gridData[i].rowSelectorWidth = dojo.marginBox(dojo.query("* td.dojoxGridRowbarInner",grids[i].domNode)[0]).w;
255 gridData[i].scrollBoxWidth = dojo.marginBox(grids[i].views.views[1].scrollboxNode).w;
256 },i),500);
257 }
258 doh.robot.sequence(d.getTestCallback(function(){
259 for(var i=1; i<grids.length; i++){
260 // compare the dimensions of each cell
261 for(var j=0; j<gridData[i].cellBoxes.length; j++){
262 doh.is(gridData[0].cellBoxes[j],gridData[i].cellBoxes[j],dojo.global.structure1[0].rows[j].name+" cell in "+grids[i].id+" should be the same as "+grids[0].id);
263 }
264 // compare the width of the initially visible (correct) grid to the grids in the other tabs
265 doh.is(gridData[0].rowSelectorWidth,gridData[i].rowSelectorWidth,grids[i].id+" row selector width should be the same as "+grids[0].id);
266 // compare the scrollBox width (determines whether the user can scroll the grid with the vertical scrollbar)
267 doh.is(gridData[0].scrollBoxWidth, gridData[i].scrollBoxWidth, grids[i].id+" scrollboxWidth should be the same as "+grids[0].id);
268 // compare heights of all of these identical grids (since they have the same amount of data, they should be the same height right?)
269 doh.is(gridData[0].height, gridData[i].height, grids[i].id+" height should be the same as "+grids[0].id);
270 }
271 }),500);
272 return d;
273 }
274 },
275 {
276 name: "update() grids",
277 timeout:20000,
278 runTest: function(){
279 var d = new doh.Deferred();
280 var grid1=dijit.byId('markup_grid_1'); // visible
281 var grid2=dijit.byId('markup_grid_2'); // hidden in tab
282 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500);
283 doh.robot.mouseClick({left:true},500);
284 doh.robot.sequence(function(){
285 // sizes before update
286 var boxBefore1 = dojo.marginBox(grid1.domNode);
287 var boxBefore2 = dojo.marginBox(grid2.domNode);
288 grid1.update(); // slow
289 grid2.update(); // slow
290 doh.robot.sequence(d.getTestCallback(function(){
291 // sizes after update
292 var boxAfter1 = dojo.marginBox(grid1.domNode);
293 var boxAfter2 = dojo.marginBox(grid2.domNode);
294 doh.is(boxBefore1.w,boxAfter1.w,"width of visible grid should not have changed after update()");
295 doh.is(boxBefore1.h,boxBefore1.h,"height of visible grid should not have changed after update()");
296 doh.is(boxBefore2.w,boxAfter2.w,"width of hidden grid should not have changed after update()");
297 doh.is(boxBefore2.h,boxAfter2.h,"height of hidden grid should not have changed after update()");
298 }),5000);
299 },500);
300 return d;
301 }
302 },
303 {
304 name: "column resizing",
305 timeout:20000,
306 grid: null,
307 setUp: function(){
308 this.grid = dijit.byId('markup_grid_1');
309 this.grid.sortInfo=0;
310 },
311 runTest: function(){
312 var d = new doh.Deferred();
313 var grid=this.grid;
314 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500);
315 doh.robot.mouseClick({left:true},500);
316 doh.robot.sequence(function(){
317 grid.domNode.scrollTop = 0;
318 // try to size column headers
319 // Id width changes
320 var columns = dojo.query('div.dojoxGridSortNode',grid.domNode).map(function(e){
321 return e.parentNode;
322 });;
323 var box = dojo.position(columns[0].firstChild);
324 doh.robot.mouseMoveAt(columns[1],500,100,0,box.h/2);
325 doh.robot.mousePress({left:true},500);
326 doh.robot.mouseMoveAt(columns[1],500,100,-box.w/2,0);
327 doh.robot.mouseRelease({left:true},500); // this takes a long time
328 doh.robot.sequence(function(){
329 try{
330 columns = dojo.query('div.dojoxGridSortNode',grid.domNode);
331 var box2 = dojo.position(columns[0]);
332 doh.t(Math.abs(box.w/2-box2.w)<1, "ID column width did not shrink as expected.");
333 // Message (col4) should be unsizeable
334 box = dojo.position(columns[5]);
335 doh.robot.mouseMoveAt(columns[6],500,100,0,box.h/2);
336 doh.robot.mousePress({left:true},500);
337 doh.robot.mouseMoveAt(columns[6],500,100,-box.w/2,box.h/2);
338 doh.robot.mouseRelease({left:true},500); // this takes a long time
339 doh.robot.sequence(d.getTestCallback(function(){
340 columns = dojo.query('div.dojoxGridSortNode',grid.domNode);
341 box2 = dojo.position(columns[5]);
342 doh.is(box.w, box2.w, "Message column width should not have changed.");
343 doh.is(0,grid.sortInfo,"Attempting to resize a non-resizable column should not set the sort order.");
344 }),5000);
345 }catch(e){
346 d.callback(e);
347 }
348 },5000);
349 },500);
350 return d;
351 },
352 tearDown: function(){
353 this.grid = null;
354 }
355 },
356 {
357 name: "edit columns",
358 timeout:60000,
359 grid: null,
360 setUp:function(){
361 this.grid = dijit.byId('markup_grid_1');
362 },
363 runTest: function(){
364 // see also "edit reordered columns" test below
365 var d = new doh.Deferred();
366 var grid=this.grid;
367 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500);
368 doh.robot.mouseClick({left:true},500);
369 // precondition: cells still arranged to id date priority mark status message amount amount
370 var editorids=[null,'dijit_form_DateTextBox_0','dijit_form_ComboBox_0','dijit_form_CheckBox_0',null,'dijit_Editor_0','dijit_form_CurrencyTextBox_0','dijit_form_HorizontalSlider_0'];
371 function nextTest(i){
372 if(i==editorids.length){
373 d.callback(true);
374 return;
375 }
376 if(!editorids[i]){
377 nextTest(i+1);
378 return;
379 }
380 doh.robot.sequence(function(){
381 var cells=dojo.query("td.dojoxGridCell",grid.views.views[1].scrollboxNode);
382 doh.robot.mouseMoveAt(cells[i],500);
383 doh.robot.mouseClick({left:true},500);
384 doh.robot.mouseClick({left:true},1);
385 doh.robot.sequence(function(){
386 try{
387 // this better have opened the expected editor or something very bad happened
388 doh.isNot(undefined,dijit.byId(editorids[i]),"Editing the "+i+" field of the 1st row did not open the expected editor.");
389 doh.t(dijit.byId(editorids[i]).focused);
390 grid.edit.cancel();
391 nextTest(i+1);
392 }catch(e){
393 d.callback(e);
394 }
395 },2000);
396 },500);
397 }
398 nextTest(0);
399 return d;
400 },
401 tearDown:function(){
402 // done editing
403
404 this.grid.edit.cancel();
405 this.grid = null;
406 }
407 },
408 {
409 name: "column reordering",
410 timeout:10000,
411 runTest: function(){
412 var d = new doh.Deferred();
413 // FIXME: choose one of the other grids with filler text on the top so IE scrollIntoView doesn't freak out
414 var grid=dijit.byId('markup_grid_1');
415 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500);
416 doh.robot.mouseClick({left:true},500);
417 // try to reorder column headers:
418 // Id (fixed width)
419 // Message (auto width)
420 doh.robot.sequence(function(){
421 grid.domNode.scrollTop = 0;
422 var columns = dojo.query('div.dojoxGridSortNode',grid.domNode);
423 var id=columns[0];
424 var priority=columns[2];
425 var expectedtext=[id.innerHTML,priority.innerHTML];
426 doh.robot.mouseMoveAt(id,500);
427 doh.robot.mousePress({left:true},500);
428 // position id left of priority
429 doh.robot.mouseMoveAt(priority,500,1000,0,0);
430 doh.robot.mouseRelease({left:true},500);
431 doh.robot.sequence(function(){
432 try{
433 var newColumns = dojo.query('div.dojoxGridSortNode',grid.domNode);
434 var newId = newColumns[1];
435 var newPriority = newColumns[2];
436 // the original nodes get orphaned so direct comparison is impossible
437 doh.is(expectedtext[0],newId.innerHTML,"2nd column should have been Id after dnd");
438 doh.is(expectedtext[1],newPriority.innerHTML,"3rd column should have been Priority after dnd");
439 // position message left of status
440 columns = newColumns;
441 var status=columns[4];
442 var message=columns[5];
443 expectedtext=[message.innerHTML,status.innerHTML,];
444 doh.robot.mouseMoveAt(message,500);
445 doh.robot.mousePress({left:true},500);
446 doh.robot.mouseMoveAt(status,500,1000,0,0);
447 doh.robot.mouseRelease({left:true},500);
448 doh.robot.sequence(d.getTestCallback(function(){
449 newColumns = dojo.query('div.dojoxGridSortNode',grid.domNode);
450 var newMessage = newColumns[4];
451 var newStatus = newColumns[5];
452 doh.is(expectedtext[0],newMessage.innerHTML,"5th column should have been Message after dnd");
453 doh.is(expectedtext[1],newStatus.innerHTML,"6th column should have been Status after dnd");
454 }),500);
455 }catch(e){
456 d.callback(e);
457 }
458 },500);
459 },500);
460 // also, should not be able to drag columns to other dojo.dnd targets
461 return d;
462 }
463 },
464 {
465 name: "edit reordered columns",
466 timeout:60000,
467 grid: null,
468 setUp:function(){
469 this.grid = dijit.byId('markup_grid_1');
470 },
471 runTest: function(){
472 // same test as the previous edit test, but on next row (since cell editors persist)
473 // assumes previous dnd test rearranged the cells successfully
474 var d = new doh.Deferred();
475 var grid=this.grid;
476 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500);
477 doh.robot.mouseClick({left:true},500);
478 // precondition: cells rearranged to date id priority mark message status amount amount
479 var editorids=['dijit_form_DateTextBox_1',null,'dijit_form_ComboBox_1','dijit_form_CheckBox_1','dijit_Editor_1',null,'dijit_form_CurrencyTextBox_1','dijit_form_HorizontalSlider_1'];
480 function nextTest(i){
481 if(i==(editorids.length*2)){
482 d.callback(true);
483 return;
484 }
485 if(!editorids[i-editorids.length]){
486 nextTest(i+1);
487 return;
488 }
489 doh.robot.sequence(function(){
490 var cells=dojo.query("td.dojoxGridCell",grid.views.views[1].scrollboxNode);
491 doh.robot.mouseMoveAt(cells[i],500);
492 doh.robot.mouseClick({left:true},500);
493 doh.robot.mouseClick({left:true},1);
494 doh.robot.sequence(function(){
495 try{
496 // this better have opened the expected editor or something very bad happened
497 doh.isNot(undefined,dijit.byId(editorids[i]),"Editing the "+(i-editorids.length)+" field of the 2nd row after column drag and drop did not open the expected editor.");
498 doh.t(dijit.byId(editorids[i]).focused);
499 grid.edit.cancel();
500 nextTest(i+1);
501 }catch(e){
502 d.callback(e);
503 }
504 },2000);
505 },500);
506 }
507 nextTest(editorids.length);
508 return d;
509 },
510 tearDown:function(){
511 // done editing
512 this.grid.edit.cancel();
513 this.grid = null;
514 }
515 },
516 {
517 name: "column 1px move should not reorder",
518 timeout:10000,
519 runTest: function(){
520 var d = new doh.Deferred();
521 var grid=dijit.byId('markup_grid_1');
522 doh.robot.mouseMoveAt('mainTabContainer_tablist_dijit_layout_ContentPane_0',500,1);
523 doh.robot.mouseClick({left:true},500);
524 doh.robot.sequence(function(){
525 grid.domNode.scrollTop = 0;
526 var columns = dojo.query('div.dojoxGridSortNode',grid.domNode);
527 var prevHTML = columns[1].innerHTML;
528 var priority = columns[2];
529 doh.robot.mouseMoveAt(priority,500,500,10,5);
530 doh.robot.mousePress({left:true},100);
531 // drag priority column 1px
532 doh.robot.mouseMoveAt(priority,500,1,9,5);
533 doh.robot.mouseRelease({left:true},100);
534 doh.robot.sequence(d.getTestCallback(function(){
535 var newColumns = dojo.query('div.dojoxGridSortNode',grid.domNode);
536 var newHTML = newColumns[1].innerHTML;
537 // the original nodes get orphaned so direct comparison is impossible
538 doh.is(prevHTML,newHTML,"1st column should still be id after nop dnd " + ' old = ['+prevHTML+'] new = [' + newHTML + ']');
539 }),2000);
540 },1);
541 // also, should not be able to drag columns to other dojo.dnd targets
542 return d;
543 }
544 }
545 ]);
546 doh.run();
547 });
548 </script>
549 </head>
550 </html>