/wwwroot/widgets/whiteboard/test_uce.whiteboard.js

http://github.com/AF83/ucengine · JavaScript · 158 lines · 142 code · 16 blank · 0 comment · 0 complexity · 6b2789c043f5256cf9fb58457f76ddc8 MD5 · raw file

  1. module("uce.whiteboard", {teardown: function() {
  2. $('#whiteboard').whiteboard('destroy');
  3. }});
  4. test("create some elements, and destroy", function() {
  5. $('#whiteboard').whiteboard();
  6. equals($('#whiteboard .ui-widget-header-title').text(), 'Whiteboard');
  7. equals($('#whiteboard .ui-widget-content .ui-whiteboard-drawing > canvas').size(), 1);
  8. equals($('#whiteboard .ui-whiteboard-toolbar > *').size(), 8);
  9. ok($('#whiteboard').hasClass('ui-widget'), 'should have class ui-widget');
  10. ok($('#whiteboard').hasClass('ui-whiteboard'), 'should have class ui-whiteboard');
  11. $('#whiteboard').whiteboard('destroy');
  12. equals($('#whiteboard > *').size(), 0);
  13. ok(!$('#whiteboard').hasClass('ui-widget'), 'should have class ui-widget');
  14. ok(!$('#whiteboard').hasClass('ui-whiteboard'), 'should have class ui-whiteboard');
  15. });
  16. test("can set width/height of main canvas on contruct", function() {
  17. $('#whiteboard').whiteboard({width : 200,
  18. height : 150});
  19. equals($('#whiteboard .ui-whiteboard-drawing > canvas').attr("height"), 150);
  20. equals($('#whiteboard .ui-whiteboard-drawing > canvas').attr("width"), 200);
  21. });
  22. test("hide/show controls after init", function() {
  23. $('#whiteboard').whiteboard();
  24. equals($('#whiteboard .ui-whiteboard-toolbar').css('display'), 'block');
  25. $('#whiteboard').whiteboard('hideControls');
  26. equals($('#whiteboard .ui-whiteboard-toolbar').css('display'), 'none');
  27. $('#whiteboard').whiteboard('showControls');
  28. equals($('#whiteboard .ui-whiteboard-toolbar').css('display'), 'block');
  29. });
  30. jackTest("bind event handler", function() {
  31. var ucemeeting = jack.create("ucemeeting", ['on']);
  32. jack.expect("ucemeeting.on")
  33. .exactly("2 times");
  34. $('#whiteboard').whiteboard({ucemeeting: ucemeeting});
  35. });
  36. function emptyCanvas() {
  37. var canvas = document.createElement("canvas");
  38. canvas.setAttribute('height', 240);
  39. canvas.setAttribute('width', 300);
  40. return canvas;
  41. }
  42. jackTest("when performing action, send event to ucengine", function() {
  43. expect(9);
  44. var ucemeeting = jack.create("ucemeeting", ['push', 'on']);
  45. jack.expect("ucemeeting.push")
  46. .exactly("1 time")
  47. .mock(function(type, metadata, callback) {
  48. equals(type, "whiteboard.shape.draw");
  49. ok(metadata.tool);
  50. ok(metadata.color);
  51. ok(metadata.x1);
  52. ok(metadata.y1);
  53. ok(metadata.x2);
  54. ok(metadata.y2);
  55. ok($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  56. emptyCanvas().toDataURL("image/png"), "should be a empty canvas");
  57. });
  58. $('#whiteboard').whiteboard({
  59. ucemeeting : ucemeeting,
  60. width : 300,
  61. height: 240
  62. });
  63. $('#whiteboard canvas').triggerSyn("mousedown", {});
  64. $('#whiteboard canvas').triggerSyn("mousemove", {});
  65. });
  66. jackTest("on clear, send special event to ucengine", function() {
  67. var ucemeeting = jack.create("ucemeeting", ['push', 'on']);
  68. jack.expect("ucemeeting.push")
  69. .exactly("1 time")
  70. .mock(function(type, metadata, callback) {
  71. equals(type, "whiteboard.drawing.clear");
  72. });
  73. $('#whiteboard').whiteboard({
  74. ucemeeting : ucemeeting
  75. });
  76. $('#whiteboard .ui-icon-trash').click();
  77. });
  78. test("handle draw/clear events", function() {
  79. expect(3);
  80. $('#whiteboard').whiteboard({width: 300, height: 240});
  81. ok(($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  82. emptyCanvas().toDataURL("image/png")), "should be a empty canvas");
  83. $('#whiteboard').whiteboard("triggerUceEvent", {type: "whiteboard.shape.draw",
  84. metadata: {'tool': 'pencil',
  85. 'color': '#000000',
  86. 'x1': '1',
  87. 'y1': '1',
  88. 'x2': '2',
  89. 'y2': '2'}});
  90. ok(!($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  91. emptyCanvas().toDataURL("image/png")), "should not be a empty canvas");
  92. $('#whiteboard').whiteboard("triggerUceEvent", {type: "whiteboard.drawing.clear", metadata: {}});
  93. ok(($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  94. emptyCanvas().toDataURL("image/png")), "should be a empty canvas");
  95. });
  96. test("clear method", function() {
  97. $('#whiteboard').whiteboard({width: 300, height: 240});
  98. $('#whiteboard').whiteboard("triggerUceEvent", {type: "whiteboard.shape.draw",
  99. metadata: {'tool': 'pencil',
  100. 'color': '#000000',
  101. 'x1': '1',
  102. 'y1': '1',
  103. 'x2': '2',
  104. 'y2': '2'}});
  105. $('#whiteboard').whiteboard("triggerUceEvent", {type: "whiteboard.drawing.clear", metadata: {}});
  106. ok(($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  107. emptyCanvas().toDataURL("image/png")), "should be a empty canvas");
  108. $('#whiteboard').whiteboard("triggerUceEvent", {type: "whiteboard.shape.draw",
  109. metadata: {'tool': 'pencil',
  110. 'color': '#000000',
  111. 'x1': '1',
  112. 'y1': '1',
  113. 'x2': '2',
  114. 'y2': '2'}});
  115. $('#whiteboard').whiteboard("clear");
  116. ok(($('#whiteboard canvas').get(0).toDataURL("image/png") ==
  117. emptyCanvas().toDataURL("image/png")), "should be a empty canvas");
  118. });
  119. jackTest("when disabled, no event are send to ucengine", function() {
  120. var ucemeeting = jack.create("ucemeeting", ['push', 'on']);
  121. jack.expect("ucemeeting.push")
  122. .exactly("0 time");
  123. $('#whiteboard').whiteboard({
  124. ucemeeting : ucemeeting,
  125. disabled : true
  126. });
  127. $('#whiteboard .ui-icon-trash').click();
  128. $('#whiteboard canvas').triggerSyn("mousedown", {});
  129. $('#whiteboard canvas').triggerSyn("mousemove", {});
  130. });
  131. jackTest("dynanic disabled, no event are send to ucengine", function() {
  132. var ucemeeting = jack.create("ucemeeting", ['push', 'on']);
  133. jack.expect("ucemeeting.push")
  134. .exactly("0 time");
  135. $('#whiteboard').whiteboard({
  136. ucemeeting : ucemeeting
  137. });
  138. $('#whiteboard').whiteboard("option", "disabled", true);
  139. $('#whiteboard .ui-icon-trash').click();
  140. $('#whiteboard canvas').triggerSyn("mousedown", {});
  141. $('#whiteboard canvas').triggerSyn("mousemove", {});
  142. });