mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 19:49:35 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
679c905621 | ||
|
|
3103ec19f9 | ||
|
|
026ef8794f |
No files matched your search
@@ -320,3 +320,88 @@ test("the Paths filter replaces the repository filter and can be cleared from ov
|
||||
await picker.getByRole("button", { name: "OK" }).click();
|
||||
await expect(firstCommit.getByText("Commit 1", { exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("the Git Log path tree resizes and keeps selected paths reachable in a short window", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 1000, height: 720 });
|
||||
const longName = "reconcile-invoices-and-export-the-complete-quarterly-settlement-audit.ts";
|
||||
await page.evaluate(async (longName) => {
|
||||
const logPath = "/src/features/vcs/logStore.ts";
|
||||
const optionsPath = "/src/features/vcs/logOptions.ts";
|
||||
const { setLogFilters } = await import(/* @vite-ignore */ logPath);
|
||||
const { setLogOptions } = await import(/* @vite-ignore */ optionsPath);
|
||||
const root = "/dev/acme-api";
|
||||
const selected = Array.from({ length: 9 }, (_, i) => `entry-${i + 1}.ts`);
|
||||
const entry = (name: string, kind: "dir" | "file") => ({
|
||||
name,
|
||||
path: `${root}/${name}`,
|
||||
kind,
|
||||
size: 0,
|
||||
mtimeMs: 0,
|
||||
});
|
||||
window.__ipc.handlers.fs_read_dir = ({ path }) =>
|
||||
path === root
|
||||
? [entry("src", "dir"), entry(longName, "file"), ...selected.map((name) => entry(name, "file"))]
|
||||
: [];
|
||||
setLogOptions({ showBranches: false, showDetails: false });
|
||||
setLogFilters({ paths: selected.map((name) => `${root}/${name}`) });
|
||||
}, longName);
|
||||
|
||||
const toolbar = page.getByRole("toolbar", { name: "Log filters" });
|
||||
const openTree = async () => {
|
||||
await toolbar.getByRole("button", { name: "More Filters" }).click();
|
||||
await page.getByRole("menuitem", { name: /^Paths:/ }).click();
|
||||
await page.getByRole("menuitem", { name: "Select in Tree…" }).click();
|
||||
};
|
||||
await openTree();
|
||||
const dialog = page.getByRole("dialog", { name: "Filter by Paths" });
|
||||
const tree = dialog.getByRole("tree", { name: "Files and folders" });
|
||||
const resize = dialog.locator('[class*="_resizeGrip_"]');
|
||||
await expect(tree).toBeVisible();
|
||||
await expect(resize).toBeVisible();
|
||||
await tree.getByRole("treeitem", { name: "acme-api", exact: true }).locator("[data-tree-toggle]").click();
|
||||
const folder = tree.getByRole("checkbox", { name: "src", exact: true });
|
||||
const file = tree.getByRole("checkbox", { name: longName, exact: true });
|
||||
await expect(folder.locator("xpath=ancestor::label").locator("svg")).toHaveCount(1);
|
||||
const title = file.locator("xpath=ancestor::label").getByTitle(longName);
|
||||
await expect(title).toHaveCSS("font-size", "13px");
|
||||
await expect(title).toHaveCSS("text-overflow", "ellipsis");
|
||||
|
||||
const originalTreeHeight = (await tree.boundingBox())!.height;
|
||||
const grip = (await resize.boundingBox())!;
|
||||
const x = grip.x + grip.width / 2;
|
||||
const y = grip.y + grip.height / 2;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x + 30, y + 65, { steps: 5 });
|
||||
await page.mouse.up();
|
||||
await expect.poll(async () => (await tree.boundingBox())!.height).toBeGreaterThan(originalTreeHeight + 40);
|
||||
|
||||
await dialog.getByRole("button", { name: "Cancel" }).click();
|
||||
await page.setViewportSize({ width: 420, height: 325 });
|
||||
await openTree();
|
||||
await tree.getByRole("treeitem", { name: "acme-api", exact: true }).locator("[data-tree-toggle]").click();
|
||||
const selected = dialog.getByRole("group", { name: "Selected paths" });
|
||||
await expect(selected).toBeVisible();
|
||||
await expect.poll(() => selected.evaluate((node) => node.scrollHeight - node.clientHeight)).toBeGreaterThan(1);
|
||||
await expect
|
||||
.poll(() => dialog.locator("[data-dialog-body]").evaluate((node) => node.scrollHeight - node.clientHeight))
|
||||
.toBeLessThanOrEqual(1);
|
||||
await expect.poll(() => title.evaluate((node) => node.scrollWidth - node.clientWidth)).toBeGreaterThan(1);
|
||||
const removed = selected.getByRole("checkbox", { name: "acme-api/entry-9.ts", exact: true });
|
||||
await removed.click();
|
||||
await expect(removed).toHaveCount(0);
|
||||
await file.check();
|
||||
await expect(selected.getByRole("checkbox", { name: `acme-api/${longName}`, exact: true })).toBeChecked();
|
||||
await expect(dialog.getByRole("button", { name: "OK" })).toBeInViewport({ ratio: 1 });
|
||||
await dialog.getByRole("button", { name: "OK" }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
const applied = await page.evaluate(async () => {
|
||||
const path = "/src/features/vcs/logStore.ts";
|
||||
const { useGitLog } = await import(/* @vite-ignore */ path);
|
||||
return useGitLog.getState().filters.paths;
|
||||
});
|
||||
expect(applied).toContain(`/dev/acme-api/${longName}`);
|
||||
expect(applied).not.toContain("/dev/acme-api/entry-9.ts");
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
.chooser > [data-dialog-body] {
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-2) var(--space-4) 0;
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
|
||||
.tree {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-input);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.choice {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.entry {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.entry svg {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.path {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.selected {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 0 1 auto;
|
||||
min-height: 0;
|
||||
max-height: min(96px, 33%);
|
||||
padding-inline: var(--space-2);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.selected .choice {
|
||||
flex: none;
|
||||
min-height: var(--h-list-row);
|
||||
}
|
||||
|
||||
.error {
|
||||
max-height: 25%;
|
||||
overflow: auto;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--danger);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { Checkbox, Dialog, SearchField, Tree } from "@/ui";
|
||||
import { Checkbox, Dialog, Icon, SearchField, Tree, fileIconName } from "@/ui";
|
||||
import { projectFs } from "@/features/project-tree/fs";
|
||||
import { openDialog } from "./dialogs";
|
||||
import { dirName, relTo, stripSlash } from "./model";
|
||||
@@ -7,6 +7,7 @@ import { repoName, repoOf } from "./store";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { ipcPath, isSameOrInside } from "@/platform/paths";
|
||||
import styles from "./PathFilterDialog.module.css";
|
||||
|
||||
interface PathNode {
|
||||
path: string;
|
||||
@@ -167,15 +168,21 @@ function PathFilterDialog({
|
||||
<Dialog
|
||||
open
|
||||
title="Filter by Paths"
|
||||
width={560}
|
||||
className={styles.chooser}
|
||||
width={432}
|
||||
initialSize={{ w: 432, h: 392 }}
|
||||
resizable="both"
|
||||
minWidth={300}
|
||||
minHeight={220}
|
||||
onClose={() => onDone(null)}
|
||||
buttons={[
|
||||
{ label: "OK", role: "default", onClick: () => onDone([...checked]) },
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<div style={{ height: 320 }}>
|
||||
<div className={styles.content}>
|
||||
<Tree<PathNode>
|
||||
className={styles.tree}
|
||||
roots={nodes}
|
||||
getKey={(n) => n.path}
|
||||
getLabel={(n) => n.name}
|
||||
@@ -183,21 +190,49 @@ function PathFilterDialog({
|
||||
isExpandable={(n) => n.directory}
|
||||
loadChildren={load}
|
||||
renderNode={(n) => (
|
||||
<Checkbox label={n.name} checked={checked.has(n.path)} onChange={(on) => toggle(n.path, on)} />
|
||||
<Checkbox
|
||||
className={styles.choice}
|
||||
label={
|
||||
<span className={styles.entry}>
|
||||
<Icon name={n.directory ? "folder" : fileIconName(n.name, n.path)} size={16} />
|
||||
<span className={styles.path} title={n.name}>
|
||||
{n.name}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
checked={checked.has(n.path)}
|
||||
onChange={(on) => toggle(n.path, on)}
|
||||
/>
|
||||
)}
|
||||
aria-label="Files and folders"
|
||||
/>
|
||||
{checked.size > 0 && (
|
||||
<div className={styles.selected} role="group" aria-label={tx("Selected paths")}>
|
||||
{[...checked].map((path) => {
|
||||
const root = roots.includes(path) ? path : repoOf(path, roots);
|
||||
const label = root ? (path === root ? repoName(root) : `${repoName(root)}/${relTo(root, path)}`) : path;
|
||||
return (
|
||||
<Checkbox
|
||||
key={path}
|
||||
className={styles.choice}
|
||||
label={
|
||||
<span className={styles.path} title={label}>
|
||||
{label}
|
||||
</span>
|
||||
}
|
||||
checked
|
||||
onChange={(on) => toggle(path, on)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className={styles.error} role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{checked.size > 0 && (
|
||||
<div style={{ maxHeight: 100, overflow: "auto" }} aria-label="Selected paths">
|
||||
{[...checked].map((path) => {
|
||||
const root = roots.includes(path) ? path : repoOf(path, roots);
|
||||
const label = root ? (path === root ? repoName(root) : `${repoName(root)}/${relTo(root, path)}`) : path;
|
||||
return <Checkbox key={path} label={label} checked onChange={(on) => toggle(path, on)} />;
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{error && <div role="alert">{error}</div>}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { FileStatus } from "@/bindings";
|
||||
|
||||
const stage = vi.hoisted(() => vi.fn(async () => ({ status: "ok", data: null })));
|
||||
const ignore = vi.hoisted(() => vi.fn(async () => ({ status: "ok", data: [] })));
|
||||
const notify = vi.hoisted(() => vi.fn());
|
||||
const project = vi.hoisted(() => ({ paths: [] as string[] }));
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return {
|
||||
...real,
|
||||
commands: {
|
||||
...real.commands,
|
||||
vcsStage: stage,
|
||||
vcsAddToIgnore: ignore,
|
||||
vcsStatus: async () => ({ status: "ok", data: [] }),
|
||||
vcsBranchInfo: async () => ({ status: "ok", data: null }),
|
||||
vcsRoots: async () => ({ status: "ok", data: [{ root: "/repo", operation: null }] }),
|
||||
},
|
||||
};
|
||||
});
|
||||
vi.mock("@/workbench/contributions", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/workbench/contributions")>()),
|
||||
projectViewSelection: () => project.paths,
|
||||
notifications: () => ({ notify }),
|
||||
}));
|
||||
vi.mock("../comparePaths", () => ({ showDirectoryWorkingDiff: async () => false }));
|
||||
vi.mock("../diffDialog", () => ({ openDiffDialog: vi.fn() }));
|
||||
vi.mock("../DiffWindow", () => ({ showDiffWindow: vi.fn() }));
|
||||
|
||||
import { getAction } from "@/platform/actions";
|
||||
import { registerVcsActions } from "../actions";
|
||||
import { useVcs } from "../store";
|
||||
|
||||
const fs = (relPath: string, unstaged: FileStatus["unstaged"]): FileStatus => ({
|
||||
path: `/repo/${relPath}`,
|
||||
relPath,
|
||||
staged: null,
|
||||
unstaged,
|
||||
renamedFrom: null,
|
||||
});
|
||||
|
||||
let unregister: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
stage.mockClear();
|
||||
ignore.mockClear();
|
||||
notify.mockClear();
|
||||
project.paths = [];
|
||||
const files = [fs("dir/new.ts", "untracked"), fs("dir/sub/n2.ts", "untracked"), fs("dir/tracked.ts", "modified")];
|
||||
useVcs.setState({
|
||||
root: "/repo",
|
||||
roots: ["/repo"],
|
||||
status: files,
|
||||
byPath: new Map(files.map((f) => [f.path, f])),
|
||||
statusLoaded: true,
|
||||
});
|
||||
unregister = registerVcsActions();
|
||||
});
|
||||
|
||||
afterEach(() => unregister());
|
||||
|
||||
const addToVcs = () => getAction("vcs.addToVcs")!;
|
||||
|
||||
describe("Add to VCS", () => {
|
||||
it("adds the unversioned files below the Project view's selected directory", async () => {
|
||||
project.paths = ["/repo/dir"];
|
||||
await addToVcs().run({ arg: undefined, ctx: { vcsAvailable: true, projectViewFocus: true } });
|
||||
expect(stage).toHaveBeenCalledWith(["/repo/dir/new.ts", "/repo/dir/sub/n2.ts"]);
|
||||
expect(notify).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("leaves the Project view's selection alone while another view has focus", async () => {
|
||||
project.paths = ["/repo/dir"];
|
||||
await addToVcs().run({ arg: undefined, ctx: { vcsAvailable: true } });
|
||||
expect(stage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("only adds the unversioned files under an explicit selection", async () => {
|
||||
await addToVcs().run({ arg: ["/repo/dir/tracked.ts"], ctx: { vcsAvailable: true } });
|
||||
expect(stage).not.toHaveBeenCalled();
|
||||
expect(notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ title: "Nothing to add: the files are already under version control" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Add to .gitignore", () => {
|
||||
it("ignores the Project view's selection while it has focus, and not otherwise", async () => {
|
||||
project.paths = ["/repo/dir/new.ts"];
|
||||
await getAction("vcs.ignoreShared")!.run({ arg: undefined, ctx: { vcsAvailable: true, projectViewFocus: true } });
|
||||
expect(ignore).toHaveBeenCalledWith(["/repo/dir/new.ts"], "gitignore");
|
||||
ignore.mockClear();
|
||||
await getAction("vcs.ignoreShared")!.run({ arg: undefined, ctx: { vcsAvailable: true } });
|
||||
expect(ignore).not.toHaveBeenCalledWith(["/repo/dir/new.ts"], "gitignore");
|
||||
});
|
||||
});
|
||||
@@ -156,6 +156,11 @@ function selectedPaths(arg: unknown): string[] {
|
||||
return project.length ? project : contextPaths(arg);
|
||||
}
|
||||
|
||||
/** Paths a file action targets: the Project view's selection while it has focus, else the open file. */
|
||||
function focusedPaths(arg: unknown, ctx: { projectViewFocus?: unknown }): string[] {
|
||||
return ctx.projectViewFocus ? selectedPaths(arg) : contextPaths(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* The repository a repository-wide dialog (Pull, Merge, Rebase) starts on: the one holding the
|
||||
* action's file, else the Project view's selection while it has focus, else the active editor's
|
||||
@@ -661,8 +666,8 @@ export function registerVcsActions(): () => void {
|
||||
category: "Git",
|
||||
icon: "history",
|
||||
when: VCS,
|
||||
run: ({ arg }) => {
|
||||
const path = contextPaths(arg)[0];
|
||||
run: ({ arg, ctx }) => {
|
||||
const path = focusedPaths(arg, ctx)[0];
|
||||
if (!path) return;
|
||||
openLogTab("history", path);
|
||||
showGitWindow();
|
||||
@@ -717,7 +722,7 @@ export function registerVcsActions(): () => void {
|
||||
category: "Git",
|
||||
when: VCS,
|
||||
keywords: ["ignore", "unversioned", "exclude"],
|
||||
run: ({ arg }) => addToIgnore(contextPaths(arg), destination),
|
||||
run: ({ arg, ctx }) => addToIgnore(focusedPaths(arg, ctx), destination),
|
||||
})),
|
||||
{
|
||||
id: "vcs.addToVcs",
|
||||
@@ -726,9 +731,7 @@ export function registerVcsActions(): () => void {
|
||||
icon: "plus",
|
||||
when: VCS,
|
||||
keywords: ["git add", "stage"],
|
||||
run: ({ arg }) => {
|
||||
return addToVcs(contextPaths(arg));
|
||||
},
|
||||
run: ({ arg, ctx }) => addToVcs(focusedPaths(arg, ctx)),
|
||||
},
|
||||
{
|
||||
id: "vcs.stash",
|
||||
|
||||
Reference in new issue
Block a user