Файли
openidea/e2e/gitFileHistoryLayout.spec.ts
T
LU XIANGRUIтаwildcatDownstairs 6fbbab6c6f fix(vcs): show the file's diff to the right of file history (#7744)
Fixes #6406

Git > Show History for a file now keeps the revisions and their commit details on the left (details below the revisions) and shows the selected revision's diff of that file on the right. Directory history keeps the repository log layout.

The diff follows Show Diff Preview and file history's own Diff Preview Location (Right by default; Bottom puts it below; Editor leaves it out and Show Diff opens a tab). The split is remembered per location. The details pane's change loading and preview are shared with the new pane, and the rename-aware matching of the history file's changes moved to historyFileChanges so Show Diff and the pane agree.

Co-authored-by: wildcatDownstairs <[email protected]>
2026-12-04 02:00:01 +08:00

129 рядки
6.5 KiB
TypeScript

import { expect, stubDesktop, test } from "./fixtures";
test("file history puts commit details below the revisions, the file's diff to the right, and keeps directory history in the log layout", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1100, height: 760 });
await stubDesktop(page);
await page.evaluate(async () => {
const root = "/dev/acme-api";
const id = (n: number) => n.toString().padStart(40, "0");
const commits = ["Update the reviewed totals", "Add the weekly total"].map((summary, index) => ({
id: id(index + 1),
shortId: id(index + 1).slice(-8),
author: index === 0 ? "Lena Park" : "Morgan Chen",
email: "[email protected]",
timeMs: Date.UTC(2026, 9, 25 - index),
parents: index === 0 ? [id(2)] : [],
refs: [],
summary,
message: `${summary}\n\nRevision notes for the release review.`,
}));
const h = window.__ipc.handlers;
h.fs_entry_kind = ({ path }) => (path === `${root}/src` ? "dir" : "file");
h.vcs_log = ({ query }) => {
const { skip, path } = query as { skip: number; path?: string };
return commits
.slice(skip)
.map((c) => ({ ...c, historyPath: path?.endsWith(".kts") ? "build.gradle.kts" : null }));
};
h.vcs_log_refs = () => ({});
h.vcs_branches = () => [];
h.vcs_commit_files = () => [{ path: "build.gradle.kts", kind: "modified" }];
h.vcs_log_details_batch = ({ revisions }) =>
(revisions as string[]).map((revision) => ({
message: commits.find((commit) => commit.id === revision)!.message,
containingBranches: ["main"],
signature: "N",
signer: "",
key: "",
fingerprint: "",
}));
const storeModule = "/src/features/vcs/store.ts";
const { useVcs } = await import(/* @vite-ignore */ storeModule);
useVcs.setState({ available: true, root, repo: root, roots: [root], branchesLoaded: true });
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.showHistory", `${root}/build.gradle.kts`);
});
const git = page.getByRole("tablist", { name: "Git" });
const historyTab = git.getByRole("tab", { name: /History: build.gradle.kts/ });
const revisions = page.getByRole("listbox", { name: "Commits" });
const separator = page.getByRole("separator", { name: "Details", exact: true });
const details = page.getByRole("region", { name: "Commit message" });
await expect(historyTab).toHaveAttribute("aria-selected", "true");
const newest = revisions.getByRole("option", { name: /Update the reviewed totals/ });
await expect(newest).toBeVisible();
await expect(separator).toHaveAttribute("aria-orientation", "horizontal");
// IDEA's file history: the file's diff to the right of the revisions and their details.
const diffSeparator = page.getByRole("separator", { name: "Diff", exact: true });
await expect(diffSeparator).toHaveAttribute("aria-orientation", "vertical");
const diffEdge = (await diffSeparator.boundingBox())!.x;
expect((await revisions.boundingBox())!.x + (await revisions.boundingBox())!.width).toBeLessThanOrEqual(diffEdge + 1);
await expect(page.getByRole("toolbar", { name: "Branches", exact: true })).toHaveCount(0);
await expect(page.getByRole("button", { name: "Show Branches", exact: true })).toHaveCount(0);
const author = await newest.getByText("Lena Park", { exact: true }).boundingBox();
const subject = await newest.getByText("Update the reviewed totals", { exact: true }).boundingBox();
expect(author!.x).toBeLessThan(subject!.x);
const earlier = revisions.getByRole("option", { name: /Add the weekly total/ });
await earlier.click();
await expect(details).toContainText("Add the weekly total");
await expect(details).toContainText("Revision notes for the release review.");
const listBox = (await revisions.boundingBox())!;
expect((await details.boundingBox())!.y).toBeGreaterThanOrEqual(listBox.y + listBox.height - 1);
await expect(
page.getByRole("tree", { name: "Changed files" }).getByRole("treeitem", { name: "build.gradle.kts" }),
).toBeVisible();
await separator.press("ArrowUp");
await expect.poll(async () => (await revisions.boundingBox())!.height).toBeLessThan(listBox.height);
await expect(earlier).toHaveAttribute("aria-selected", "true");
const resized = (await revisions.boundingBox())!.height;
await page.evaluate(async () => {
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("vcs.showHistory", "/dev/acme-api/src");
});
await expect(git.getByRole("tab", { name: /History: src/ })).toHaveAttribute("aria-selected", "true");
await expect(page.getByRole("toolbar", { name: "Branches", exact: true })).toBeVisible();
await expect(separator).toHaveCount(0);
await expect(diffSeparator).toHaveCount(0);
await historyTab.click();
await expect(earlier).toHaveAttribute("aria-selected", "true");
await expect.poll(async () => (await revisions.boundingBox())!.height).toBeCloseTo(resized, 0);
await expect(details).toContainText("Add the weekly total");
await page.evaluate(async () => {
const servicesModule = "/src/workbench/contributions.ts";
const { editorService } = await import(/* @vite-ignore */ servicesModule);
const service = editorService();
service.openFile = async (path: string) => {
(window as unknown as { __revisionOpen: string }).__revisionOpen = path;
return null;
};
});
const changedFile = page.getByRole("tree", { name: "Changed files" }).getByRole("treeitem", {
name: "build.gradle.kts",
});
await changedFile.click({ button: "right" });
const openRevision = page.getByRole("menuitem", { name: "Open Repository Version" });
await expect(openRevision).toBeEnabled();
await openRevision.click();
await expect
.poll(async () =>
page.evaluate(async () => {
const virtualDocsModule = "/src/platform/virtualDocs.ts";
const { gitRevisionOf } = await import(/* @vite-ignore */ virtualDocsModule);
const uri = (window as unknown as { __revisionOpen?: string }).__revisionOpen;
return uri ? gitRevisionOf(uri) : null;
}),
)
.toEqual({ repo: "/dev/acme-api", revision: "2".padStart(40, "0"), path: "build.gradle.kts" });
});