Files
archie/e2e/checks/workflow-phone-layout.cjs
T

84 lines
5.0 KiB
JavaScript

// The workflow canvas at phone width: no page scroll, a clean topbar, lanes
// inside the canvas, zoom controls below the graph, step and run dialogs
// that fit, YAML without page scroll, and a pinned run header that stays
// visible.
const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot, settled }) => {
await page.setViewportSize({ width: 390, height: 844 });
for (const workflow of ['implement', 'feasibility']) {
await go(`/workflows?workflow=${workflow}`);
const canvas = page.locator('.workflow-canvas');
await canvas.waitFor();
const dimensions = await page.evaluate(() => ({
height: innerHeight, width: innerWidth,
scrollHeight: document.documentElement.scrollHeight,
scrollWidth: document.documentElement.scrollWidth,
}));
assert.equal(dimensions.scrollHeight, dimensions.height, 'workflow page scrolls vertically');
assert.equal(dimensions.scrollWidth, dimensions.width, 'workflow page scrolls horizontally');
const topbar = page.locator('header').first();
const bar = await topbar.boundingBox();
assert.equal(bar.y, 0, 'blank band above topbar');
assert.equal(await topbar.evaluate(el => getComputedStyle(el).backdropFilter), 'none');
assert.ok(!await canvas.getByText('Works on a repository', { exact: true }).count());
const run = page.getByRole('button', { name: new RegExp(`^(Run|Test) ${workflow}$`) });
assert.ok(await run.isVisible(), 'Run hidden on phone');
const box = await canvas.boundingBox();
const start = await page.locator('.vue-flow__node[data-id="start"]').boundingBox();
assert.ok(start.y >= box.y && start.y < box.y + box.height, 'start is outside initial viewport');
const nodes = await page.locator('.vue-flow__node').evaluateAll(elements => elements.map(el => ({
left: el.getBoundingClientRect().left, right: el.getBoundingClientRect().right,
})));
assert.ok(nodes.every(node => node.left >= box.x && node.right <= box.x + box.width), 'branch lanes clipped horizontally');
const controls = await page.getByRole('button', { name: 'Zoom in', exact: true }).boundingBox();
const flow = await canvas.locator('.vue-flow').boundingBox();
assert.ok(controls.y >= flow.y + flow.height, 'zoom control overlays graph');
await shot(workflow);
const step = page.locator('.vue-flow__node').filter({ hasText: 'Prepare worktree' }).first();
assert.equal(await step.locator('[data-slot="badge"]').innerText(), 'Prepare worktree');
await step.click();
const dialog = page.getByRole('dialog');
await dialog.waitFor();
const dialogBox = await dialog.boundingBox();
assert.ok(dialogBox.x >= 0 && dialogBox.x + dialogBox.width <= 390, 'step editor exceeds phone width');
const input = dialog.getByRole('textbox').first();
if (await input.count()) assert.ok(await input.evaluate(el => el.getBoundingClientRect().height) >= 24, 'step form scaled down');
await shot(`${workflow}-step`);
await page.keyboard.press('Escape');
await run.click();
await page.getByRole('dialog').waitFor();
await shot(`${workflow}-run`);
await page.keyboard.press('Escape');
}
// YAML must not make the page scroll at phone width.
await go('/workflows?workflow=feasibility');
await page.getByRole('tab', { name: 'YAML', exact: true }).click();
await settled();
const yamlPage = await page.evaluate(() => ({
scrollHeight: document.documentElement.scrollHeight, height: innerHeight,
}));
assert.equal(yamlPage.scrollHeight, yamlPage.height, 'YAML causes page scroll');
await page.getByRole('tab', { name: 'Canvas', exact: true }).click();
// A pinned historical run keeps its header visible on the canvas.
const response = await page.request.get(new URL('/api/control-plane/resources/workflow-definitions', page.url()).href);
const resource = await response.json();
const snapshot = resource.resource.value.definitions.find(entry => entry.id === 'feasibility').yaml;
await page.route('**/api/tasks?*', route => {
const workflow = new URL(route.request().url()).searchParams.get('workflow');
return workflow === 'feasibility'
? route.fulfill({ json: [{ id: 999999, workflow, title: 'Historical run', status: 'failed', workflow_definition_yaml: snapshot }] })
: route.continue();
});
await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [] }] } }));
await go('/workflows?workflow=feasibility');
const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
await picker.waitFor();
assert.match(await picker.innerText(), /Run #999999/);
const root = await page.locator('.vue-flow__node[data-id="workflow"]').boundingBox();
const pinnedCanvas = await page.locator('.workflow-canvas').boundingBox();
assert.ok(root.y >= pinnedCanvas.y, 'historical workflow header clipped above canvas');
};