mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-24 01:50:04 +08:00
* feat(screen): accept percent points in tapAt, doubleTapAt, and swipe
A coordinate may be a percentage of the viewport ('0%' to '100%') as well as
CSS pixels, as in Maestro's `point: "50%,50%"`. Numbers stay pixels, and
`Point` stays pixels for `tap({ position })`, the agent, and the engine
contract.
A percent point costs one screen read inside the action's timeout, then
resolves to whole pixels, '100%' landing on the last one. Pixel points skip
the read. The step label keeps the point as written.
* test(screen): cover percent points in tapAt, doubleTapAt, and swipe
* docs(screen): document percent points for tapAt, doubleTapAt, and swipe
* chore: add a changeset for percent points
* docs(screen): say percent points round to the nearest pixel
* refactor(screen): resolve percent points through one helper
* test(screen): check a pixel swipe skips the screen read
* docs(screen): say a percent point reads the screen once
104 lines
4.7 KiB
TypeScript
104 lines
4.7 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('screen.tapAt and screen.swipe take percentages of the viewport', { requires: ['browser'] }, async ({ app, browser, screen }) => {
|
|
await browser.setViewport({ width: 1000, height: 800 });
|
|
await app.open('/pointer');
|
|
const box = await boxOf(screen.getByRole('image', 'Pointer pad'));
|
|
const onPad = (x: number, y: number) => `${Math.round(x - box.x)},${Math.round(y - box.y)}`;
|
|
|
|
await screen.tapAt({ x: '10%', y: '25%' });
|
|
await expect(screen.getByLabel('Pad state')).toHaveText(`tapped at ${onPad(100, 200)}`);
|
|
|
|
await screen.swipe({ from: { x: '10%', y: '25%' }, to: { x: '30%', y: 200 } });
|
|
await expect(screen.getByLabel('Pad state')).toHaveText(`swiped from ${onPad(100, 200)} to ${onPad(300, 200)}`);
|
|
});
|
|
|
|
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');
|
|
});
|