From 6110dc5ab073fd8f84cc5260cb770680202bde43 Mon Sep 17 00:00:00 2001 From: Jeffrey Espiritu Date: Wed, 13 Feb 2019 21:10:13 -0500 Subject: [PATCH] touch: Add scrolling tests --- test/specs/TouchCapableSpec.js | 88 ++++++++++++++++++++++++++++++++++ tpl/SpecRunner.tpl | 20 ++++++++ 2 files changed, 108 insertions(+) diff --git a/test/specs/TouchCapableSpec.js b/test/specs/TouchCapableSpec.js index 97acf2bc..01e8dc31 100644 --- a/test/specs/TouchCapableSpec.js +++ b/test/specs/TouchCapableSpec.js @@ -480,4 +480,92 @@ describe("Touch Capable Tests", function() { }); + describe("Scrolling tests", function() { + + describe("horizontal sliding tests", function() { + var horzScrollDiv; + + beforeEach(function() { + // Initialize the slider + $testSlider = $('#' + inputId).slider(sliderOptions); + + // Get slider instance + sliderInst = $testSlider.data('slider'); + + horzScrollDiv = document.getElementById('horz-scroll-div'); + }); + + // index= [0 1 2 3 4] + // ticks= [0 3 5 7 10] + it("should not scroll the div horizontally while sliding the slider", function(done) { + var sliderElem = $testSlider.slider('getElement'); + + $testSlider.on('slideStop', function() { + expect(horzScrollDiv.scrollLeft).toBe(0); + done(); + }); + + var tick = sliderInst.ticks[2]; // 5 + var sliderCoords = calcTouchEventCoords(sliderElem); + var coords = [sliderCoords.x + tick.offsetLeft, sliderCoords.y]; + touchStart = createTouchEvent(sliderElem, 'touchstart', coords); + + tick = sliderInst.ticks[3]; // 7 + coords = [sliderCoords.x + tick.offsetLeft, sliderCoords.y]; + touchMove = createTouchEvent(sliderElem, 'touchmove', coords); + + touchEnd = createTouchEvent(sliderElem, 'touchend', coords); + + sliderElem.dispatchEvent(touchStart); + sliderElem.dispatchEvent(touchMove); + sliderElem.dispatchEvent(touchEnd); + }); + + }); + + describe("vertical sliding tests", function() { + var vertScrollDiv; + + beforeEach(function() { + sliderOptions.orientation = 'vertical'; + + // Initialize the slider + $testSlider = $('#' + inputId).slider(sliderOptions); + + // Get slider instance + sliderInst = $testSlider.data('slider'); + + vertScrollDiv = document.getElementById('vert-scroll-div'); + }); + + // index= [0 1 2 3 4] + // ticks= [0 3 5 7 10] + it("should not scroll the div vertically while sliding the slider", function(done) { + var sliderElem = $testSlider.slider('getElement'); + + $testSlider.on('slideStop', function() { + expect(vertScrollDiv.scrollTop).toBe(0); + done(); + }); + + var tick = sliderInst.ticks[2]; // 5 + var sliderCoords = calcTouchEventCoords(sliderElem); + var coords = [sliderCoords.x + tick.offsetLeft, sliderCoords.y]; + touchStart = createTouchEvent(sliderElem, 'touchstart', coords); + + tick = sliderInst.ticks[3]; // 7 + coords = [sliderCoords.x + tick.offsetLeft, sliderCoords.y]; + touchMove = createTouchEvent(sliderElem, 'touchmove', coords); + + touchEnd = createTouchEvent(sliderElem, 'touchend', coords); + + sliderElem.dispatchEvent(touchStart); + sliderElem.dispatchEvent(touchMove); + sliderElem.dispatchEvent(touchEnd); + }); + + }); + + }); + }); \ No newline at end of file diff --git a/tpl/SpecRunner.tpl b/tpl/SpecRunner.tpl index af1b1b06..f2b497e3 100644 --- a/tpl/SpecRunner.tpl +++ b/tpl/SpecRunner.tpl @@ -26,6 +26,16 @@ padding: 2000px 0 500px 0; } + #horz-scroll-div { + overflow-x: scroll; + width: 300px; + height: 150px; + } + #vert-scroll-div { + overflow-y: scroll; + width: 150px; + height: 300px; + } @@ -96,6 +106,16 @@ +
+ +
Text
+
+ +
+ +
More text
+
+