-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug when click happens on touch device
- Loading branch information
1 parent
1773bc4
commit 3e67ada
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, it, beforeAll, afterAll, expect } from 'vitest' | ||
import type { Page } from 'puppeteer' | ||
import { | ||
getPage, | ||
getResultAfter, | ||
getTouchCollection, | ||
type InPageEventListener, | ||
type EventListenerAdder, | ||
type TouchCollection, | ||
ensureNoError | ||
} from './utils' | ||
|
||
describe('when a click happens in a touch way', () => { | ||
let page: Page; | ||
let cleanup: () => Promise<void>; | ||
let addEventListenerInPage: EventListenerAdder; | ||
let touchCollection: TouchCollection; | ||
let clicked: InPageEventListener<MouseEvent> | ||
|
||
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(); | ||
}) | ||
}) |