OrientationSpec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. describe("Orientation Tests", function() {
  2. var testSlider;
  3. var sliderHandleTopPos;
  4. var sliderHandleLeftPos;
  5. describe("Vertical", function() {
  6. beforeEach(function() {
  7. testSlider = new Slider("#orientationSlider", {
  8. id: "orientationSliderId",
  9. orientation: "vertical",
  10. min: 0,
  11. max: 10,
  12. value: 5
  13. });
  14. var sliderHandleEl = document.querySelector("#orientationSliderId .slider-handle");
  15. var sliderHandleBoundingBoxInfo = sliderHandleEl.getBoundingClientRect();
  16. sliderHandleTopPos = sliderHandleBoundingBoxInfo.top;
  17. sliderHandleLeftPos = sliderHandleBoundingBoxInfo.left;
  18. });
  19. afterEach(function() {
  20. if(testSlider) {
  21. testSlider.destroy();
  22. }
  23. });
  24. it("slides up when handle moves upwards", function() {
  25. var mousemove = document.createEvent('MouseEvents');
  26. var mousemoveX = sliderHandleLeftPos;
  27. var mousemoveY = sliderHandleTopPos - 100;
  28. var newSliderValue;
  29. mousemove.initMouseEvent(
  30. "mousedown",
  31. true /* bubble */,
  32. true /* cancelable */,
  33. window,
  34. null,
  35. 0, 0, mousemoveX, mousemoveY, /* coordinates */
  36. false, false, false, false, /* modifier keys */
  37. 0 /*left*/,
  38. null
  39. );
  40. testSlider.sliderElem.dispatchEvent(mousemove);
  41. newSliderValue = testSlider.getValue();
  42. expect(newSliderValue).toBeLessThan(5);
  43. });
  44. it("slides down when handle moves downwards", function() {
  45. var mousemove = document.createEvent('MouseEvents');
  46. var mousemoveX = sliderHandleLeftPos;
  47. var mousemoveY = sliderHandleTopPos + 100;
  48. var newSliderValue;
  49. mousemove.initMouseEvent(
  50. "mousedown",
  51. true /* bubble */,
  52. true /* cancelable */,
  53. window,
  54. null,
  55. 0, 0, mousemoveX, mousemoveY, /* coordinates */
  56. false, false, false, false, /* modifier keys */
  57. 0 /*left*/,
  58. null
  59. );
  60. testSlider.sliderElem.dispatchEvent(mousemove);
  61. newSliderValue = testSlider.getValue();
  62. expect(newSliderValue).toBeGreaterThan(5);
  63. });
  64. });
  65. }); // End of spec