Файли
openidea/e2e/welcomeProjectsLayout.spec.ts
T

76 рядки
3.8 KiB
TypeScript

import { expect, test } from "./fixtures";
test("Welcome keeps project search and actions on one row at a narrow width", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1080, height: 700 });
await page.evaluate(async () => {
const projectPath = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectPath);
useProject.setState({ project: null, lightEdit: false });
});
const projects = page.getByRole("region", { name: "Projects", exact: true });
const search = projects.getByRole("textbox", { name: "Search projects" });
const list = projects.getByRole("listbox", { name: "Recent projects" });
const more = projects.getByRole("button", { name: "More Actions", exact: true });
const open = projects.getByRole("button", { name: "Open", exact: true });
await expect(list.getByRole("option")).toHaveCount(4);
await expect(more).toBeVisible();
await expect(open).toHaveText("Open");
await expect(projects.getByRole("button", { name: "Remote Development", exact: true })).toBeVisible();
await page.setViewportSize({ width: 440, height: 620 });
const boxes = await Promise.all([search.boundingBox(), open.boundingBox(), more.boundingBox()]);
// Four icon-only header actions plus More Actions leave the field room for its placeholder.
expect(boxes[0]!.width).toBeGreaterThan(64);
for (const box of boxes.slice(1)) {
expect(Math.abs(box!.y + box!.height / 2 - (boxes[0]!.y + boxes[0]!.height / 2))).toBeLessThan(2);
expect(box!.x + box!.width).toBeLessThanOrEqual(440);
}
await expect(open.getByText("Open", { exact: true })).toBeHidden();
await expect.poll(() => projects.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await search.fill("tokio");
await expect(list.getByRole("option")).toHaveCount(1);
await expect(list.getByRole("option")).toContainText("tokio");
await more.press("Enter");
const menu = page.getByRole("menu", { name: "More Actions" });
for (const label of ["New File", "Open File"]) {
await expect(menu.getByRole("menuitem", { name: new RegExp(label) })).toBeVisible();
}
await page.keyboard.press("Escape");
await expect(menu).toBeHidden();
await expect(more).toBeFocused();
await expect(search).toHaveValue("tokio");
});
test("Welcome lists local and remote projects at the same level", async ({ workbench: page }) => {
await page.evaluate(async () => {
const projectPath = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectPath);
useProject.setState({ project: null, lightEdit: false });
});
const list = page.getByRole("listbox", { name: "Recent projects" });
const rows = list.getByRole("option");
await expect(rows).toHaveCount(4);
await page.evaluate(async () => {
const recentPath = "/src/features/welcome/recent.ts";
const { useRecent } = await import(/* @vite-ignore */ recentPath);
useRecent.setState({
groups: [],
projects: [
{ name: "tty7", path: "ssh://macmini/Users/thomas/repo/tty7", branch: null, openedAtMs: 100 },
{ name: "OpenIDEA", path: "/Users/dev/dev/openidea", branch: null, openedAtMs: 90 },
{ name: "tty7", path: "/Users/dev/dev/tty7", branch: null, openedAtMs: 80 },
],
});
});
await expect(rows).toHaveCount(3);
await expect(rows.nth(0)).toContainText("macmini:/Users/thomas/repo/tty7");
await expect(rows.nth(1)).toContainText("OpenIDEA");
await expect(rows.nth(2)).toContainText("~/dev/tty7");
await expect(list.locator("[aria-expanded]")).toHaveCount(0);
await expect(list.locator("[data-remote-badge]")).toHaveCount(1);
const avatars = await rows.evaluateAll((els) => els.map((el) => el.firstElementChild!.getBoundingClientRect().x));
expect(avatars).toEqual([avatars[0], avatars[0], avatars[0]]);
});