Файли
openidea/e2e/replaceAllConfirmationLayout.spec.ts
T
l0ng-ai e4d6f50a0b fix(search): make Replace All details easier to review (#5236)
Replace All puts the affected count above separate, scrollable values for the search text and replacement. Both values stay available in full, and an empty replacement is labeled explicitly. The Replace in Files popup and the Find tool window use the same confirmation.
2026-11-23 09:12:56 +08:00

76 рядки
3.7 KiB
TypeScript

import type { SearchQuery } from "../src/bindings";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("Replace All keeps both values readable and the actions visible", async ({ workbench: page }) => {
const pattern = `LEGACY_${"MONTH_END_RECONCILIATION_INPUT_".repeat(15)}END`;
const replacement = `ACTIVE_${"MONTH_END_RECONCILIATION_OUTPUT_".repeat(18)}END`;
await page.emulateMedia({ reducedMotion: "reduce" });
await page.setViewportSize({ width: 1040, height: 700 });
await stubDesktop(page);
await page.evaluate((pattern) => {
window.__ipc.handlers.search_validate = () => null;
window.__ipc.handlers.search_start = ({ query, onEvent }) => {
if ((query as SearchQuery).pattern !== pattern) return null;
setTimeout(() => {
for (const relPath of ["invoice.txt", "receipt.txt"]) {
window.__ipc.send(onEvent, {
type: "file",
file: {
path: `/dev/acme-api/${relPath}`,
relPath,
matches: [{ line: 0, text: pattern, ranges: [[0, pattern.length]], textOffset: 0 }],
},
});
}
window.__ipc.send(onEvent, {
type: "done",
summary: { files: 2, matches: 2, limitHit: false, cancelled: false, elapsedMs: 1 },
});
}, 20);
return null;
};
}, pattern);
await page.keyboard.press("Meta+Shift+r");
const popup = page.getByRole("dialog", { name: "Replace in Files", exact: true });
await popup.getByRole("textbox", { name: "Text to find", exact: true }).fill(pattern);
const replacementInput = popup.getByRole("textbox", { name: "Replace with", exact: true });
await replacementInput.fill(replacement);
await expect(popup.getByRole("listbox", { name: "Matches" }).getByRole("option")).toHaveCount(2);
await page.setViewportSize({ width: 440, height: 520 });
await popup.getByRole("button", { name: "Replace All", exact: true }).click();
const dialog = page.getByRole("dialog", { name: "Replace All", exact: true });
const findText = dialog.getByRole("region", { name: "Text to find", exact: true });
const replaceText = dialog.getByRole("region", { name: "Replace with", exact: true });
const replace = dialog.getByRole("button", { name: "Replace", exact: true });
const cancel = dialog.getByRole("button", { name: "Cancel", exact: true });
await expect(findText).toHaveText(pattern);
await expect(replaceText).toHaveText(replacement);
await expect(dialog.getByText("Replace 2 occurrences in 2 files?", { exact: true })).toBeVisible();
const bottom = (await replace.boundingBox())!.y;
for (const item of [findText, replaceText]) {
await expect(item).toHaveCSS("font-size", "13px");
expect(await item.evaluate((el) => el.scrollHeight > el.clientHeight && el.scrollWidth === el.clientWidth)).toBe(
true,
);
await item.focus();
await page.keyboard.press("End");
await expect.poll(() => item.evaluate((el) => el.scrollTop)).toBeGreaterThan(0);
}
expect((await replace.boundingBox())!.y).toBeCloseTo(bottom, 0);
await expect(replace).toBeInViewport({ ratio: 1 });
await expect(cancel).toBeInViewport({ ratio: 1 });
await cancel.click();
await expect(dialog).toBeHidden();
await page.setViewportSize({ width: 1040, height: 700 });
await replacementInput.fill("");
await popup.getByRole("button", { name: "Open in Find Window", exact: true }).click();
const findWindow = page.getByRole("region", { name: "Find", exact: true });
await findWindow.getByRole("button", { name: "Replace All", exact: true }).click();
await expect(findText).toHaveText(pattern);
await expect(replaceText).toHaveText("Empty text");
await cancel.click();
expect(await ipcCalls(page, "replace_in_files")).toHaveLength(0);
});