| 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 DnD Multi-parent 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/dnd/common", "dojo/dom", "dojo/dom-class", "dojo/keys", "dojo/query", "dojo/sniff", |
| 17 | "dijit/tests/helpers", "dijit/tests/tree/robot/Tree_dnd", "dojo/domReady!" |
| 18 | ], function(doh, robot, dndCommon, dom, domClass, keys, query, has, helpers, dndHelpers){ |
| 19 | |
| 20 | robot.initRobot('../test_Tree_DnD.html'); |
| 21 | |
| 22 | dndHelpers.setup(); |
| 23 | |
| 24 | doh.register("multi-parent tests", [ |
| 25 | { |
| 26 | name: "add 'Fruits' as parent of vegetables", |
| 27 | timeout: 10000, |
| 28 | runTest: function(){ |
| 29 | var |
| 30 | d = new doh.Deferred(), |
| 31 | vegetablesTreeNode = dndHelpers.findTreeNodeByPath("collectionsTree", ["Vegetables (0)"]), // the left tree |
| 32 | fruitsTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits"]); // right tree |
| 33 | |
| 34 | robot.mouseMoveAt("collectionsTree", 500, 1); // scroll source parent into view |
| 35 | robot.mouseMoveAt(vegetablesTreeNode.domNode, 500, 1); |
| 36 | // Drag and Drop, *copying* in order to add a parent rather than change |
| 37 | robot.keyDown(keys.copyKey, 500); |
| 38 | if(has("mac")){ |
| 39 | // I can't get DOH robot to generate the mousePress event w/metaKey=true so |
| 40 | // hack it |
| 41 | robot.sequence(function(){ |
| 42 | realIsCopyKey = dndCommon.getCopyKeyState; |
| 43 | dndCommon.getCopyKeyState = function(){ return true; } |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | robot.mousePress({left: true}, 500); |
| 48 | robot.mouseMoveAt("itemTree", 500, 500); // move to dest parent to scroll it into view |
| 49 | robot.mouseMoveAt(fruitsTreeNode.labelNode, 0, 500); |
| 50 | robot.mouseRelease({left: true}, 500); |
| 51 | robot.keyUp(keys.copyKey, 500); |
| 52 | if(has("mac")){ |
| 53 | // See if(has("mac")) above |
| 54 | robot.sequence(function(){ |
| 55 | dndCommon.getCopyKeyState = realIsCopyKey; |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | robot.sequence(d.getTestCallback(function(){ |
| 60 | // Check that Vegetables remains a child of Foods |
| 61 | var children = dndHelpers.getNamesOfChildrenOfItem("Foods"); |
| 62 | doh.is(3, children.categories.length, "foods category child"); |
| 63 | doh.is("Fruits", children.categories[0]); |
| 64 | doh.is("Vegetables", children.categories[1]); |
| 65 | doh.is("Cereals", children.categories[2]); |
| 66 | |
| 67 | // Check that Vegetables added as child of Fruits |
| 68 | var children2 = dndHelpers.getNamesOfChildrenOfItem("Fruits"); |
| 69 | doh.is(2, children2.categories.length, "foods category child"); |
| 70 | doh.is("Citrus", children2.categories[0]); |
| 71 | doh.is("Vegetables", children2.categories[1]); |
| 72 | |
| 73 | // Check that new item *wasn't* created |
| 74 | var items; |
| 75 | robot.window.myStore.fetch({ |
| 76 | onComplete: function(i){ items = i; } |
| 77 | }); |
| 78 | doh.is(6, items.length, "# of items in store"); |
| 79 | |
| 80 | // Check that data store update was reflected in the tree |
| 81 | doh.t(fruitsTreeNode.isExpanded, "drop caused the node to expand"); |
| 82 | var treeNodeChildren = fruitsTreeNode.getChildren(); |
| 83 | doh.is(2, treeNodeChildren.length, "2 TreeNode children"); |
| 84 | doh.is("Citrus", helpers.innerText(treeNodeChildren[0].labelNode)); |
| 85 | doh.is("Vegetables", helpers.innerText(treeNodeChildren[1].labelNode)); |
| 86 | }), 1000); // 1000ms to wait for 'Fruits' node to expand and show 'Apple' node |
| 87 | |
| 88 | return d; |
| 89 | } |
| 90 | }, |
| 91 | { |
| 92 | name: "move Foods/Vegetables to Foods/Cereal/Vegetables", |
| 93 | timeout: 10000, |
| 94 | runTest: function(){ |
| 95 | var |
| 96 | d = new doh.Deferred(), |
| 97 | vegetablesTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Vegetables"]), |
| 98 | cerealsTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Cereals"]); |
| 99 | |
| 100 | robot.window.scrollTo(0, 9000); // scroll to bottom to try and prevent the DnD code from autoscrolling |
| 101 | |
| 102 | // Drag and Drop |
| 103 | robot.mouseMoveAt(vegetablesTreeNode.domNode, 500, 1); |
| 104 | robot.mouseClick({left: true}, 500); // helps prevent screen jitter |
| 105 | robot.mousePress({left: true}, 1000); |
| 106 | robot.mouseMoveAt(vegetablesTreeNode.labelNode, 500, 500, 0, 0); // move mouse slightly to trigger DnD |
| 107 | robot.mouseMoveAt(cerealsTreeNode.domNode, 500, 100); // double move to allow for autoscrolling jitter |
| 108 | robot.mouseMoveAt(cerealsTreeNode.domNode, 500, 100); |
| 109 | robot.mouseRelease({left: true}, 500); |
| 110 | |
| 111 | robot.sequence(d.getTestCallback(function(){ |
| 112 | // Check that Vegetables remains a child of Fruits |
| 113 | var children = dndHelpers.getNamesOfChildrenOfItem("Fruits"); |
| 114 | doh.is(2, children.categories.length, "fruits category child"); |
| 115 | doh.is("Citrus", children.categories[0]); |
| 116 | doh.is("Vegetables", children.categories[1]); |
| 117 | |
| 118 | // Check that Vegetables added as child of Cereals |
| 119 | children = dndHelpers.getNamesOfChildrenOfItem("Cereals"); |
| 120 | doh.is(1, children.categories.length, "cereals category child"); |
| 121 | doh.is("Vegetables", children.categories[0]); |
| 122 | |
| 123 | // Check that Vegetables no longer a child of Foods |
| 124 | children = dndHelpers.getNamesOfChildrenOfItem("Foods"); |
| 125 | doh.is(2, children.categories.length, "foods category child"); |
| 126 | doh.is("Fruits", children.categories[0]); |
| 127 | doh.is("Cereals", children.categories[1]); |
| 128 | |
| 129 | // Check that new item *wasn't* created |
| 130 | var items; |
| 131 | robot.window.myStore.fetch({ |
| 132 | onComplete: function(i){ items = i; } |
| 133 | }); |
| 134 | doh.is(6, items.length, "# of items in store"); |
| 135 | }), 1000); // 1000ms to wait for 'Fruits' node to expand and show 'Apple' node |
| 136 | |
| 137 | return d; |
| 138 | } |
| 139 | }, |
| 140 | { |
| 141 | name: "move Fruits/Vegetables to Fruits/Citrus", |
| 142 | timeout: 10000, |
| 143 | runTest: function(){ |
| 144 | var |
| 145 | d = new doh.Deferred(), |
| 146 | vegetablesTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits", "Vegetables"]), |
| 147 | citrusTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits", "Citrus"]); |
| 148 | |
| 149 | // Drag and Drop |
| 150 | robot.mouseMoveAt(vegetablesTreeNode.labelNode, 500, 1); |
| 151 | robot.mouseClick({left: true}, 500); // helps prevent screen jitter |
| 152 | robot.mousePress({left: true}, 1000); |
| 153 | robot.mouseMoveAt(vegetablesTreeNode.labelNode, 500, 500, 0, 0); // move mouse slightly to trigger DnD |
| 154 | robot.mouseMoveAt(citrusTreeNode.labelNode, 0, 500); |
| 155 | robot.mouseRelease({left: true}, 500); |
| 156 | |
| 157 | robot.sequence(d.getTestCallback(function(){ |
| 158 | // Check that Vegetables remains a child of Cereals |
| 159 | var children = dndHelpers.getNamesOfChildrenOfItem("Cereals"); |
| 160 | doh.is(1, children.categories.length, "cereals category child"); |
| 161 | doh.is("Vegetables", children.categories[0]); |
| 162 | |
| 163 | // Check that Vegetables added as child of Citrus |
| 164 | children = dndHelpers.getNamesOfChildrenOfItem("Citrus"); |
| 165 | doh.is(1, children.categories.length, "citrus category child"); |
| 166 | doh.is("Vegetables", children.categories[0]); |
| 167 | doh.is(1, children.items.length, "citrus item child"); |
| 168 | doh.is("Orange", children.items[0]); |
| 169 | |
| 170 | // Check that Vegetables removed as child of Fruits |
| 171 | children = dndHelpers.getNamesOfChildrenOfItem("Fruits"); |
| 172 | doh.is(1, children.categories.length, "fruits category child"); |
| 173 | doh.is("Citrus", children.categories[0]); |
| 174 | |
| 175 | // Check that new item *wasn't* created |
| 176 | var items; |
| 177 | robot.window.myStore.fetch({ |
| 178 | onComplete: function(i){ items = i; } |
| 179 | }); |
| 180 | doh.is(6, items.length, "# of items in store"); |
| 181 | }), 1000); // 1000ms to wait for 'Fruits' node to expand and show 'Apple' node |
| 182 | |
| 183 | return d; |
| 184 | } |
| 185 | } |
| 186 | ]); |
| 187 | |
| 188 | doh.register("external drop tests", [ |
| 189 | { |
| 190 | name: "drop banana on fruits", |
| 191 | timeout: 10000, |
| 192 | runTest: function(){ |
| 193 | var |
| 194 | d = new doh.Deferred(), |
| 195 | fruitsTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits"]); // right tree |
| 196 | |
| 197 | var node = dom.byId("1003", robot.doc); |
| 198 | robot.mouseMoveAt(node.parentNode, 500, 1, 0, 0); // move to source parent node to help prevent DnD autoscrolling |
| 199 | robot.mouseMoveAt(node, 500, 1); // move to source banana node |
| 200 | robot.mousePress({left: true}, 500); |
| 201 | robot.mouseMoveAt(node.parentNode, 500, 100); // move just a little to start the DnD operation before scrolling |
| 202 | robot.mouseMoveAt("itemTree", 500, 500); // go to target parent top to allow for better scrolling of the destination |
| 203 | robot.mouseMoveAt(fruitsTreeNode.labelNode, 1000, 500); |
| 204 | robot.mouseRelease({left: true}, 500); |
| 205 | |
| 206 | robot.sequence(d.getTestCallback(function(){ |
| 207 | |
| 208 | var children = dndHelpers.getChildrenOfItem("Fruits"); |
| 209 | doh.is(1, children.items.length, "new item added"); |
| 210 | doh.is(1003, children.items[0].id, "id of new item came from dropped node"); |
| 211 | doh.is("Banana", children.items[0].name, "name of new item came from dropped node"); |
| 212 | |
| 213 | robot.window.myStore.fetch({ |
| 214 | query: { name: "Banana" }, |
| 215 | queryOptions: { deep: true }, |
| 216 | onComplete: function(i){ items = i; } |
| 217 | }); |
| 218 | doh.is(1, items.length, "1 banana item in store"); |
| 219 | }), 1000); |
| 220 | |
| 221 | return d; |
| 222 | } |
| 223 | }, |
| 224 | { |
| 225 | name: "drop banana on cereal", |
| 226 | timeout: 10000, |
| 227 | runTest: function(){ |
| 228 | var |
| 229 | d = new doh.Deferred(), |
| 230 | cerealsTreeNode = dndHelpers.findTreeNodeByPath("itemTree", ["Cereals"]); // right tree |
| 231 | |
| 232 | var node = dom.byId("1003", robot.doc); |
| 233 | robot.mouseMoveAt(node.parentNode, 500, 1, 0, 0); // move to source parent node to help prevent DnD autoscrolling |
| 234 | robot.mouseMoveAt(node, 500, 1); // move to source banana node |
| 235 | robot.mousePress({left: true}, 500); |
| 236 | robot.mouseMoveAt(node.parentNode, 500, 100); // move just a little to start the DnD operation before scrolling |
| 237 | robot.mouseMoveAt("itemTree", 500, 100); // go to target parent top to allow for better scrolling of the destination |
| 238 | robot.mouseMoveAt(cerealsTreeNode.labelNode, 1000, 500); |
| 239 | robot.mouseRelease({left: true}, 500); |
| 240 | |
| 241 | robot.sequence(d.getTestCallback(function(){ |
| 242 | |
| 243 | var children = dndHelpers.getChildrenOfItem("Cereals"); |
| 244 | doh.is(1, children.items.length, "banana is child of cereals"); |
| 245 | doh.is(1003, children.items[0].id, "id of item came from dropped node"); |
| 246 | doh.is("Banana", children.items[0].name, "name of new item came from dropped node"); |
| 247 | |
| 248 | var children2 = dndHelpers.getChildrenOfItem("Fruits"); |
| 249 | doh.is(1, children2.items.length, "banana still a child of fruits"); |
| 250 | doh.is(1003, children2.items[0].id, "id of new item came from dropped node"); |
| 251 | doh.is("Banana", children2.items[0].name, "name of new item came from dropped node"); |
| 252 | |
| 253 | robot.window.myStore.fetch({ |
| 254 | query: { name: "Banana" }, |
| 255 | queryOptions: { deep: true }, |
| 256 | onComplete: function(i){ items = i; } |
| 257 | }); |
| 258 | doh.is(1, items.length, "1 banana item in store (with 2 parents)"); |
| 259 | }), 1000); |
| 260 | |
| 261 | return d; |
| 262 | } |
| 263 | } |
| 264 | ]); |
| 265 | |
| 266 | doh.register("illegal drop", [ |
| 267 | // This tests dropping a node onto another node when both nodes represent the same item. |
| 268 | { |
| 269 | name: "try to drop Vegetables as child of Vegetables", |
| 270 | timeout: 10000, |
| 271 | runTest: function(){ |
| 272 | var |
| 273 | d = new doh.Deferred(), |
| 274 | drag = dndHelpers.findTreeNodeByPath("itemTree", ["Cereals", "Vegetables"]), |
| 275 | aboveDrop = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits", "Citrus"]); |
| 276 | drop = dndHelpers.findTreeNodeByPath("itemTree", ["Fruits", "Citrus", "Vegetables"]); |
| 277 | |
| 278 | doh.is(drop.item.id, drag.item.id, "both nodes point to same item"); |
| 279 | |
| 280 | // Drag bottom vegetables node over Citrus |
| 281 | robot.mouseMoveAt(drag.domNode, 500, 1); |
| 282 | robot.mousePress({left: true}, 500); |
| 283 | robot.mouseMoveAt(aboveDrop.labelNode, 0, 500); |
| 284 | |
| 285 | robot.sequence(d.getTestErrback(function(){ |
| 286 | var avatar = query(".dojoDndAvatar", robot.doc); |
| 287 | doh.t(avatar && avatar[0], "avatar found"); |
| 288 | doh.t(domClass.contains(avatar[0], "dojoDndAvatarCanDrop"), "can drop"); |
| 289 | }), 500); |
| 290 | |
| 291 | // Now move it to over first Vegetables node. Should be red icon indicating drop-unallowed |
| 292 | robot.mouseMoveAt(drop.labelNode, 0, 500); |
| 293 | robot.sequence(d.getTestErrback(function(){ |
| 294 | var avatar = query(".dojoDndAvatar", robot.doc); |
| 295 | doh.t(avatar && avatar[0], "avatar found"); |
| 296 | doh.f(domClass.contains(avatar[0], "dojoDndAvatarCanDrop"), "can't drop"); |
| 297 | }), 500); |
| 298 | |
| 299 | // Try to drop anyway, and make sure Tree structure doesn't change |
| 300 | robot.mouseRelease({left: true}, 500); |
| 301 | robot.sequence(d.getTestCallback(function(){ |
| 302 | doh.is(0, drop.getChildren().length, "drop node has no children"); |
| 303 | doh.t(drag == dndHelpers.findTreeNodeByPath("itemTree", ["Cereals", "Vegetables"]), |
| 304 | "drag node still in same place"); |
| 305 | }), 500); |
| 306 | |
| 307 | return d; |
| 308 | } |
| 309 | } |
| 310 | ]); |
| 311 | |
| 312 | doh.run(); |
| 313 | }); |
| 314 | </script> |
| 315 | </head> |
| 316 | </html> |