]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Swipe: add test to ensure that it ignores `pinch` events (#35161)
authorGeoSot <geo.sotis@gmail.com>
Tue, 12 Oct 2021 12:48:19 +0000 (15:48 +0300)
committerGitHub <noreply@github.com>
Tue, 12 Oct 2021 12:48:19 +0000 (15:48 +0300)
js/src/util/swipe.js
js/tests/unit/util/swipe.spec.js

index 321572eb8b6cc5a25c79d58757f499eb0255ef58..a78f598d9d96eb83fa8b34846d001b51a59bacaa 100644 (file)
@@ -1,6 +1,7 @@
 import EventHandler from '../dom/event-handler'
 import { execute, typeCheckConfig } from './index'
 
+const NAME = 'swipe'
 const EVENT_KEY = '.bs.swipe'
 const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`
 const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`
@@ -11,7 +12,6 @@ const POINTER_TYPE_TOUCH = 'touch'
 const POINTER_TYPE_PEN = 'pen'
 const CLASS_NAME_POINTER_EVENT = 'pointer-event'
 const SWIPE_THRESHOLD = 40
-const NAME = 'swipe'
 
 const Default = {
   leftCallback: null,
index 5690319ffc9bcf13ea1272d6525d77841edc3627..d6aeb17f6a82d46446e579a0e5f4e7199d5661f9 100644 (file)
@@ -151,6 +151,25 @@ describe('Swipe', () => {
   })
 
   describe('Functionality on PointerEvents', () => {
+    it('should not allow pinch with touch events', () => {
+      Simulator.setType('touch')
+      clearPointerEvents()
+      deleteDocumentElementOntouchstart()
+
+      const swipe = new Swipe(swipeEl)
+      spyOn(swipe, '_handleSwipe')
+
+      mockSwipeGesture(swipeEl, {
+        pos: [300, 10],
+        deltaX: -300,
+        deltaY: 0,
+        touches: 2
+      })
+
+      restorePointerEvents()
+      expect(swipe._handleSwipe).not.toHaveBeenCalled()
+    })
+
     it('should allow swipeRight and call "rightCallback" with pointer events', done => {
       if (!supportPointerEvent) {
         expect().nothing()