дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
The title-bar project switcher keeps only Open Projects and Recent Projects, as one flat list ordered by recency, without host or custom group headings. Local and remote projects share one row layout; remote rows keep the avatar badge and show host:path on the path line. Section headings line up with the project badges. The Welcome screen and the standalone Recent Projects popup keep their grouping.
148 рядки
6.2 KiB
TypeScript
148 рядки
6.2 KiB
TypeScript
import { expect, stubDesktop, test } from "./fixtures";
|
||
|
||
test("keeps the project switcher flat while grouping Welcome and Recent Projects without row overlap", async ({
|
||
workbench: page,
|
||
}) => {
|
||
await page.setViewportSize({ width: 980, height: 740 });
|
||
await stubDesktop(page);
|
||
|
||
await page.evaluate(async () => {
|
||
const localProjects = [
|
||
{ path: "/Users/dev/git/gocommon", name: "gocommon", openedAtMs: 70_000, branch: "main" },
|
||
{ path: "/Users/dev/git/openidea_all", name: "openidea_all", openedAtMs: 40_000, branch: null },
|
||
{ path: "/Users/dev/git/superpowers", name: "superpowers", openedAtMs: 20_000, branch: "main" },
|
||
];
|
||
const remoteProjects = [
|
||
{
|
||
target: { kind: "ssh", config: "devbox" },
|
||
path: "/home/coder/git/openidea_all",
|
||
name: "openidea_all",
|
||
host: "[email protected]:22",
|
||
openedAtMs: 100_000,
|
||
},
|
||
{
|
||
target: { kind: "ssh", config: "mbp1" },
|
||
path: "/Users/dev/git/gocommon",
|
||
name: "gocommon",
|
||
host: "dev-mbp1.local",
|
||
openedAtMs: 90_000,
|
||
},
|
||
{
|
||
target: { kind: "ssh", config: "devbox" },
|
||
path: "/home/coder/git/gocommon",
|
||
name: "gocommon",
|
||
host: "[email protected]:22",
|
||
openedAtMs: 60_000,
|
||
},
|
||
{
|
||
target: { kind: "wsl", distro: "Ubuntu-24.04" },
|
||
path: "/home/dev/git/openidea_all",
|
||
name: "openidea_all",
|
||
host: "Ubuntu-24.04",
|
||
openedAtMs: 30_000,
|
||
},
|
||
];
|
||
localStorage.setItem("openidea.remote.recent", JSON.stringify(remoteProjects));
|
||
|
||
window.__ipc.handlers.recent_projects = () => localProjects;
|
||
window.__ipc.handlers.recent_project_groups = () => [];
|
||
window.__ipc.handlers.app_info = () => ({ version: "0.1.55" });
|
||
window.__ipc.handlers.window_open_projects = () => [
|
||
{ name: "openidea_all", root: "/Users/dev/git/openidea_all", current: true, remote: null },
|
||
{
|
||
name: "openidea_all",
|
||
root: "/home/coder/git/openidea_all",
|
||
current: false,
|
||
remote: { kind: "ssh", config: "devbox" },
|
||
},
|
||
];
|
||
|
||
const projectMod = "/src/platform/project.ts";
|
||
const recentMod = "/src/features/welcome/recent.ts";
|
||
const { useProject } = await import(/* @vite-ignore */ projectMod);
|
||
const { loadRecent, useRecent } = await import(/* @vite-ignore */ recentMod);
|
||
await loadRecent();
|
||
useRecent.setState({ home: "/Users/dev" });
|
||
const prev = useProject.getState().project;
|
||
if (prev) {
|
||
useProject.setState({
|
||
project: { ...prev, name: "openidea_all", displayName: "openidea_all", root: "/Users/dev/git/openidea_all" },
|
||
});
|
||
}
|
||
});
|
||
|
||
// 1. The project widget uses the same row layout for local and remote projects.
|
||
await page.getByRole("button", { name: "openidea_all" }).click();
|
||
const projectPopup = page.getByRole("dialog", { name: "Projects" });
|
||
await expect(projectPopup).toBeVisible();
|
||
await expect(projectPopup).toContainText("Open Projects");
|
||
await expect(projectPopup).toContainText("Recent Projects");
|
||
await expect(projectPopup).toContainText("dev-mbp1.local");
|
||
await expect(projectPopup.getByText("Local", { exact: true })).toHaveCount(0);
|
||
await expect(projectPopup).toContainText("Ubuntu-24.04");
|
||
// The two section headers and every project badge share the same left inset.
|
||
const headers = [
|
||
projectPopup.getByText("Open Projects", { exact: true }),
|
||
projectPopup.getByText("Recent Projects", { exact: true }),
|
||
];
|
||
const headerMetrics = await Promise.all(
|
||
headers.map((header) =>
|
||
header.evaluate((el) => {
|
||
const style = getComputedStyle(el);
|
||
const rect = el.getBoundingClientRect();
|
||
return { x: rect.x + parseFloat(style.paddingLeft), height: rect.height, fontSize: style.fontSize };
|
||
}),
|
||
),
|
||
);
|
||
expect(headerMetrics[1]).toEqual(headerMetrics[0]);
|
||
const projectRows = projectPopup.getByRole("option").filter({ hasText: "/git/" });
|
||
await expect(projectRows).toHaveCount(7);
|
||
await expect(projectRows.locator("[data-remote-badge]")).toHaveCount(4);
|
||
const rowMetrics = await projectRows.evaluateAll((rows) =>
|
||
rows.map((el) => ({
|
||
x: el.firstElementChild!.getBoundingClientRect().x,
|
||
height: el.getBoundingClientRect().height,
|
||
})),
|
||
);
|
||
for (const row of rowMetrics) expect(row.x).toBeCloseTo(headerMetrics[0]!.x, 0);
|
||
// Both open projects have no branch metadata and must have identical heights.
|
||
expect(rowMetrics[0]!.height).toBeCloseTo(rowMetrics[1]!.height, 0);
|
||
await expect(projectPopup.getByRole("separator")).toHaveCount(2);
|
||
await page.keyboard.press("Escape");
|
||
await expect(projectPopup).toBeHidden();
|
||
|
||
// 2. Recent Projects popup groups by host and never overlaps rows (grouped or 3-line search results).
|
||
await page.evaluate(async () => {
|
||
const popupMod = "/src/features/welcome/RecentProjectsPopup.tsx";
|
||
const { showRecentProjectsPopup } = await import(/* @vite-ignore */ popupMod);
|
||
showRecentProjectsPopup();
|
||
});
|
||
const recentDialog = page.getByRole("dialog", { name: "Recent Projects" });
|
||
await expect(recentDialog).toBeVisible();
|
||
const assertNoVerticalOverlap = async () => {
|
||
const options = recentDialog.getByRole("option");
|
||
const count = await options.count();
|
||
expect(count).toBeGreaterThan(1);
|
||
const boxes = await Promise.all(Array.from({ length: count }, (_, i) => options.nth(i).boundingBox()));
|
||
for (let i = 1; i < boxes.length; i++) {
|
||
expect(boxes[i]!.y).toBeGreaterThanOrEqual(boxes[i - 1]!.y + boxes[i - 1]!.height - 0.5);
|
||
}
|
||
};
|
||
await assertNoVerticalOverlap();
|
||
await recentDialog.getByRole("textbox", { name: "Search recent projects" }).fill("openidea_all");
|
||
await assertNoVerticalOverlap();
|
||
await page.keyboard.press("Escape");
|
||
await expect(recentDialog).toBeHidden();
|
||
|
||
// 3. Welcome › Projects folds and unfolds host groups.
|
||
await page.evaluate(async () => {
|
||
const projectMod = "/src/platform/project.ts";
|
||
const { useProject } = await import(/* @vite-ignore */ projectMod);
|
||
useProject.setState({ project: null, lightEdit: false });
|
||
});
|
||
const welcomeList = page.getByRole("listbox", { name: "Recent projects" });
|
||
await expect(welcomeList.getByRole("option")).toHaveCount(11);
|
||
await welcomeList.getByRole("option").first().click();
|
||
await expect(welcomeList.getByRole("option")).toHaveCount(9);
|
||
});
|