mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-22 18:19:48 +08:00
* feat(web): add coordinate double-click to browser mouse * test: handle Unicode checkout paths in hosted-session fixtures * test(web): simplify double-click regressions after review * feat(e2e): add screen.doubleTapAt for viewport gestures
91 lines
4.0 KiB
TypeScript
91 lines
4.0 KiB
TypeScript
import { test } from '@e2e-dev/web';
|
|
import { expect } from 'e2e';
|
|
import { boxOf, centerOf, failure } from './helpers.ts';
|
|
|
|
test('screen.tapAt taps a viewport point with no node behind it', async ({ app, screen }) => {
|
|
await app.open('/pointer');
|
|
|
|
const box = await boxOf(screen.getByRole('image', 'Pointer pad'));
|
|
await screen.tapAt({ x: box.x + 40, y: box.y + 30 });
|
|
|
|
await expect(screen.getByLabel('Pad state')).toHaveText('tapped at 40,30');
|
|
});
|
|
|
|
test('locator.tap({ position }) taps at an offset of the node', async ({ app, screen }) => {
|
|
await app.open('/pointer');
|
|
const pad = screen.getByRole('image', 'Pointer pad');
|
|
|
|
await pad.tap({ position: { x: 300, y: 10 } });
|
|
await expect(screen.getByLabel('Pad state')).toHaveText('tapped at 300,10');
|
|
|
|
await pad.click({ position: { x: 0, y: 0 } });
|
|
await expect(screen.getByLabel('Pad state')).toHaveText('tapped at 0,0');
|
|
});
|
|
|
|
test('a position tap on a node the engine cannot bring into view fails as the engine reports', async ({ app, screen }) => {
|
|
await app.open('/pointer');
|
|
|
|
expect(
|
|
await failure(() => screen.getByLabel('Hidden pad').tap({ position: { x: 1, y: 1 }, timeout: 1_000 })),
|
|
).toHaveProperty('code', 'ACTION_FAILED');
|
|
});
|
|
|
|
test('screen.swipe({ from, to }) moves the pointer along the path', async ({ app, screen }) => {
|
|
await app.open('/pointer');
|
|
|
|
const box = await boxOf(screen.getByRole('image', 'Pointer pad'));
|
|
await screen.swipe({ from: { x: box.x + 10, y: box.y + 20 }, to: { x: box.x + 250, y: box.y + 20 } });
|
|
|
|
await expect(screen.getByLabel('Pad state')).toHaveText('swiped from 10,20 to 250,20');
|
|
});
|
|
|
|
test('a path swipe drags and drops on the board', async ({ app, screen }) => {
|
|
await app.open('/board');
|
|
|
|
const card = centerOf(await boxOf(screen.getByText('Design review', { exact: true })));
|
|
const done = centerOf(await boxOf(screen.getByLabel('Done column')));
|
|
await screen.swipe({ from: card, to: done });
|
|
|
|
await expect(screen.getByLabel('Board state')).toHaveText('Design review is done');
|
|
});
|
|
|
|
test.describe('raw pointer input', { requires: ['browser'] }, () => {
|
|
test('raw mouse input drags along the pad', async ({ app, screen, browser }) => {
|
|
await app.open('/pointer');
|
|
const box = await boxOf(screen.getByRole('image', 'Pointer pad'));
|
|
|
|
await browser.mouse.move(box.x + 10, box.y + 20);
|
|
await browser.mouse.down();
|
|
await browser.mouse.move(box.x + 150, box.y + 20);
|
|
await browser.mouse.up();
|
|
await expect(screen.getByLabel('Pad state')).toHaveText('swiped from 10,20 to 150,20');
|
|
});
|
|
});
|
|
|
|
test('screen.doubleTapAt edits a label beneath a sibling SVG', { requires: ['browser'] }, async ({ app, browser, screen }) => {
|
|
await app.open('/pointer');
|
|
const label = screen.getByRole('textbox', 'Edit label');
|
|
const point = centerOf(await boxOf(label));
|
|
const hit = await browser.evaluate(({ x, y }: { x: number; y: number }) => {
|
|
const node = document.querySelector<HTMLElement>('#diagram-node')!;
|
|
node.dataset['events'] = '';
|
|
for (const type of ['mousedown', 'mouseup', 'click', 'dblclick'] as const) {
|
|
node.addEventListener(type, (event) => {
|
|
node.dataset['events'] += `${event.type}|${event.isTrusted}|${event.button}|${event.detail}|${event.clientX},${event.clientY};`;
|
|
});
|
|
}
|
|
const target = document.elementFromPoint(x, y);
|
|
return { tag: target?.localName ?? null, node: target?.closest('#diagram-node')?.id ?? null };
|
|
}, { x: point.x, y: point.y });
|
|
expect(hit).toEqual({ tag: 'path', node: 'diagram-node' });
|
|
await screen.doubleTapAt(point);
|
|
const events = await browser.evaluate(() => document.querySelector<HTMLElement>('#diagram-node')!.dataset['events'] ?? '');
|
|
const at = `${Math.round(point.x)},${Math.round(point.y)}`;
|
|
expect(events).toBe(
|
|
`mousedown|true|0|1|${at};mouseup|true|0|1|${at};click|true|0|1|${at};` +
|
|
`mousedown|true|0|2|${at};mouseup|true|0|2|${at};click|true|0|2|${at};dblclick|true|0|2|${at};`,
|
|
);
|
|
await label.fill('Renamed');
|
|
await expect(label).toHaveValue('Renamed');
|
|
});
|