Files
crank/apps/ui/tests/e2e/onboarding-shell-layout.spec.js
T
bsodfather 249b777bec
CI / Rust Checks (pull_request) Successful in 22m46s
CI / UI Checks (pull_request) Successful in 6s
CI / Frontend E2E (pull_request) Successful in 11m48s
CI / Community Image Smoke (pull_request) Successful in 13m42s
CI / Deploy (pull_request) Skipped
Исправить перекрытие навигации и обновить пакеты образов
2026-10-09 19:13:02 +03:00

156 lines
5.7 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const { getCurrentWorkspace, login } = require('./helpers');
function onboardingSnapshot(workspaceId) {
return {
schema_version: 1,
workspace_id: workspaceId,
revision: 1,
status: 'in_progress',
dismissed: false,
eligible_since: '2026-08-23T08:00:00Z',
started_at: '2026-08-23T08:01:00Z',
completed_at: null,
steps: [
{ kind: 'operation', status: 'complete', action: 'open_operation' },
{ kind: 'test', status: 'complete', action: 'open_operation' },
{ kind: 'publish', status: 'complete', action: 'open_operation' },
{ kind: 'agent', status: 'current', action: 'create_agent' },
{ kind: 'key', status: 'pending', action: 'create_key' },
{ kind: 'connection', status: 'pending', action: 'show_connection' },
{ kind: 'first_call', status: 'pending', action: 'open_logs' },
],
operation: { id: 'op_shell_layout', published_version: 1, last_test: null },
agent: null,
key: null,
connection: { status: 'pending', reason_code: 'key_required' },
first_call: null,
};
}
function rectsIntersect(a, b) {
return a.x < b.x + b.width
&& a.x + a.width > b.x
&& a.y < b.y + b.height
&& a.y + a.height > b.y;
}
async function openShellLayoutCase(page, path) {
await login(page);
const workspace = await getCurrentWorkspace(page);
await page.route(/\/api\/admin\/workspaces\/[^/]+\/onboarding(?:\/events)?(?:\?.*)?$/, async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(onboardingSnapshot(workspace.id)),
});
});
await page.goto(path);
// Open the full server-derived Getting Started panel explicitly. The panel is
// auto-opened for a fresh workspace, but the trigger is used when a previous
// navigation already persisted the "opened" UI preference.
const trigger = page.getByTestId('onboarding-trigger');
const checklist = page.getByTestId('onboarding-checklist');
if (!await checklist.isVisible()) await trigger.click();
await expect(checklist).toBeVisible();
await expect(checklist.locator('ol > li')).toHaveCount(7);
const avatar = page.getByTestId('shell-avatar');
await expect(avatar).toBeVisible();
const navbar = page.locator('.navbar');
const navbarBox = await navbar.boundingBox();
const avatarBox = await avatar.boundingBox();
const panelBox = await checklist.boundingBox();
// Real hit-testing at the avatar centre: whatever would receive the pointer
// event must be the avatar itself, not the onboarding panel or its head.
// Playwright's click actionability uses exactly this condition, so this is
// the deterministic equivalent of the CI830 shell-avatar.click interception.
const avatarCentre = {
x: avatarBox.x + avatarBox.width / 2,
y: avatarBox.y + avatarBox.height / 2,
};
const hit = await page.evaluate((centre) => {
const element = document.elementFromPoint(centre.x, centre.y);
if (!element) return null;
const owner = element.closest('[data-testid="shell-avatar"]');
return {
isAvatar: Boolean(owner),
tag: element.tagName,
className: String(element.className || ''),
testId: element.getAttribute('data-testid'),
};
}, avatarCentre);
console.log('shell-layout geometry', JSON.stringify({
path,
viewport: page.viewportSize(),
navbar: navbarBox,
avatar: avatarBox,
avatarCentre,
panel: panelBox,
hit,
}));
expect(hit, `no element at avatar centre ${JSON.stringify(avatarCentre)}`).not.toBeNull();
expect(
hit.isAvatar,
`avatar centre ${JSON.stringify(avatarCentre)} is covered by ${JSON.stringify(hit)}`,
).toBe(true);
// The sticky header owns the top of the viewport; an optional helper panel
// must never overlap it.
expect(
rectsIntersect(panelBox, navbarBox),
`onboarding panel ${JSON.stringify(panelBox)} overlaps header ${JSON.stringify(navbarBox)}`,
).toBe(false);
// A single real (non-forced) click on the avatar must open the shell user menu.
await avatar.click();
await expect(page.getByTestId('shell-user-name').first()).toBeVisible();
const settings = page.locator('.user-dropdown-item').first();
await expect.poll(() => settings.evaluate((element) => {
const box = element.getBoundingClientRect();
const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2);
return element === hit || element.contains(hit);
})).toBe(true);
await settings.click();
await expect(page).toHaveURL(/\/settings(?:#profile)?$/);
if (page.viewportSize().width <= 640) {
await page.goto(path);
if (!await checklist.isVisible()) await trigger.click();
await expect(checklist).toBeVisible();
await expect(checklist.locator('ol > li')).toHaveCount(7);
const hamburger = page.locator('.nav-hamburger');
await hamburger.focus();
await hamburger.press('Enter');
await expect(hamburger).toBeFocused();
const mobileNavigation = page.locator('.mobile-nav');
await expect(mobileNavigation).toBeVisible();
await mobileNavigation.locator('a[href="/agents"]').click();
await expect(page).toHaveURL(/\/agents\/?$/);
}
}
const CASES = [
{ path: '/', viewport: { width: 1280, height: 720 } },
{ path: '/', viewport: { width: 390, height: 720 } },
{ path: '/wizard/', viewport: { width: 1280, height: 720 } },
{ path: '/wizard/', viewport: { width: 390, height: 720 } },
];
for (const testCase of CASES) {
test.describe(`${testCase.path} at ${testCase.viewport.width}x${testCase.viewport.height}`, () => {
test.use({ viewport: testCase.viewport });
test('an open Getting Started panel never covers the shell avatar in the header', async ({ page }) => {
await openShellLayoutCase(page, testCase.path);
});
});
}