diff options
author | Johann-S <johann.servoire@gmail.com> | 2018-10-14 14:59:51 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2018-10-20 15:32:09 +0300 |
commit | c08652cfe84051184570d704d3a0904e8d01358c (patch) | |
tree | 789d1a191cfd9fbc6632b564d756eae42cf9cd40 /js/tests | |
parent | caefd7046372e954d21550bbdadcabf98b2a86f0 (diff) |
swipe left/right without hammerjs
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/index.html | 1 | ||||
-rw-r--r-- | js/tests/karma.conf.js | 11 | ||||
-rw-r--r-- | js/tests/unit/carousel.js | 73 | ||||
-rw-r--r-- | js/tests/visual/carousel.html | 1 |
4 files changed, 36 insertions, 50 deletions
diff --git a/js/tests/index.html b/js/tests/index.html index 201e15f2a8..1bcdc5380e 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -20,7 +20,6 @@ }()) </script> <script src="../../node_modules/popper.js/dist/umd/popper.min.js"></script> - <script src="../../node_modules/hammerjs/hammer.min.js"></script> <!-- QUnit --> <link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css" media="screen"> diff --git a/js/tests/karma.conf.js b/js/tests/karma.conf.js index c3c64e8850..807f977d96 100644 --- a/js/tests/karma.conf.js +++ b/js/tests/karma.conf.js @@ -12,16 +12,16 @@ const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery- const bundle = process.env.BUNDLE === 'true' const browserStack = process.env.BROWSER === 'true' -const plugins = [ - 'karma-qunit', - 'karma-sinon' -] - const frameworks = [ 'qunit', 'sinon' ] +const plugins = [ + 'karma-qunit', + 'karma-sinon' +] + const reporters = ['dots'] const detectBrowsers = { @@ -48,7 +48,6 @@ const customLaunchers = { let files = [ 'node_modules/popper.js/dist/umd/popper.min.js', - 'node_modules/hammerjs/hammer.min.js', 'node_modules/hammer-simulator/index.js' ] diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 0bc52219e4..e416ab20e4 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -3,8 +3,6 @@ $(function () { window.Carousel = typeof bootstrap !== 'undefined' ? bootstrap.Carousel : Carousel - var touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0 - QUnit.module('carousel plugin') QUnit.test('should be defined on jQuery object', function (assert) { @@ -1009,13 +1007,8 @@ $(function () { }) QUnit.test('should allow swiperight and call prev', function (assert) { - if (!touchSupported) { - assert.expect(0) - - return - } - - assert.expect(2) + Simulator.setType('touch') + assert.expect(3) var done = assert.async() document.documentElement.ontouchstart = $.noop @@ -1035,10 +1028,13 @@ $(function () { $carousel.appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() + var carousel = $carousel.data('bs.carousel') + var spy = sinon.spy(carousel, 'prev') $carousel.one('slid.bs.carousel', function () { assert.ok(true, 'slid event fired') assert.ok($item.hasClass('active')) + assert.ok(spy.called) delete document.documentElement.ontouchstart done() }) @@ -1049,40 +1045,10 @@ $(function () { }) }) - QUnit.test('should not use HammerJS when touch option is false', function (assert) { - assert.expect(1) - - var $carousel = $('<div></div>').appendTo('#qunit-fixture') - $carousel.bootstrapCarousel({ - touch: false - }) - - var carousel = $carousel.data('bs.carousel') - - assert.strictEqual(carousel.hammer, null) - }) - - QUnit.test('should use HammerJS when touch option is true', function (assert) { - assert.expect(1) - - document.documentElement.ontouchstart = $.noop - - var $carousel = $('<div></div>').appendTo('#qunit-fixture') - $carousel.bootstrapCarousel() - - var carousel = $carousel.data('bs.carousel') - - assert.ok(carousel.hammer !== null) - }) - QUnit.test('should allow swipeleft and call next', function (assert) { - if (!touchSupported) { - assert.expect(0) - - return - } + assert.expect(3) + Simulator.setType('touch') - assert.expect(2) var done = assert.async() document.documentElement.ontouchstart = $.noop @@ -1102,11 +1068,13 @@ $(function () { $carousel.appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() + var carousel = $carousel.data('bs.carousel') + var spy = sinon.spy(carousel, 'next') $carousel.one('slid.bs.carousel', function () { assert.ok(true, 'slid event fired') assert.ok(!$item.hasClass('active')) - delete document.documentElement.ontouchstart + assert.ok(spy.called) done() }) @@ -1116,4 +1084,25 @@ $(function () { deltaY: 0 }) }) + + QUnit.test('should not allow pinch', function (assert) { + assert.expect(0) + Simulator.setType('touch') + var done = assert.async() + document.documentElement.ontouchstart = $.noop + + var carouselHTML = '<div class="carousel" data-interval="false"></div>' + var $carousel = $(carouselHTML) + $carousel.appendTo('#qunit-fixture') + $carousel.bootstrapCarousel() + + Simulator.gestures.swipe($carousel[0], { + pos: [300, 10], + deltaX: -300, + deltaY: 0, + touches: 2 + }, function () { + done() + }) + }) }) diff --git a/js/tests/visual/carousel.html b/js/tests/visual/carousel.html index cd917caa62..630f870cf4 100644 --- a/js/tests/visual/carousel.html +++ b/js/tests/visual/carousel.html @@ -46,7 +46,6 @@ </div> <script src="../../../site/docs/4.1/assets/js/vendor/jquery-slim.min.js"></script> - <script src="../../../node_modules/hammerjs/hammer.min.js"></script> <script src="../../dist/util.js"></script> <script src="../../dist/carousel.js"></script> <script> |