Compare commits

...
Author SHA1 Message Date
l0ng-ai 1d57839651 fix(project): group file rename options below the name field 2026-11-23 01:02:21 +08:00
3 changed files with 124 additions and 25 deletions

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import { expect, test } from "./fixtures";
const root = "/dev/acme-api";
const stem = "InternationalSettlementRegionalReconciliationAndAuditWarehouseAllocationConfiguration";
const original = stem + ".txt";
const renamed = "WarehouseAllocation.txt";
test("file rename groups the name and reflows the options without losing validation", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1000, height: 700 });
await page.evaluate(
async ({ root, original }) => {
const fsModule = "/src/features/project-tree/fs.ts";
const storeModule = "/src/features/project-tree/store.ts";
const { projectFs } = await import(/* @vite-ignore */ fsModule);
const { loadDir } = await import(/* @vite-ignore */ storeModule);
await projectFs(root).createFile(root + "/" + original);
await loadDir(root, true);
},
{ root, original },
);
const source = page.getByRole("treeitem", { name: original, exact: true });
await source.click();
await page.keyboard.press("Shift+F6");
const dialog = page.getByRole("dialog", { name: "Rename", exact: true });
const prompt = dialog.getByText("Rename file '" + original + "' and its usages to:", { exact: true });
const field = dialog.getByRole("textbox", { name: "New name" });
const references = dialog.getByRole("checkbox", { name: "Search for references" });
const comments = dialog.getByRole("checkbox", { name: "Search in comments and strings" });
const submit = dialog.getByRole("button", { name: "Refactor", exact: true });
const referencesRow = references.locator("xpath=ancestor::label");
const commentsRow = comments.locator("xpath=ancestor::label");
await expect(field).toBeFocused();
const selected = await field.evaluate((el: HTMLInputElement) => el.value.slice(el.selectionStart!, el.selectionEnd!));
expect(selected).toBe(stem);
await expect
.poll(async () => {
const a = (await prompt.boundingBox())!;
const b = (await field.boundingBox())!;
return b.y - a.y - a.height;
})
.toBeCloseTo(4, 0);
await expect
.poll(async () => {
const a = (await referencesRow.boundingBox())!;
const b = (await commentsRow.boundingBox())!;
return Math.abs(a.y - b.y) < 1 && b.x >= a.x + a.width;
})
.toBe(true);
await field.fill("README.md");
await expect(dialog.getByRole("alert")).toBeVisible();
await expect(submit).toBeDisabled();
await page.setViewportSize({ width: 400, height: 520 });
await expect
.poll(async () => {
const a = (await referencesRow.boundingBox())!;
const b = (await commentsRow.boundingBox())!;
return b.y >= a.y + a.height;
})
.toBe(true);
await expect(field).toHaveValue("README.md");
await expect(prompt).toBeInViewport({ ratio: 1 });
await expect(submit).toBeInViewport({ ratio: 1 });
expect(
await dialog.locator("[data-dialog-body]").evaluate((node) => node.scrollWidth - node.clientWidth),
).toBeLessThanOrEqual(1);
await field.fill(renamed);
await expect(dialog.getByRole("alert")).toBeHidden();
await references.uncheck();
await comments.uncheck();
await submit.click();
await expect(dialog).toBeHidden();
await page.setViewportSize({ width: 1000, height: 700 });
await expect(page.getByRole("treeitem", { name: renamed, exact: true })).toBeVisible();
await expect(source).toHaveCount(0);
});
@@ -1,8 +1,25 @@
.form {
display: flex;
flex-direction: column;
.renameForm {
display: grid;
gap: var(--space-2);
padding: 14px;
padding: var(--space-3) var(--space-4);
}
.renameName {
display: grid;
gap: var(--space-1);
}
.renameOptions {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
gap: var(--space-2) var(--space-4);
overflow-wrap: anywhere;
}
.renameOptions > label {
min-width: 0;
max-width: 100%;
}
.refactorForm {
@@ -143,7 +143,7 @@ function Options({
disabled: boolean;
}) {
return (
<div className={styles.options}>
<div className={move ? styles.options : styles.renameOptions}>
<Checkbox
label="Search for references"
checked={value.references}
@@ -223,31 +223,33 @@ function RenameDialog({ request }: { request: Extract<FileRefactorRequest, { kin
]}
>
<form
className={styles.form}
className={styles.renameForm}
onSubmit={(e) => {
e.preventDefault();
submit();
}}
>
<label className={styles.fieldLabel} htmlFor="file-rename-name">
{request.dir
? tx`Rename directory '${current}' and its usages to:`
: tx`Rename file '${current}' and its usages to:`}
</label>
<Input
id="file-rename-name"
ref={input}
value={name}
disabled={busy}
invalid={!!error}
aria-label="New name"
onChange={(e) => setName(e.target.value)}
/>
{error && (
<div className={styles.error} role="alert">
{error}
</div>
)}
<div className={styles.renameName}>
<label className={styles.fieldLabel} htmlFor="file-rename-name">
{request.dir
? tx`Rename directory '${current}' and its usages to:`
: tx`Rename file '${current}' and its usages to:`}
</label>
<Input
id="file-rename-name"
ref={input}
value={name}
disabled={busy}
invalid={!!error}
aria-label="New name"
onChange={(e) => setName(e.target.value)}
/>
{error && (
<div className={styles.error} role="alert">
{error}
</div>
)}
</div>
<Options value={options} onChange={setOptions} move={false} disabled={busy} />
</form>
</Dialog>