fix(webui): restore navigation after automation deletion

Let the automation detail dialog own the background interaction lock instead of nesting a second modal menu. Overlapping exit lifecycles during deletion could leave body pointer events disabled after all dialogs closed.

Cover confirmed and cancelled deletion with animated Radix lifecycle tests and assert that sidebar navigation works after dismissal.

Refs NAN-117.
This commit is contained in:
Xubin Ren committed 2026-09-11 21:37:07 +08:00
1 parent c3fb819203
commit a2e33893e1
2 files changed
+64 -3

No files matched your search

@@ -553,7 +553,8 @@ function AutomationDetailPanel({
{actionKey === `${job.enabled ? "disable" : "enable"}:${job.id}` ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden /> : null}
{job.enabled ? tx("settings.automations.pause", "Pause") : tx("settings.automations.resume", "Resume")}
</Button>
<DropdownMenu>
{/* The detail dialog owns modality, including during the delete handoff. */}
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon" className="h-8 w-8 rounded-full text-muted-foreground" disabled={busy} aria-label={tx("settings.automations.moreActions", "More actions")}>
<MoreHorizontal className="h-4 w-4" aria-hidden />
+62 -2
View File
@@ -1,9 +1,9 @@
import { useState } from "react";
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from "vitest";
import { AutomationEditDialog, AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
import { AutomationDeleteDialog, AutomationEditDialog, AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
import type { AutomationFilter, AutomationSort } from "@/components/settings/system/AutomationsSettings";
import type { SessionAutomationJob } from "@/lib/types";
@@ -462,6 +462,66 @@ describe("Automation task list and detail sheet", () => {
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
it.each(["Cancel", "Delete"])("unlocks navigation after the real deletion flow ends with %s", async (operation) => {
const previousPointerEvents = document.body.style.pointerEvents;
onTestFinished(() => {
cleanup();
document.body.style.pointerEvents = previousPointerEvents;
});
// Exercise the real animated Radix presence lifecycle. The parent dialog
// may finish its exit before its nested menu; both must release modality.
const getStyle = window.getComputedStyle.bind(window);
vi.spyOn(window, "getComputedStyle").mockImplementation((node) => {
const style = getStyle(node);
if (!["menu", "dialog"].includes(node.getAttribute("role") ?? "")) return style;
return new Proxy(style, {
get(target, property) {
if (property === "animationName") return node.getAttribute("data-state") === "closed" ? "exit" : "enter";
const value = Reflect.get(target, property, target);
return typeof value === "function" ? value.bind(target) : value;
},
});
});
const finishExit = (node: HTMLElement) => {
const exit = new Event("animationend", { bubbles: true });
Object.defineProperty(exit, "animationName", { value: "exit" });
fireEvent(node, exit);
};
const user = userEvent.setup();
const navigate = vi.fn();
function DeletionHarness() {
const [jobs, setJobs] = useState([task, systemTask]);
const [pending, setPending] = useState<SessionAutomationJob | null>(null);
return <>
<button onClick={navigate}>Sidebar Apps</button>
<AutomationDeleteDialog job={pending} deleting={false}
onOpenChange={(open) => { if (!open) setPending(null); }}
onConfirm={(job) => {
setJobs((items) => items.filter((item) => item.id !== job.id));
setPending(null);
}} />
<Harness payload={{ jobs }} onRequestDelete={setPending} />
</>;
}
render(<DeletionHarness />);
await user.click(screen.getByRole("button", { name: /PR watch/ }));
const detail = screen.getByRole("dialog", { name: "PR watch" });
await user.click(screen.getByRole("button", { name: "More actions" }));
expect(document.body.style.pointerEvents).toBe("none");
await user.click(screen.getByRole("menuitem", { name: "Delete" }));
expect(detail).toHaveAttribute("data-state", "closed");
finishExit(detail);
const confirmation = await screen.findByRole("dialog", { name: "Delete automation" });
expect(document.body.style.pointerEvents).toBe("none");
await user.click(within(confirmation).getByRole("button", { name: operation, exact: true }));
finishExit(confirmation);
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
expect(document.body.style.pointerEvents).not.toBe("none");
await user.click(screen.getByRole("button", { name: "Sidebar Apps" }));
expect(navigate).toHaveBeenCalledOnce();
expect(screen.queryByRole("button", { name: /PR watch/ }) !== null).toBe(operation === "Cancel");
});
it("returns keyboard focus to the task after cancelling or saving the real editor", async () => {
const user = userEvent.setup();
const save = vi.fn();