StepReachMaxValueSpec.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. describe("TickMaxValueNotATickBehavior", function() {
  2. var SLIDER_ID = "testSlider1";
  3. var slider;
  4. var options;
  5. describe('max value should be reached', function() {
  6. beforeEach(function() {
  7. options = {
  8. min: 40,
  9. max: 1310,
  10. step: 5,
  11. scale: "logarithmic",
  12. value: 44
  13. };
  14. slider = new Slider(document.getElementById(SLIDER_ID), options);
  15. });
  16. it("Value should contain max value when slider is moved to outer right position", function() {
  17. var sliderLeft = slider.sliderElem.offsetLeft;
  18. var offsetY = slider.sliderElem.offsetTop;
  19. // I think the + 10 work because it is half of the handle size;
  20. var offsetX = sliderLeft + slider.sliderElem.clientWidth + 10;
  21. var expectedValue = slider.options.max;
  22. var mouseEvent = getMouseDownEvent(offsetX, offsetY);
  23. slider.mousedown(mouseEvent);
  24. // FIXME: Use 'mouseup' event type
  25. slider.mouseup(mouseEvent);
  26. expect(slider.getValue()).toBe(expectedValue);
  27. });
  28. });
  29. afterEach(function() {
  30. slider.destroy();
  31. });
  32. // helper functions
  33. function getMouseDownEvent(offsetXToClick, offsetYToClick) {
  34. var args = [
  35. 'mousedown', // type
  36. true, // canBubble
  37. true, // cancelable
  38. document, // view,
  39. 0, // detail
  40. 0, // screenX
  41. 0, // screenY
  42. offsetXToClick, // clientX
  43. offsetYToClick, // clientY,
  44. false, // ctrlKey
  45. false, // altKey
  46. false, // shiftKey
  47. false, // metaKey,
  48. 0, // button
  49. null // relatedTarget
  50. ];
  51. var event = document.createEvent('MouseEvents');
  52. event.initMouseEvent.apply(event, args);
  53. return event;
  54. }
  55. });