| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 4 | <head> |
|---|
| 5 | <title>script.aculo.us Unit test file</title> |
|---|
| 6 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|---|
| 7 | <script src="../../lib/prototype.js" type="text/javascript"></script> |
|---|
| 8 | <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
|---|
| 9 | <script src="../../src/unittest.js" type="text/javascript"></script> |
|---|
| 10 | <link rel="stylesheet" href="../test.css" type="text/css" /> |
|---|
| 11 | <style type="text/css" media="screen"> |
|---|
| 12 | /* <![CDATA[ */ |
|---|
| 13 | #div_absolute_test { position: absolute } |
|---|
| 14 | /* ]]> */ |
|---|
| 15 | </style> |
|---|
| 16 | |
|---|
| 17 | </head> |
|---|
| 18 | <body> |
|---|
| 19 | <h1>script.aculo.us Unit test file</h1> |
|---|
| 20 | <p> |
|---|
| 21 | Test of drag & drop functions in dragdrop.js |
|---|
| 22 | </p> |
|---|
| 23 | |
|---|
| 24 | <!-- Log output --> |
|---|
| 25 | <div id="testlog"> </div> |
|---|
| 26 | |
|---|
| 27 | <p id="p_test">p_test</p> |
|---|
| 28 | <p id="p_test2">p_test2</p> |
|---|
| 29 | <p id="p_test3">p_test3</p> |
|---|
| 30 | <img id="img_test" src="icon.png" alt="img_text"/> |
|---|
| 31 | <div id="droppable_test">droppable_test</div> |
|---|
| 32 | |
|---|
| 33 | <div id="div_test">div_test</div> |
|---|
| 34 | <div id="div_absolute_test">div_absolute_test</div> |
|---|
| 35 | <div id="div_absolute_inline_test" style="position:absolute">div_absolute_inline_test</div> |
|---|
| 36 | |
|---|
| 37 | <div id="droppable_container"> |
|---|
| 38 | <div id="d1">droppable_test</div> |
|---|
| 39 | <div id="d2">droppable_test</div> |
|---|
| 40 | </div> |
|---|
| 41 | |
|---|
| 42 | <div id="droppable_container_2"> |
|---|
| 43 | <div id="d3">droppable_test</div> |
|---|
| 44 | </div> |
|---|
| 45 | |
|---|
| 46 | <!-- Tests follow --> |
|---|
| 47 | <script type="text/javascript" language="javascript" charset="utf-8"> |
|---|
| 48 | // <![CDATA[ |
|---|
| 49 | |
|---|
| 50 | new Test.Unit.Runner({ |
|---|
| 51 | |
|---|
| 52 | testDraggableBasics: function() { with(this) { |
|---|
| 53 | var d = new Draggable('p_test'); |
|---|
| 54 | assertInstanceOf(Draggable, d); |
|---|
| 55 | }}, |
|---|
| 56 | |
|---|
| 57 | testDraggableStartEffect: function() { with(this) { |
|---|
| 58 | var d = new Draggable('p_test2'); |
|---|
| 59 | assert(d.options.starteffect, 'There should be a default start effect.'); |
|---|
| 60 | d = new Draggable('p_test3', { endeffect: Prototype.EmptyFunction }); |
|---|
| 61 | assert(undefined === d.options.startEffect, 'There should be no default start effect.'); |
|---|
| 62 | }}, |
|---|
| 63 | |
|---|
| 64 | testAutoPositioning: function() { with(this) { |
|---|
| 65 | assertEqual('static', Element.getStyle('div_test','position')); |
|---|
| 66 | new Draggable('div_test'); |
|---|
| 67 | new Draggable('div_absolute_test'); |
|---|
| 68 | new Draggable('div_absolute_inline_test'); |
|---|
| 69 | assertEqual('relative', Element.getStyle('div_test','position')); |
|---|
| 70 | assertEqual('absolute', Element.getStyle('div_absolute_test','position')); |
|---|
| 71 | assertEqual('absolute', Element.getStyle('div_absolute_inline_test','position')); |
|---|
| 72 | }}, |
|---|
| 73 | |
|---|
| 74 | testDroppbalesBasics: function() { with(this) { |
|---|
| 75 | assertEqual(0, Droppables.drops.length); |
|---|
| 76 | assertEqual('static', Element.getStyle('droppable_test','position')); |
|---|
| 77 | |
|---|
| 78 | Droppables.add('droppable_test'); |
|---|
| 79 | assertEqual(1, Droppables.drops.length); |
|---|
| 80 | assertEqual('relative', Element.getStyle('droppable_test','position')); |
|---|
| 81 | |
|---|
| 82 | Droppables.remove('droppable_test'); |
|---|
| 83 | assertEqual(0, Droppables.drops.length); |
|---|
| 84 | |
|---|
| 85 | // accept option should take strings or array of strings |
|---|
| 86 | Droppables.add('droppable_test',{accept:'document'}); |
|---|
| 87 | assertEqual(['document'].inspect(), Droppables.drops[0].accept.inspect()); |
|---|
| 88 | Droppables.remove('droppable_test'); |
|---|
| 89 | |
|---|
| 90 | Droppables.add('droppable_test',{accept:['document','image']}); |
|---|
| 91 | assertEqual(['document','image'].inspect(), Droppables.drops[0].accept.inspect()); |
|---|
| 92 | Droppables.remove('droppable_test'); |
|---|
| 93 | }}, |
|---|
| 94 | |
|---|
| 95 | testDroppableContainment: function() { with(this) { |
|---|
| 96 | // Droppable containers should be cached |
|---|
| 97 | Droppables.add('droppable_test', { |
|---|
| 98 | containment:'droppable_container' }); |
|---|
| 99 | assertEqual(1, Droppables.drops[0]._containers.length); |
|---|
| 100 | assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]); |
|---|
| 101 | assert(Droppables.isContained($('d1'), Droppables.drops[0])); |
|---|
| 102 | assert(Droppables.isContained($('d2'), Droppables.drops[0])); |
|---|
| 103 | assert(!Droppables.isContained($('d3'), Droppables.drops[0])); |
|---|
| 104 | Droppables.remove('droppable_test'); |
|---|
| 105 | |
|---|
| 106 | Droppables.add('droppable_test', { |
|---|
| 107 | containment:['droppable_container','droppable_container_2'] }); |
|---|
| 108 | assertEqual(2, Droppables.drops[0]._containers.length); |
|---|
| 109 | assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]); |
|---|
| 110 | assertEqual($('droppable_container_2'), Droppables.drops[0]._containers[1]); |
|---|
| 111 | assert(Droppables.isContained($('d1'), Droppables.drops[0])); |
|---|
| 112 | assert(Droppables.isContained($('d2'), Droppables.drops[0])); |
|---|
| 113 | assert(Droppables.isContained($('d3'), Droppables.drops[0])); |
|---|
| 114 | Droppables.remove('droppable_test'); |
|---|
| 115 | }}, |
|---|
| 116 | |
|---|
| 117 | testDroppablesIsAffected: function() { with(this) { |
|---|
| 118 | Droppables.add('droppable_test'); |
|---|
| 119 | |
|---|
| 120 | Position.prepare(); |
|---|
| 121 | assert(!Droppables.isAffected([-10, -10], null, Droppables.drops[0])); |
|---|
| 122 | |
|---|
| 123 | var p = Position.page($('droppable_test')); |
|---|
| 124 | assert(Droppables.isAffected(p, null, Droppables.drops[0])); |
|---|
| 125 | }} |
|---|
| 126 | |
|---|
| 127 | }, "testlog"); |
|---|
| 128 | // ]]> |
|---|
| 129 | </script> |
|---|
| 130 | </body> |
|---|
| 131 | </html> |
|---|