dragdrop_test.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. </head>
  17. <body>
  18. <h1>script.aculo.us Unit test file</h1>
  19. <p>
  20. Test of drag &amp; drop functions in dragdrop.js
  21. </p>
  22. <!-- Log output -->
  23. <div id="testlog"> </div>
  24. <p id="p_test">p_test</p>
  25. <p id="p_test2">p_test2</p>
  26. <p id="p_test3">p_test3</p>
  27. <img id="img_test" src="icon.png" alt="img_text"/>
  28. <div id="droppable_test">droppable_test</div>
  29. <div id="div_test">div_test</div>
  30. <div id="div_absolute_test">div_absolute_test</div>
  31. <div id="div_absolute_inline_test" style="position:absolute">div_absolute_inline_test</div>
  32. <div id="droppable_container">
  33. <div id="d1">droppable_test</div>
  34. <div id="d2">droppable_test</div>
  35. </div>
  36. <div id="droppable_container_2">
  37. <div id="d3">droppable_test</div>
  38. </div>
  39. <!-- Tests follow -->
  40. <script type="text/javascript" language="javascript" charset="utf-8">
  41. // <![CDATA[
  42. new Test.Unit.Runner({
  43. testDraggableBasics: function() { with(this) {
  44. var d = new Draggable('p_test');
  45. assertInstanceOf(Draggable, d);
  46. }},
  47. testDraggableStartEffect: function() { with(this) {
  48. var d = new Draggable('p_test2');
  49. assert(d.options.starteffect, 'There should be a default start effect.');
  50. d = new Draggable('p_test3', { endeffect: Prototype.EmptyFunction });
  51. assert(undefined === d.options.startEffect, 'There should be no default start effect.');
  52. }},
  53. testAutoPositioning: function() { with(this) {
  54. assertEqual('static', Element.getStyle('div_test','position'));
  55. new Draggable('div_test');
  56. new Draggable('div_absolute_test');
  57. new Draggable('div_absolute_inline_test');
  58. assertEqual('relative', Element.getStyle('div_test','position'));
  59. assertEqual('absolute', Element.getStyle('div_absolute_test','position'));
  60. assertEqual('absolute', Element.getStyle('div_absolute_inline_test','position'));
  61. }},
  62. testDroppbalesBasics: function() { with(this) {
  63. assertEqual(0, Droppables.drops.length);
  64. assertEqual('static', Element.getStyle('droppable_test','position'));
  65. Droppables.add('droppable_test');
  66. assertEqual(1, Droppables.drops.length);
  67. assertEqual('relative', Element.getStyle('droppable_test','position'));
  68. Droppables.remove('droppable_test');
  69. assertEqual(0, Droppables.drops.length);
  70. // accept option should take strings or array of strings
  71. Droppables.add('droppable_test',{accept:'document'});
  72. assertEqual(['document'].inspect(), Droppables.drops[0].accept.inspect());
  73. Droppables.remove('droppable_test');
  74. Droppables.add('droppable_test',{accept:['document','image']});
  75. assertEqual(['document','image'].inspect(), Droppables.drops[0].accept.inspect());
  76. Droppables.remove('droppable_test');
  77. }},
  78. testDroppableContainment: function() { with(this) {
  79. // Droppable containers should be cached
  80. Droppables.add('droppable_test', {
  81. containment:'droppable_container' });
  82. assertEqual(1, Droppables.drops[0]._containers.length);
  83. assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]);
  84. assert(Droppables.isContained($('d1'), Droppables.drops[0]));
  85. assert(Droppables.isContained($('d2'), Droppables.drops[0]));
  86. assert(!Droppables.isContained($('d3'), Droppables.drops[0]));
  87. Droppables.remove('droppable_test');
  88. Droppables.add('droppable_test', {
  89. containment:['droppable_container','droppable_container_2'] });
  90. assertEqual(2, Droppables.drops[0]._containers.length);
  91. assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]);
  92. assertEqual($('droppable_container_2'), Droppables.drops[0]._containers[1]);
  93. assert(Droppables.isContained($('d1'), Droppables.drops[0]));
  94. assert(Droppables.isContained($('d2'), Droppables.drops[0]));
  95. assert(Droppables.isContained($('d3'), Droppables.drops[0]));
  96. Droppables.remove('droppable_test');
  97. }},
  98. testDroppablesIsAffected: function() { with(this) {
  99. Droppables.add('droppable_test');
  100. Position.prepare();
  101. assert(!Droppables.isAffected([-10, -10], null, Droppables.drops[0]));
  102. var p = Position.page($('droppable_test'));
  103. assert(Droppables.isAffected(p, null, Droppables.drops[0]));
  104. }}
  105. }, "testlog");
  106. // ]]>
  107. </script>
  108. </body>
  109. </html>