From c90e2a337d41e42b0195d84d73d10c33490d0bf8 Mon Sep 17 00:00:00 2001 From: Daniel Karadachki Date: Wed, 27 Mar 2019 17:03:06 +0200 Subject: [PATCH] test: pointercancel --- e2e/draggable.js | 26 +++++++++++++++++++++++++- e2e/pointer-util.js | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/e2e/draggable.js b/e2e/draggable.js index 7cfcb92..c77b76b 100644 --- a/e2e/draggable.js +++ b/e2e/draggable.js @@ -1,5 +1,5 @@ import Draggable from '../src/main'; -import { pointerdown, pointermove, pointerup } from './pointer-util'; +import { pointerdown, pointermove, pointerup, pointercancel } from './pointer-util'; import { aMouseEvent } from './util'; describe('Draggable with Pointer events', () => { @@ -148,6 +148,30 @@ describe('Draggable with Pointer events', () => { expect(handler).toHaveBeenCalledTimes(1); }); + it("does not triggers release on pointerup if not primary", () => { + pointerdown(el, 100, 200); + pointermove(el, 101, 201); + pointerup(el, 101, 201, false); + + expect(handler).not.toHaveBeenCalled(); + }); + + it("triggers release on pointercancel", () => { + pointerdown(el, 100, 200); + pointercancel(el, 101, 201); + pointercancel(el, 101, 201); + + expect(handler).toHaveBeenCalledTimes(1); + }); + + it("does not triggers release on pointercancel if not primary", () => { + pointerdown(el, 100, 200); + pointermove(el, 101, 201); + pointercancel(el, 101, 201, false); + + expect(handler).not.toHaveBeenCalled(); + }); + it("does not trigger release if the element was not pressed", () => { pointerup(el, 100, 200); expect(handler).not.toHaveBeenCalled(); diff --git a/e2e/pointer-util.js b/e2e/pointer-util.js index 168560e..e15c4aa 100644 --- a/e2e/pointer-util.js +++ b/e2e/pointer-util.js @@ -23,3 +23,7 @@ export function pointerup(element, x, y, primary, button) { element.dispatchEvent(pointerEvent("pointerup", x, y, primary)); } +export function pointercancel(element, x, y, primary) { + element.dispatchEvent(pointerEvent("pointercancel", x, y, primary)); +} +