дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-27 21:12:34 +02:00
In the Rollback Changes dialog, double-click and Enter only toggled a file's checkbox and Show Diff did nothing. The file checklist shared by Rollback, Shelve and Create Patch now opens the file's diff in a front dialog on double-click, Enter and Show Diff, with the listed files as the next/previous chain; Space toggles the selected rows and clicking a box still toggles it. Rollback Unstaged Changes shows the index against the working copy. Closes #5295. Co-authored-by: audichuang <[email protected]>
144 рядки
7.6 KiB
TypeScript
144 рядки
7.6 KiB
TypeScript
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
|
import type { DiffEntryRequest, FileStatus } from "../src/bindings";
|
|
|
|
test("Rollback fits a short window and scopes its options to checked files", async ({ workbench: page }) => {
|
|
await page.setViewportSize({ width: 410, height: 330 });
|
|
await stubDesktop(page);
|
|
const root = "/dev/settlement-engine";
|
|
const added = `${root}/ledger/additional-settlement-schedule.txt`;
|
|
const deleted = `${root}/ledger/retired-settlement-routing.txt`;
|
|
const modified = Array.from({ length: 16 }, (_, i) => `${root}/ledger/merchant-settlement-batch-${i + 1}.txt`);
|
|
|
|
await page.evaluate(
|
|
async ({ root, added, deleted, modified }) => {
|
|
const status = [
|
|
{ path: added, staged: "added", unstaged: null },
|
|
{ path: deleted, staged: "deleted", unstaged: null },
|
|
...modified.map((path) => ({ path, staged: null, unstaged: "modified" })),
|
|
].map((file) => ({ ...file, relPath: file.path.slice(root.length + 1), renamedFrom: null }));
|
|
const branch = { head: "main", headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null };
|
|
const h = window.__ipc.handlers;
|
|
h.vcs_branch_info = () => branch;
|
|
h.vcs_roots = () => [{ root, ...branch }];
|
|
h.vcs_status = () => status;
|
|
h.vcs_unstage = () => null;
|
|
h.vcs_discard = () => null;
|
|
|
|
const storeModule = "/src/features/vcs/store.ts";
|
|
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
|
useVcs.setState({ available: true, root, repo: root, roots: [root], branch, status });
|
|
const contextModule = "/src/platform/context.ts";
|
|
const { setContext } = await import(/* @vite-ignore */ contextModule);
|
|
setContext("vcsAvailable", true);
|
|
const actionsModule = "/src/platform/actions.ts";
|
|
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
|
|
await executeAction("vcs.rollback", [root]);
|
|
},
|
|
{ root, added, deleted, modified },
|
|
);
|
|
|
|
const dialog = page.getByRole("dialog", { name: "Rollback Changes", exact: true });
|
|
const tree = dialog.getByRole("tree", { name: "Files to roll back" });
|
|
const body = dialog.locator("[data-dialog-body]");
|
|
await expect(tree).toBeVisible();
|
|
expect(await body.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeLessThanOrEqual(1);
|
|
expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
|
|
expect(await tree.evaluate((el) => el.scrollHeight > el.clientHeight)).toBe(true);
|
|
await expect(tree).toBeFocused();
|
|
await expect(tree.getByTitle("ledger/additional-settlement-schedule.txt", { exact: true })).toBeVisible();
|
|
|
|
const status = dialog.getByRole("status");
|
|
const deleteCopies = dialog.getByRole("checkbox", { name: "Delete local copies of added files" });
|
|
const rollback = dialog.getByRole("button", { name: "Rollback", exact: true });
|
|
await expect(status).toHaveText("1 added16 modified1 deleted");
|
|
|
|
// Double-click shows the file's diff over Rollback and leaves its box alone; closing it comes back.
|
|
// Let the dialog's open animation finish so both clicks land on the same row.
|
|
await dialog.evaluate((el) => Promise.all(el.getAnimations({ subtree: true }).map((a) => a.finished)));
|
|
await tree.getByTitle("ledger/merchant-settlement-batch-1.txt", { exact: true }).dblclick();
|
|
const diff = page.getByRole("dialog", { name: "merchant-settlement-batch-1.txt (HEAD ↔ Your version)" });
|
|
await expect(diff).toBeVisible();
|
|
await page.keyboard.press("Escape");
|
|
await expect(diff).toBeHidden();
|
|
await expect(dialog).toBeVisible();
|
|
await expect(tree).toBeFocused();
|
|
await expect(status).toHaveText("1 added16 modified1 deleted");
|
|
// Space toggles the selected row, also right after clicking its box.
|
|
await page.keyboard.press("Space");
|
|
await expect(status).toHaveText("1 added15 modified1 deleted");
|
|
await page.keyboard.press("Space");
|
|
await expect(status).toHaveText("1 added16 modified1 deleted");
|
|
await tree.getByRole("checkbox", { name: "Include merchant-settlement-batch-1.txt", exact: true }).click();
|
|
await expect(status).toHaveText("1 added15 modified1 deleted");
|
|
await page.keyboard.press("Space");
|
|
await expect(status).toHaveText("1 added16 modified1 deleted");
|
|
await expect(deleteCopies).toBeEnabled();
|
|
await expect(deleteCopies).not.toBeChecked();
|
|
await deleteCopies.check();
|
|
await tree.getByRole("checkbox", { name: "Include additional-settlement-schedule.txt" }).uncheck();
|
|
await expect(deleteCopies).toBeDisabled();
|
|
await expect(status).toHaveText("16 modified1 deleted");
|
|
|
|
const rootCheckbox = tree.getByRole("checkbox", { name: "Include settlement-engine", exact: true });
|
|
await expect(rootCheckbox).toHaveAttribute("aria-checked", "mixed");
|
|
await rootCheckbox.click();
|
|
await rootCheckbox.uncheck();
|
|
await expect(rollback).toBeDisabled();
|
|
await expect(status).toHaveText("No files selected");
|
|
|
|
await tree.getByRole("checkbox", { name: "Include merchant-settlement-batch-1.txt", exact: true }).check();
|
|
await expect(status).toHaveText("1 modified");
|
|
await expect(deleteCopies).toBeDisabled();
|
|
await rollback.click();
|
|
await expect(dialog).toBeHidden();
|
|
await expect.poll(() => ipcCalls(page, "vcs_discard")).toEqual([{ paths: [modified[0]] }]);
|
|
expect(await ipcCalls(page, "vcs_unstage")).toEqual([]);
|
|
});
|
|
|
|
test("a selected submodule can restore the parent index and checkout separately", async ({ workbench: page }) => {
|
|
await stubDesktop(page);
|
|
const root = "/dev/parent";
|
|
const path = root + "/libs/module";
|
|
await page.evaluate(
|
|
async ({ root, path }) => {
|
|
const branch = { head: "main", headCommit: "a", upstream: null, ahead: 0, behind: 0, operation: null };
|
|
const status: FileStatus[] = [
|
|
{ path, relPath: "libs/module", staged: "modified", unstaged: "modified", renamedFrom: null },
|
|
{ path: path + "/child.txt", relPath: "child.txt", staged: null, unstaged: "modified", renamedFrom: null },
|
|
];
|
|
const h = window.__ipc.handlers;
|
|
h.vcs_branch_info = () => branch;
|
|
h.vcs_roots = () => [root, path].map((root) => ({ root, ...branch }));
|
|
h.vcs_status = () => status;
|
|
h.vcs_diff_entries = ({ entries }) =>
|
|
(entries as DiffEntryRequest[]).map((entry) =>
|
|
entry.path === path
|
|
? { mode: "160000", gitlink: entry.rev === "HEAD" ? "a" : entry.rev === ":0" ? "b" : "c" }
|
|
: null,
|
|
);
|
|
h.vcs_rollback_submodules = () => null;
|
|
const storeModule = "/src/features/vcs/store.ts";
|
|
const contextModule = "/src/platform/context.ts";
|
|
const actionsModule = "/src/platform/actions.ts";
|
|
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
|
const { setContext } = await import(/* @vite-ignore */ contextModule);
|
|
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
|
|
useVcs.setState({ available: true, root, repo: root, roots: [root, path], branch, status });
|
|
setContext("vcsAvailable", true);
|
|
await executeAction("vcs.rollback", [path]);
|
|
},
|
|
{ root, path },
|
|
);
|
|
const dialog = page.getByRole("dialog", { name: "Rollback Changes", exact: true });
|
|
const checkout = dialog.getByRole("checkbox", { name: "Restore selected submodule checkouts" });
|
|
await expect(checkout).toBeChecked();
|
|
await expect(dialog.getByText("child.txt", { exact: true })).toHaveCount(0);
|
|
await checkout.uncheck();
|
|
await dialog.getByRole("button", { name: "Rollback", exact: true }).click();
|
|
await expect
|
|
.poll(() => ipcCalls(page, "vcs_rollback_submodules"))
|
|
.toEqual([{ paths: [path], source: "head", restoreCheckout: false }]);
|
|
expect(await ipcCalls(page, "vcs_unstage")).toEqual([]);
|
|
expect(await ipcCalls(page, "vcs_discard")).toEqual([]);
|
|
});
|