| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | |
| 6 | <title>AreaManager</title> |
| 7 | <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
| 8 | |
| 9 | <link rel="stylesheet" type="text/css" href="../../../../../dojo/resources/dojo.css" /> |
| 10 | <link rel="stylesheet" type="text/css" href="../../../../../dijit/themes/tundra/tundra.css" /> |
| 11 | |
| 12 | <script type="text/javascript"><!-- |
| 13 | dojo.require("doh.runner"); |
| 14 | dojo.require("dojox.mdnd.AreaManager"); |
| 15 | dojo.require("dojox.mdnd.DropIndicator"); |
| 16 | dojo.require("dojox.mdnd.dropMode.VerticalDropMode"); |
| 17 | |
| 18 | dojo.declare("AreaManagerTestFixture", null, { |
| 19 | constructor:function(testName, test) { |
| 20 | this.name = testName; |
| 21 | this.runTest = test; |
| 22 | }, |
| 23 | setUp:function() { |
| 24 | this.mgr = dojox.mdnd.AreaManager.areaManager(); |
| 25 | |
| 26 | this.areaA = dojo.byId("areaA"); |
| 27 | this.areaB = dojo.byId("areaB"); |
| 28 | this.areaC = dojo.byId("areaC"); |
| 29 | |
| 30 | this.itemA = createItem("itemA"); |
| 31 | this.itemB = createItem("itemB"); |
| 32 | this.itemC = createItem("itemC"); |
| 33 | |
| 34 | }, |
| 35 | tearDown:function() { |
| 36 | //reinit DOM |
| 37 | var areas = [this.areaA,this.areaB,this.areaC]; |
| 38 | for (var i = 0; i < areas.length; i++) { |
| 39 | while (areas[i].firstChild) { |
| 40 | dojo.destroy(areas[i].removeChild(areas[i].lastChild)); |
| 41 | } |
| 42 | this.mgr.unregister(areas[i]); |
| 43 | } |
| 44 | delete this.areaA; |
| 45 | delete this.areaB; |
| 46 | delete this.areaC; |
| 47 | delete this.itemA; |
| 48 | delete this.itemB; |
| 49 | delete this.itemC; |
| 50 | |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | function createItem(id){ |
| 55 | return dojo.create('div',{'class':'item', 'id': id}); |
| 56 | }; |
| 57 | |
| 58 | //-------------------------------------- |
| 59 | dojo.addOnLoad(function(){ |
| 60 | |
| 61 | doh.register("AreaManagerManagingDragItems", |
| 62 | [ |
| 63 | /* |
| 64 | * Default test of adding an item |
| 65 | */ |
| 66 | new AreaManagerTestFixture("addDragItem",function(){ |
| 67 | |
| 68 | this.mgr.registerByNode(this.areaA); |
| 69 | this.mgr.addDragItem(this.areaA, this.itemA); |
| 70 | |
| 71 | doh.assertEqual(1, this.mgr._areaList.length, "One area should be register!"); |
| 72 | var areaItem = this.mgr._areaList[0]; |
| 73 | doh.assertEqual(areaItem.items.length, 1, "The register area should contain one item!"); |
| 74 | }), |
| 75 | |
| 76 | new AreaManagerTestFixture("unregisteredArea",function(){ |
| 77 | this.mgr.addDragItem(this.areaB, this.itemA); |
| 78 | doh.assertEqual(0, this.mgr._areaList.length, "An item shouldn't add to an unregitered area"); |
| 79 | }), |
| 80 | |
| 81 | new AreaManagerTestFixture("addDragItemWithDomAppendedNode",function(){ |
| 82 | this.mgr.registerByNode(this.areaB); |
| 83 | this.areaC.appendChild(this.itemA); |
| 84 | this.mgr.addDragItem(this.areaB, this.itemA); |
| 85 | doh.assertEqual(0, this.mgr._areaList[0].items.length, "Item shouldn't append to a node before add"); |
| 86 | }), |
| 87 | |
| 88 | new AreaManagerTestFixture("addDragItemWithInsideAreaNode",function(){ |
| 89 | this.mgr.registerByNode(this.areaC); |
| 90 | this.areaC.appendChild(this.itemA); |
| 91 | this.mgr.addDragItem(this.areaC, this.itemA); |
| 92 | var areaItem = this.mgr._areaList[0]; |
| 93 | doh.assertTrue(1, areaItem.items.length); |
| 94 | }), |
| 95 | |
| 96 | new AreaManagerTestFixture("addDragItemWithNegativeIndex",function(){ |
| 97 | this.mgr.registerByNode(this.areaA); |
| 98 | this.mgr.addDragItem(this.areaA, this.itemA, -1); |
| 99 | var areaItem = this.mgr._areaList[0]; |
| 100 | doh.assertEqual(1, areaItem.items.length); |
| 101 | }), |
| 102 | |
| 103 | new AreaManagerTestFixture("addDragItemWithOutsideIndex",function(){ |
| 104 | this.mgr.registerByNode(this.areaB); |
| 105 | this.mgr.addDragItem(this.areaB, this.itemA); |
| 106 | this.mgr.addDragItem(this.areaB, this.itemB, 100); |
| 107 | |
| 108 | var areaItem = this.mgr._areaList[0]; |
| 109 | doh.assertEqual(2, areaItem.items.length); |
| 110 | }), |
| 111 | |
| 112 | /* |
| 113 | * Default test of removing an item |
| 114 | */ |
| 115 | new AreaManagerTestFixture("removeDragItem",function(){ |
| 116 | this.mgr.registerByNode(this.areaA); |
| 117 | this.mgr.addDragItem(this.areaA, this.itemA); |
| 118 | |
| 119 | doh.assertEqual(1, this.mgr._areaList[0].items.length); |
| 120 | |
| 121 | this.mgr.removeDragItem(this.areaA, this.itemA); |
| 122 | var areaItem = this.mgr._areaList[0]; |
| 123 | |
| 124 | doh.assertEqual(0, this.mgr._areaList[0].items.length); |
| 125 | }), |
| 126 | |
| 127 | new AreaManagerTestFixture("removeWrongDragItem",function(){ |
| 128 | this.mgr.registerByNode(this.areaA); |
| 129 | this.mgr.registerByNode(this.areaB); |
| 130 | this.mgr.addDragItem(this.areaA, this.itemA); |
| 131 | this.mgr.removeDragItem(this.areaB, this.itemA); |
| 132 | |
| 133 | doh.assertEqual(1, this.mgr._areaList[0].items.length); |
| 134 | doh.assertEqual(0, this.mgr._areaList[1].items.length); |
| 135 | }) |
| 136 | ] |
| 137 | ); |
| 138 | doh.run(); |
| 139 | }); |
| 140 | //-------------------------------------- |
| 141 | --></script> |
| 142 | |
| 143 | </head> |
| 144 | <body class="tundra"> |
| 145 | <div class="area" id="areaA"></div> |
| 146 | <div class="area" id="areaB"></div> |
| 147 | <div class="area" id="areaC"></div> |
| 148 | </body> |
| 149 | </html> |