Файли
openidea/e2e/diffUnchangedLayout.spec.ts
T
l0ng-ai 17f5889037 fix(diff): make collapsed unchanged lines easier to find and expand (#5065)
Collapsed unchanged lines in the diff viewer are now a full-width button: a chevron, the line count in UI type and a hatched rule in the separator colour, with hover and focus states. Clicking it or pressing Enter expands the range in both panes and returns focus to the editor.
2026-11-22 02:57:36 +08:00

64 рядки
3.0 KiB
TypeScript

import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures";
async function openDiff(page: Page, mode: "split" | "unified") {
const source = Array.from({ length: 62 }, (_, index) => `const item${index + 1} = ${index + 1};`).join("\n");
const updated = source.replace("item12 = 12", "item12 = 120").replace("item49 = 49", "item49 = 490");
await page.evaluate(
async ({ mode, source, updated }) => {
localStorage.setItem(
"openidea.vcs.diffOptions",
JSON.stringify({ mode, collapse: true, alignChanges: true, highlight: "words", syncScroll: true }),
);
const path = "/src/platform/actions.ts";
await (
await import(/* @vite-ignore */ path)
).executeAction("diff.compareTexts", {
path: "items.ts",
title: "items.ts",
left: { text: source, label: "Before" },
right: { text: updated, label: "After" },
});
},
{ mode, source, updated },
);
await expect(page.getByRole("toolbar", { name: "Diff" })).toBeVisible();
}
test("side-by-side unchanged separators expand both panes from the keyboard", async ({ workbench: page }) => {
await openDiff(page, "split");
const left = page.locator(".cm-merge-a");
const right = page.locator(".cm-merge-b");
const row = left.locator(".cm-collapsedLines").first();
await expect(row).toBeVisible();
const control = row.getByRole("button", { name: "8 unchanged lines" });
await expect(control).toBeVisible();
await expect(control).toHaveCSS("font-size", "13px");
await expect(right.getByRole("button", { name: "8 unchanged lines" })).toBeVisible();
await expect(left.locator(".cm-line").getByText("item1", { exact: true })).toBeHidden();
await control.press("Enter");
await expect(left.getByRole("button", { name: "8 unchanged lines" })).toBeHidden();
await expect(right.getByRole("button", { name: "8 unchanged lines" })).toBeHidden();
await expect(left.locator(".cm-line").getByText("item1", { exact: true })).toBeVisible();
await expect(right.locator(".cm-line").getByText("item1", { exact: true })).toBeVisible();
await expect(left.locator(".cm-content")).toBeFocused();
});
test("the unified separator stays legible in a narrow viewer and expands on click", async ({ workbench: page }) => {
await page.setViewportSize({ width: 640, height: 650 });
await openDiff(page, "unified");
const pane = page.locator(".cm-merge-b");
const first = pane.locator(".cm-collapsedLines").first();
await expect(first).toBeVisible();
const control = first.getByRole("button", { name: "8 unchanged lines" });
await expect(control).toBeInViewport({ ratio: 1 });
const row = (await first.boundingBox())!;
const bounds = (await control.boundingBox())!;
expect(bounds.width).toBeGreaterThanOrEqual(row.width - 1);
await control.click();
await expect(pane.getByRole("button", { name: "8 unchanged lines" })).toBeHidden();
await expect(pane.locator(".cm-line").getByText("item1", { exact: true })).toBeVisible();
await expect(pane.locator(".cm-collapsedLines").first()).toBeVisible();
});