From 3e67adac5d4f907a0537f79f9bc246ee346d521f Mon Sep 17 00:00:00 2001 From: Emile Fokkema Date: Sat, 5 Oct 2024 21:18:56 +0200 Subject: [PATCH] fix bug when click happens on touch device --- .../handled-or-filtered-event-collection.ts | 3 ++ test-e2e/touch-click-bug.spec.ts | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test-e2e/touch-click-bug.spec.ts diff --git a/src/events/event-collections/handled-or-filtered-event-collection.ts b/src/events/event-collections/handled-or-filtered-event-collection.ts index 3ef82498..a6dc1242 100644 --- a/src/events/event-collections/handled-or-filtered-event-collection.ts +++ b/src/events/event-collections/handled-or-filtered-event-collection.ts @@ -201,6 +201,9 @@ export class HandledOrFilteredEventCollection extends BaseEventCollection { + let page: Page; + let cleanup: () => Promise; + let addEventListenerInPage: EventListenerAdder; + let touchCollection: TouchCollection; + let clicked: InPageEventListener + + beforeAll(async () => { + ({page, cleanup, addEventListenerInPage} = await getPage()); + const infCanvas = await page.evaluateHandle(() => window.TestPageLib.initializeInfiniteCanvas({ + styleWidth: '400px', + styleHeight: '400px', + canvasWidth: 400, + canvasHeight: 400, + spaceBelowCanvas: 2000, + drawing: (ctx: any) => { + ctx.fillRect(10, 10, 100, 100) + } + })) + touchCollection = await getTouchCollection(page); + clicked = await addEventListenerInPage(infCanvas, 'click'); + }) + + it('should send a click event and throw no error', async () => { + const [{offsetX}] = await getResultAfter(async () => { + const touch = await touchCollection.start(200, 200); + touch.end(); + }, [ + () => clicked.getNext(), + () => ensureNoError(page, 500) + ] as const) + expect(offsetX).toEqual(200) + }) + + afterAll(async () => { + await cleanup(); + }) +}) \ No newline at end of file