123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- describe("Scrollable body test", function() {
- var testSlider;
- var sliderHandleTopPos;
- var sliderHandleLeftPos;
- describe("Vertical scrolled body", function() {
- beforeEach(function() {
- testSlider = new Slider("#veryLowPositionedSlider", {
- id: "scrollTestSliderId",
- orientation: "vertical",
- min: 0,
- max: 20,
- value: 10,
- step: 1
- });
- document.body.scrollTop = 2000;
- var sliderHandleEl = document.querySelector("#scrollTestSliderId .slider-handle");
- var sliderHandleBoundingBoxInfo = sliderHandleEl.getBoundingClientRect();
- sliderHandleTopPos = sliderHandleBoundingBoxInfo.top;
- sliderHandleLeftPos = sliderHandleBoundingBoxInfo.left;
- });
- afterEach(function() {
- if(testSlider) {
- testSlider.destroy();
- }
- document.body.scrollTop = 0;
- });
- // The difference between sliderHandleTopPos and mousemoveY is equal to 50 in both cases,
- // but difference between initial and final slider value is not equal (6 and 4).
- // It happens because we don't 'hit' the center of handle but the top left corner.
- it("slides up when handle moves upwards after scroll page down", function() {
- var mousemove = document.createEvent('MouseEvents');
- var mousemoveX = sliderHandleLeftPos;
- var mousemoveY = sliderHandleTopPos - 50;
- var newSliderValue;
- mousemove.initMouseEvent(
- "mousedown",
- true /* bubble */,
- true /* cancelable */,
- window,
- null,
- 0, 0, mousemoveX, mousemoveY, /* coordinates */
- false, false, false, false, /* modifier keys */
- 0 /*left*/,
- null
- );
- testSlider.sliderElem.dispatchEvent(mousemove);
- newSliderValue = testSlider.getValue();
- expect(newSliderValue).toEqual(4);
- });
- it("slides down when handle moves downwards after scroll page down", function() {
- var mousemove = document.createEvent('MouseEvents');
- var mousemoveX = sliderHandleLeftPos;
- var mousemoveY = sliderHandleTopPos + 50;
- var newSliderValue;
- mousemove.initMouseEvent(
- "mousedown",
- true /* bubble */,
- true /* cancelable */,
- window,
- null,
- 0, 0, mousemoveX, mousemoveY, /* coordinates */
- false, false, false, false, /* modifier keys */
- 0 /*left*/,
- null
- );
- testSlider.sliderElem.dispatchEvent(mousemove);
- newSliderValue = testSlider.getValue();
- expect(newSliderValue).toEqual(14);
- });
- });
- describe('Horizontal scrolled body', function() {
- beforeEach(function() {
- testSlider = new Slider('#offRightEdgeSliderInput', {
- id: 'offRightEdgeSlider',
- orientation: 'horizontal',
- min: 0,
- max: 20,
- value: 10,
- step: 1,
- });
- testSlider.sliderElem.scrollIntoView();
- var handle = document.querySelector('#offRightEdgeSlider .slider-handle');
- var handleRect = handle.getBoundingClientRect();
- sliderHandleTopPos = handleRect.top;
- sliderHandleLeftPos = handleRect.left;
- });
- afterEach(function() {
- if (testSlider) {
- testSlider.destroy();
- }
- window.scrollTo(0, 0);
- });
- it('slides left when clicked on the left of the handle', function() {
- var x = sliderHandleLeftPos - 50;
- var y = sliderHandleTopPos;
- var mousedown, newSliderValue;
- mousedown = createMouseDownEvent(x, y);
- testSlider.sliderElem.dispatchEvent(mousedown);
- newSliderValue = testSlider.getValue();
- expect(newSliderValue).toEqual(4);
- });
- it('slides right when clicked on the left of the handle', function() {
- var x = sliderHandleLeftPos + 50;
- var y = sliderHandleTopPos;
- var mousedown, newSliderValue;
- mousedown = createMouseDownEvent(x, y);
- testSlider.sliderElem.dispatchEvent(mousedown);
- newSliderValue = testSlider.getValue();
- expect(newSliderValue).toEqual(14);
- });
- function createMouseDownEvent(x, y) {
- var mousedown = document.createEvent('MouseEvents');
- mousedown.initMouseEvent(
- 'mousedown',
- false /* bubble */,
- true /* cancelable */,
- window, /* view */
- null, /* detail */
- 0, 0, x, y, /* coordinates */
- false, false, false, false, /* modifier keys */
- 0, /* button: left */
- null /* relatedTarget */
- );
- return mousedown;
- }
- });
- });
|