feat(webui): simplify automation management and unify disclosure motion
Replace the dense automation workspace with a calm list and on-demand details, show current linked-chat titles, and remember manual system-task expansion preferences. Reuse disclosure transitions across expandable controls, preserve drafts and focus through closing, and release large diffs after their exit animation. Refs NAN-116
This commit is contained in:
1 parent
90b889394f
commit
1640784d45
37 files changed
+1746
-721
No files matched your search
@@ -848,7 +848,7 @@ describe("AgentActivityCluster", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps long file edit diffs collapsed until opened", () => {
|
||||
it("keeps long file edit diffs lazy and releases them after closing", async () => {
|
||||
localStorage.setItem(
|
||||
"nanobot-webui.settings-preferences",
|
||||
JSON.stringify({ fileEditDisplayMode: "diff" }),
|
||||
@@ -917,10 +917,20 @@ describe("AgentActivityCluster", () => {
|
||||
"Show 5 more lines",
|
||||
);
|
||||
|
||||
const content = document.getElementById(toggle.getAttribute("aria-controls")!)!;
|
||||
let finish!: () => void;
|
||||
const finished = new Promise<void>((resolve) => { finish = resolve; });
|
||||
Object.defineProperty(content, "getAnimations", { value: () => [{ finished }] });
|
||||
fireEvent.click(toggle);
|
||||
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
expect(content).toHaveAttribute("inert");
|
||||
expect(screen.getByTestId("file-edit-diff")).toBeInTheDocument();
|
||||
await act(async () => { finish(); });
|
||||
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
|
||||
fireEvent.click(toggle);
|
||||
expect(screen.getByText("line-160")).toBeInTheDocument();
|
||||
expect(screen.queryByText("line-161")).not.toBeInTheDocument();
|
||||
} finally {
|
||||
localStorage.removeItem("nanobot-webui.settings-preferences");
|
||||
}
|
||||
|
||||
@@ -1439,11 +1439,18 @@ describe("App layout", () => {
|
||||
expect(within(automationsMain as HTMLElement).queryByText("Settings")).not.toBeInTheDocument();
|
||||
expect(screen.getAllByText("Daily repo check").length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getAllByText("Check the repo status").length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Daily repo check/ }));
|
||||
expect(screen.getAllByText("Release prep").length).toBeGreaterThanOrEqual(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Done", exact: true }));
|
||||
expect(screen.getByText("WeChat quiz")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /WeChat quiz/ }));
|
||||
expect(screen.getByText("WeChat")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Done", exact: true }));
|
||||
expect(screen.queryByText("weixin:wx-chat")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("memory with dream state")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "true");
|
||||
expect(screen.getByText("heartbeat")).toBeInTheDocument();
|
||||
expect(within(sidebar).getByRole("button", { name: "Automations" })).toHaveAttribute(
|
||||
"aria-current",
|
||||
@@ -1451,6 +1458,7 @@ describe("App layout", () => {
|
||||
);
|
||||
expect(document.title).toBe("Automations · nanobot");
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
const searchInput = within(automationsMain as HTMLElement).getByPlaceholderText(
|
||||
"Search task, message, linked chat, or schedule",
|
||||
);
|
||||
@@ -1463,6 +1471,54 @@ describe("App layout", () => {
|
||||
expect(screen.getAllByText("WeChat quiz").length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("keeps automation linked-chat titles in sync with live sidebar renames", async () => {
|
||||
const key = "websocket:linked-chat";
|
||||
mockSessions = [{
|
||||
key, channel: "websocket", chatId: "linked-chat", createdAt: null, updatedAt: null,
|
||||
title: "Stored title", preview: "Original preview",
|
||||
}];
|
||||
const sidebarState: SidebarStatePayload = {
|
||||
schema_version: 1, pinned_keys: [], archived_keys: [], session_order: [],
|
||||
title_overrides: { [key]: "推特大战场" }, project_name_overrides: {},
|
||||
tags_by_key: {}, collapsed_groups: {}, workbench: { version: 1, tabs: {} },
|
||||
view: { density: "comfortable", show_previews: false, show_timestamps: false,
|
||||
show_archived: false, sort: "updated_desc" },
|
||||
};
|
||||
mockFetchRoutes({
|
||||
"/api/settings": baseSettingsPayload(),
|
||||
"/api/webui/sidebar-state": sidebarState,
|
||||
"/api/webui/automations": { jobs: [{
|
||||
id: "reminder", name: "Drink water", enabled: true,
|
||||
schedule: { kind: "every", every_ms: 60_000 },
|
||||
payload: { message: "Take a break" }, state: {},
|
||||
origin: { session_key: key, channel: "websocket", chat_id: "linked-chat",
|
||||
title: "Stored title", preview: "Original preview" },
|
||||
}] },
|
||||
});
|
||||
render(<App />);
|
||||
const sidebar = await screen.findByRole("navigation", { name: "Sidebar navigation" });
|
||||
await within(sidebar).findByRole("button", { name: "推特大战场", exact: true });
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "Automations" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: /Drink water/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "Drink water" });
|
||||
expect(within(dialog).getByRole("link", { name: "推特大战场" })).toHaveAttribute(
|
||||
"href", "#/chat/websocket%3Alinked-chat",
|
||||
);
|
||||
for (const title of ["新会话名称", ""]) {
|
||||
act(() => {
|
||||
sidebarStateUpdateHandlers.forEach((handler) => handler({
|
||||
...sidebarState, title_overrides: title ? { [key]: title } : {},
|
||||
}));
|
||||
});
|
||||
const expected = title || "Stored title";
|
||||
expect(within(sidebar).getByText(expected)).toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("link", { name: expected })).toHaveAttribute(
|
||||
"href", "#/chat/websocket%3Alinked-chat",
|
||||
);
|
||||
}
|
||||
expect(requestMutationSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("edits a past one-time automation without resubmitting its old schedule", async () => {
|
||||
const pastOneShot = {
|
||||
id: "past-one-shot",
|
||||
@@ -1507,7 +1563,9 @@ describe("App layout", () => {
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "Automations" }));
|
||||
|
||||
expect((await screen.findAllByText("Past one-shot")).length).toBeGreaterThanOrEqual(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Past one-shot/ }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit" }));
|
||||
await screen.findByRole("dialog", { name: "Edit automation" });
|
||||
expect(screen.queryByText("Run time must be in the future.")).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText("Update the prompt and schedule. The linked chat stays unchanged."),
|
||||
@@ -1593,18 +1651,19 @@ describe("App layout", () => {
|
||||
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "Automations" }));
|
||||
|
||||
const detailHeading = await screen.findByRole("heading", { name: "Long detail automation" });
|
||||
const detailPanel = detailHeading.closest("article") as HTMLElement;
|
||||
expect(detailPanel).not.toBeNull();
|
||||
const message = Array.from(detailPanel.querySelectorAll("section div")).find(
|
||||
fireEvent.click(await screen.findByRole("button", { name: /Long detail automation/ }));
|
||||
const detailPanel = await screen.findByRole("dialog", { name: "Long detail automation" });
|
||||
const message = Array.from(detailPanel.querySelectorAll("section p")).find(
|
||||
(node) => node.textContent === longMessage,
|
||||
) as HTMLElement | undefined;
|
||||
expect(message).toBeTruthy();
|
||||
expect(message!).toHaveClass("line-clamp-6");
|
||||
const preview = message!.closest(".expandable-text")!;
|
||||
expect(preview).toHaveAttribute("data-state", "closed");
|
||||
|
||||
fireEvent.click(within(detailPanel).getByRole("button", { name: "Show full message" }));
|
||||
expect(within(detailPanel).getByRole("button", { name: "Show less" })).toBeInTheDocument();
|
||||
expect(message!).not.toHaveClass("line-clamp-6");
|
||||
expect(preview).toHaveAttribute("data-state", "open");
|
||||
expect(preview).toContainElement(message!);
|
||||
|
||||
expect(within(detailPanel).queryByText("Recent health")).not.toBeInTheDocument();
|
||||
expect(within(detailPanel).queryByRole("button", { name: /Run history/ })).not.toBeInTheDocument();
|
||||
@@ -1665,10 +1724,11 @@ describe("App layout", () => {
|
||||
const automationsMain = heading.closest("main");
|
||||
expect(automationsMain).not.toBeNull();
|
||||
expect(within(automationsMain as HTMLElement).queryByText("设置")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("任务队列")).toBeInTheDocument();
|
||||
expect(screen.queryByText("任务队列")).not.toBeInTheDocument();
|
||||
expect(screen.getAllByText("每日检查").length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getAllByText("检查仓库状态").length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText("每 1天")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /每日检查/ }));
|
||||
expect(within(screen.getByRole("dialog", { name: "每日检查" })).getByText(/每 1天/)).toBeInTheDocument();
|
||||
expect(screen.queryByText("最近健康状态")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("近期无问题")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Workspace automations")).not.toBeInTheDocument();
|
||||
|
||||
@@ -0,0 +1,562 @@
|
||||
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 { AutomationEditDialog, AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
|
||||
import type { AutomationFilter, AutomationSort } from "@/components/settings/system/AutomationsSettings";
|
||||
import type { SessionAutomationJob } from "@/lib/types";
|
||||
|
||||
const now = Date.now();
|
||||
const task: SessionAutomationJob = {
|
||||
id: "private-job-id", name: "PR watch", enabled: true,
|
||||
schedule: { kind: "every", every_ms: 1_800_000 },
|
||||
payload: { message: "Check open pull requests and report failed CI." },
|
||||
state: { next_run_at_ms: now + 540_000, last_run_at_ms: now - 60_000, last_status: "ok" },
|
||||
origin: { channel: "websocket", session_key: "websocket:demo", title: "nanobot-development" },
|
||||
created_at_ms: now - 86_400_000,
|
||||
};
|
||||
const systemTask: SessionAutomationJob = {
|
||||
...task, id: "heartbeat", name: "heartbeat", protected: true, origin: null,
|
||||
payload: { message: "" },
|
||||
};
|
||||
type Props = Partial<React.ComponentProps<typeof AutomationsSettings>>;
|
||||
const SYSTEM_TASKS_OPEN_STORAGE_KEY = "nanobot-webui.automation-system-tasks-open";
|
||||
|
||||
function Harness({ payload = { jobs: [task, systemTask] }, ...props }: Props) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [filter, setFilter] = useState<AutomationFilter>("all");
|
||||
const [sort, setSort] = useState<AutomationSort>("next");
|
||||
return <AutomationsSettings
|
||||
payload={payload} loading={false} query={query} filter={filter} sort={sort}
|
||||
actionKey={null} error={null} onQueryChange={setQuery} onFilterChange={setFilter}
|
||||
onSortChange={setSort} onAction={() => {}} onRequestEdit={() => {}}
|
||||
onRequestDelete={() => {}} {...props}
|
||||
/>;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
window.localStorage.removeItem(SYSTEM_TASKS_OPEN_STORAGE_KEY);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.restoreAllMocks();
|
||||
window.localStorage.removeItem(SYSTEM_TASKS_OPEN_STORAGE_KEY);
|
||||
});
|
||||
|
||||
describe("Automation task list and detail sheet", () => {
|
||||
it("opens system tasks by default and remembers manual changes across visits", () => {
|
||||
const first = render(<Harness />);
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "true");
|
||||
expect(window.localStorage.getItem(SYSTEM_TASKS_OPEN_STORAGE_KEY)).toBeNull();
|
||||
fireEvent.click(screen.getByRole("button", { name: "System tasks 1" }));
|
||||
first.unmount();
|
||||
|
||||
const second = render(<Harness />);
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "false");
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "System tasks 1" }));
|
||||
second.unmount();
|
||||
|
||||
render(<Harness />);
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "true");
|
||||
expect(window.localStorage.getItem(SYSTEM_TASKS_OPEN_STORAGE_KEY)).toBe("true");
|
||||
});
|
||||
|
||||
it("does not replace a remembered collapse when search reveals system tasks", () => {
|
||||
window.localStorage.setItem(SYSTEM_TASKS_OPEN_STORAGE_KEY, "false");
|
||||
const view = render(<Harness query="heartbeat" />);
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
expect(window.localStorage.getItem(SYSTEM_TASKS_OPEN_STORAGE_KEY)).toBe("false");
|
||||
view.unmount();
|
||||
render(<Harness />);
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "false");
|
||||
});
|
||||
|
||||
it("keeps the system toggle usable when browser storage is unavailable", () => {
|
||||
vi.spyOn(window.localStorage, "getItem").mockImplementation(() => { throw new Error("Blocked"); });
|
||||
vi.spyOn(window.localStorage, "setItem").mockImplementation(() => { throw new Error("Blocked"); });
|
||||
render(<Harness />);
|
||||
const toggle = screen.getByRole("button", { name: "System tasks 1" });
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
});
|
||||
|
||||
it.each(["Done", "Escape", "removed", "Edit", "Edit removed"])("finishes the detail exit before cleanup and handoff: %s", async (action) => {
|
||||
// Happy DOM has no CSS animations. Give Radix live animation names so its
|
||||
// real presence lifecycle runs, including the outer portal's ref boundary.
|
||||
const getStyle = window.getComputedStyle.bind(window);
|
||||
vi.spyOn(window, "getComputedStyle").mockImplementation((node) => {
|
||||
const style = getStyle(node);
|
||||
if (node.getAttribute("role") !== "dialog") 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 user = userEvent.setup();
|
||||
const edit = vi.fn();
|
||||
const { rerender } = render(<Harness onRequestEdit={edit} />);
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
await user.click(row);
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
if (action === "removed") rerender(<Harness payload={{ jobs: [] }} onRequestEdit={edit} />);
|
||||
else if (action === "Escape") fireEvent.keyDown(dialog, { key: "Escape" });
|
||||
else fireEvent.click(within(dialog).getByRole("button", { name: action.startsWith("Edit") ? "Edit" : action, exact: true }));
|
||||
if (action === "Edit removed") rerender(<Harness payload={{ jobs: [] }} onRequestEdit={edit} />);
|
||||
expect(dialog).toBeInTheDocument();
|
||||
expect(dialog).toHaveAttribute("data-state", "closed");
|
||||
expect(dialog).toHaveAttribute("inert");
|
||||
expect(dialog).toHaveTextContent("PR watch");
|
||||
expect(edit).not.toHaveBeenCalled();
|
||||
const exit = new Event("animationend", { bubbles: true });
|
||||
Object.defineProperty(exit, "animationName", { value: "exit" });
|
||||
fireEvent(dialog, exit);
|
||||
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
||||
if (action.includes("removed")) expect(screen.getByRole("heading", { name: "Automations" })).toHaveFocus();
|
||||
else await waitFor(() => expect(row).toHaveFocus());
|
||||
if (action === "Edit") {
|
||||
expect(edit).toHaveBeenCalledOnce();
|
||||
expect(edit).toHaveBeenCalledWith(task);
|
||||
}
|
||||
else expect(edit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps the default list quiet and opens details only on request", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /^Active/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Create in chat" })).not.toBeInTheDocument();
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
await user.click(row);
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
expect(dialog).toHaveAccessibleDescription(/Every 30 minutes/);
|
||||
expect(within(dialog).getByText("Instructions")).toBeVisible();
|
||||
expect(within(dialog).getByRole("link", { name: "Open a chat" })).toHaveAttribute(
|
||||
"href", "#/chat/websocket%3Ademo",
|
||||
);
|
||||
expect(within(dialog).getByRole("button", { name: "More details" })).toHaveAttribute("aria-expanded", "false");
|
||||
await user.click(within(dialog).getByRole("button", { name: "Done" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(row).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "PR watch" })).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(row).toHaveFocus();
|
||||
});
|
||||
|
||||
it("keeps a text-only empty state when only system tasks exist", () => {
|
||||
render(<Harness payload={{ jobs: [systemTask] }} />);
|
||||
expect(screen.getByText("No automations yet.")).toBeVisible();
|
||||
expect(screen.getByText("Tell nanobot in a chat what you'd like it to do on a schedule.")).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Create in chat" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Search and filter" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: /heartbeat/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "heartbeat" });
|
||||
expect(within(dialog).queryByRole("button", { name: "Edit" })).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("button", { name: "Pause" })).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("button", { name: "More actions" })).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByText("Linked chat")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("distinguishes a finished one-time task from a task with no scheduled run", () => {
|
||||
render(<Harness payload={{ jobs: [{ ...task, delete_after_run: true,
|
||||
state: { last_status: "ok", next_run_at_ms: null } }] }} />);
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toHaveTextContent("Completed");
|
||||
expect(screen.queryByText("No next run")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each(["heartbeat", "dream", "other-system-job"])("shows only actual task data for %s", (id) => {
|
||||
render(<Harness payload={{ jobs: [{ ...systemTask, id, name: id, state: {
|
||||
next_run_at_ms: now + 540_000,
|
||||
} }] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: new RegExp(id) }));
|
||||
const dialog = screen.getByRole("dialog", { name: id });
|
||||
expect(dialog).toHaveClass("max-w-[440px]");
|
||||
expect(dialog).not.toHaveAttribute("aria-describedby");
|
||||
expect(dialog.querySelector("p")).toBeNull();
|
||||
expect(within(dialog).queryByText("Instructions")).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByText("System-managed automation")).not.toBeInTheDocument();
|
||||
for (const label of ["Schedule", "Next run", "Last run"]) {
|
||||
expect(within(dialog).getByText(label).tagName).toBe("DT");
|
||||
}
|
||||
expect(within(dialog).getByText("Every 30 minutes")).toBeVisible();
|
||||
expect(within(dialog).getByText("Not run yet")).toBeVisible();
|
||||
expect(within(dialog).getAllByRole("button")).toHaveLength(2);
|
||||
expect(within(dialog).getByRole("button", { name: "Done" })).toHaveClass("text-foreground");
|
||||
const toggle = within(dialog).getByRole("button", { name: "More details" });
|
||||
const metadata = document.getElementById(toggle.getAttribute("aria-controls")!)!;
|
||||
expect(metadata).toHaveAttribute("data-state", "closed");
|
||||
fireEvent.click(toggle);
|
||||
expect(metadata).toHaveAttribute("data-state", "open");
|
||||
expect(within(metadata).getByText("ID")).toBeVisible();
|
||||
fireEvent.click(toggle);
|
||||
expect(metadata).toHaveAttribute("data-state", "closed");
|
||||
expect(metadata).toHaveAttribute("inert");
|
||||
expect(metadata).toHaveClass("inline-disclosure");
|
||||
expect(within(metadata).getByText("ID")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps system failures visible and does not infer purpose from a task name", () => {
|
||||
render(<Harness payload={{ jobs: [{ ...systemTask, id: "other-system-job", name: "heartbeat",
|
||||
state: { last_status: "error", last_error: "Background check failed", next_run_at_ms: null },
|
||||
}] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /heartbeat/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "heartbeat" });
|
||||
expect(within(dialog).queryByText("System-managed automation")).not.toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("alert")).toHaveTextContent("Background check failed");
|
||||
expect(within(dialog).getByText("Failed")).toBeVisible();
|
||||
expect(within(dialog).getByText("No next run")).toBeVisible();
|
||||
expect(dialog).not.toHaveAttribute("aria-describedby");
|
||||
});
|
||||
|
||||
it("reuses compact settings rows for system tasks without changing personal rows", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [task, systemTask, {
|
||||
...systemTask, id: "dream", name: "dream",
|
||||
state: { last_status: "error", last_error: "Memory update failed" },
|
||||
}] }} />);
|
||||
const personalRow = screen.getByRole("button", { name: /PR watch/ });
|
||||
expect(personalRow).toHaveClass("min-h-[92px]");
|
||||
expect(personalRow).not.toHaveClass("settings-list-row");
|
||||
const list = screen.getByRole("list", { name: "System tasks" });
|
||||
expect(list.parentElement).toHaveClass("rounded-panel", "bg-settings-surface");
|
||||
const heartbeat = within(list).getByRole("button", { name: /heartbeat/ });
|
||||
expect(heartbeat).toHaveClass("settings-list-row", "settings-hover");
|
||||
expect(heartbeat).not.toHaveClass("min-h-[92px]");
|
||||
expect(within(list).queryByText("System-managed automation")).not.toBeInTheDocument();
|
||||
expect(within(list).getByText("Memory update failed")).toBeVisible();
|
||||
expect(within(list).getByText("Needs attention")).toBeVisible();
|
||||
heartbeat.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "heartbeat" })).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(heartbeat).toHaveFocus());
|
||||
});
|
||||
|
||||
it("keeps system tasks mounted for shared expand and collapse transitions without hidden tab stops", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const toggle = screen.getByRole("button", { name: "System tasks 1" });
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
await user.click(toggle);
|
||||
const drawer = document.getElementById(toggle.getAttribute("aria-controls")!);
|
||||
expect(drawer).toHaveClass("inline-disclosure");
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
expect(drawer).toHaveAttribute("aria-hidden", "true");
|
||||
expect(drawer!.firstElementChild).toHaveClass("inline-disclosure-clip");
|
||||
expect(drawer!.firstElementChild?.firstElementChild).toHaveClass("inline-disclosure-content");
|
||||
const row = within(drawer!).getByRole("button", { hidden: true });
|
||||
expect(row).toBeDisabled();
|
||||
toggle.focus();
|
||||
await user.tab();
|
||||
expect(row).not.toHaveFocus();
|
||||
|
||||
toggle.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
expect(drawer).toHaveAttribute("data-state", "open");
|
||||
expect(drawer).not.toHaveAttribute("aria-hidden");
|
||||
expect(row).toBeEnabled();
|
||||
await user.tab();
|
||||
expect(row).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "heartbeat" })).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(row).toHaveFocus());
|
||||
await user.tab({ shift: true });
|
||||
expect(toggle).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(document.getElementById("automation-system-tasks")).toBe(drawer);
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
expect(drawer).toHaveAttribute("aria-hidden", "true");
|
||||
expect(row).toBeDisabled();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
await user.click(toggle);
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBe(row);
|
||||
});
|
||||
|
||||
it("keeps search, status filters and sorting available on demand", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [task, { ...task, id: "paused", name: "Weekly review", enabled: false }, systemTask] }} />);
|
||||
await user.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
const search = screen.getByRole("textbox");
|
||||
await user.type(search, "chat:nanobot");
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
|
||||
await user.clear(search);
|
||||
await user.type(search, "heartbeat");
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "true");
|
||||
await user.clear(search);
|
||||
await user.click(screen.getByRole("button", { name: "Paused 1" }));
|
||||
expect(screen.queryByRole("button", { name: /PR watch/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /Weekly review/ })).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
expect(screen.getByRole("button", { name: "Paused 1" })).toHaveAttribute("aria-pressed", "true");
|
||||
await user.click(screen.getByRole("button", { name: "All 2" }));
|
||||
await user.click(screen.getByRole("button", { name: "Next run" }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Name" }));
|
||||
const rows = within(screen.getByRole("list", { name: "Your automations" })).getAllByRole("button");
|
||||
expect(rows[0]).toHaveTextContent("PR watch");
|
||||
});
|
||||
|
||||
it("uses live renamed chat titles in details and search without changing the bound task", async () => {
|
||||
const user = userEvent.setup();
|
||||
const action = vi.fn();
|
||||
const payload = { jobs: [task] };
|
||||
const { rerender } = render(<Harness payload={payload} onAction={action}
|
||||
titleOverrides={{ "websocket:demo": "推特大战场" }} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
const chatLink = within(dialog).getByRole("link", { name: "推特大战场" });
|
||||
expect(chatLink).toHaveAttribute("href", "#/chat/websocket%3Ademo");
|
||||
rerender(<Harness payload={payload} onAction={action}
|
||||
titleOverrides={{ "websocket:demo": "新会话名称" }} />);
|
||||
expect(within(dialog).getByRole("link", { name: "新会话名称" })).toBe(chatLink);
|
||||
await user.click(within(dialog).getByRole("button", { name: "Pause" }));
|
||||
expect(action).toHaveBeenCalledWith("disable", expect.objectContaining({
|
||||
id: task.id, payload: task.payload,
|
||||
origin: expect.objectContaining({ session_key: "websocket:demo" }),
|
||||
}));
|
||||
expect(task.origin?.title).toBe("nanobot-development");
|
||||
await user.click(within(dialog).getByRole("button", { name: "Done" }));
|
||||
await user.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
await user.type(screen.getByRole("textbox"), "chat:新会话名称");
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
|
||||
rerender(<Harness payload={payload} titleOverrides={{}} />);
|
||||
expect(screen.queryByRole("button", { name: /PR watch/ })).not.toBeInTheDocument();
|
||||
await user.clear(screen.getByRole("textbox"));
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
expect(screen.getByRole("link", { name: "nanobot-development" })).toHaveAttribute("href", "#/chat/websocket%3Ademo");
|
||||
});
|
||||
|
||||
it("retains the inspected task across refreshes and closes if it is removed", () => {
|
||||
const action = vi.fn();
|
||||
const { rerender } = render(<Harness onAction={action} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Pause" }));
|
||||
expect(action).toHaveBeenCalledWith("disable", task);
|
||||
rerender(<Harness payload={{ jobs: [{ ...task, enabled: false }] }} onAction={action} filter="active" />);
|
||||
expect(screen.getByRole("dialog", { name: "PR watch" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Resume" }));
|
||||
expect(action).toHaveBeenLastCalledWith("enable", { ...task, enabled: false });
|
||||
rerender(<Harness payload={{ jobs: [] }} />);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("focuses search on expansion and restores the toggle on Escape without clearing filters", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const toggle = screen.getByRole("button", { name: "Search and filter" });
|
||||
await user.click(toggle);
|
||||
const search = screen.getByRole("textbox");
|
||||
expect(search).toHaveFocus();
|
||||
await user.keyboard("PR");
|
||||
await user.keyboard("{Escape}");
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
expect(toggle).toHaveFocus();
|
||||
expect(search).toHaveValue("PR");
|
||||
expect(search).toBeDisabled();
|
||||
|
||||
await user.keyboard("{Enter}");
|
||||
expect(search).toHaveFocus();
|
||||
expect(search).toHaveValue("PR");
|
||||
fireEvent.keyDown(search, { key: "Escape", isComposing: true });
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
await user.click(screen.getByRole("button", { name: "Next run", exact: true }));
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
expect(screen.getByRole("button", { name: "Next run", exact: true })).toHaveFocus();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
expect(toggle).toHaveFocus();
|
||||
});
|
||||
|
||||
it("returns focus to the filter or page heading when the inspected row is no longer present", async () => {
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<Harness filter="active" />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
rerender(<Harness payload={{ jobs: [{ ...task, enabled: false }] }} filter="active" />);
|
||||
await user.click(screen.getByRole("button", { name: "Done" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Search and filter" })).toHaveFocus());
|
||||
|
||||
rerender(<Harness payload={{ jobs: [task] }} filter="all" />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
rerender(<Harness payload={{ jobs: [] }} filter="all" />);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("heading", { name: "Automations" })).toHaveFocus();
|
||||
expect(screen.getByText("No automations yet.")).toBeVisible();
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the filter drawer mounted for both transitions and disables hidden controls", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const toggle = screen.getByRole("button", { name: "Search and filter" });
|
||||
const drawer = document.getElementById(toggle.getAttribute("aria-controls")!)!;
|
||||
const search = within(drawer).getByRole("textbox", { hidden: true });
|
||||
expect(drawer).toHaveClass("inline-disclosure");
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
expect(drawer).toHaveAttribute("aria-hidden", "true");
|
||||
expect(drawer.firstElementChild).toHaveClass("inline-disclosure-clip");
|
||||
expect(drawer.firstElementChild?.firstElementChild).toHaveClass("inline-disclosure-content");
|
||||
for (const control of [search, ...within(drawer).getAllByRole("button", { hidden: true })]) {
|
||||
expect(control).toBeDisabled();
|
||||
}
|
||||
|
||||
await user.click(toggle);
|
||||
expect(drawer).toHaveAttribute("data-state", "open");
|
||||
expect(drawer).not.toHaveAttribute("aria-hidden");
|
||||
expect(screen.getByRole("textbox")).toBe(search);
|
||||
await user.type(search, "PR");
|
||||
await user.click(toggle);
|
||||
expect(document.getElementById("automation-view-options")).toBe(drawer);
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
expect(search).toHaveValue("PR");
|
||||
expect(search).toBeDisabled();
|
||||
await user.tab();
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toHaveFocus();
|
||||
|
||||
await user.click(toggle);
|
||||
await user.dblClick(toggle);
|
||||
expect(drawer).toHaveAttribute("data-state", "open");
|
||||
expect(screen.getByRole("textbox")).toBe(search);
|
||||
expect(search).toHaveValue("PR");
|
||||
await user.click(screen.getByRole("button", { name: "Next run", exact: true }));
|
||||
expect(screen.getByRole("menu")).toBeVisible();
|
||||
fireEvent.click(toggle);
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
await user.click(toggle);
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hands off editing and deletion without leaving a second modal open", async () => {
|
||||
const user = userEvent.setup();
|
||||
const edit = vi.fn();
|
||||
const remove = vi.fn();
|
||||
render(<Harness onRequestEdit={edit} onRequestDelete={remove} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
await user.click(screen.getByRole("button", { name: "Edit" }));
|
||||
await waitFor(() => expect(edit).toHaveBeenCalledWith(task));
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
await user.click(screen.getByRole("button", { name: "More actions" }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Delete" }));
|
||||
await waitFor(() => expect(remove).toHaveBeenCalledWith(task));
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("returns keyboard focus to the task after cancelling or saving the real editor", async () => {
|
||||
const user = userEvent.setup();
|
||||
const save = vi.fn();
|
||||
function EditorHarness() {
|
||||
const [editing, setEditing] = useState<SessionAutomationJob | null>(null);
|
||||
return <>
|
||||
<Harness onRequestEdit={setEditing} />
|
||||
<AutomationEditDialog job={editing} saving={false}
|
||||
onOpenChange={(open) => { if (!open) setEditing(null); }}
|
||||
onSave={(job, values) => { save(job, values); setEditing(null); }} />
|
||||
</>;
|
||||
}
|
||||
render(<EditorHarness />);
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
for (const operation of ["Cancel", "Save"]) {
|
||||
await user.click(row);
|
||||
await user.click(screen.getByRole("button", { name: "Edit", exact: true }));
|
||||
const editor = await screen.findByRole("dialog", { name: "Edit automation" });
|
||||
expect(screen.getAllByRole("dialog")).toHaveLength(1);
|
||||
if (operation === "Save") {
|
||||
await user.clear(within(editor).getByRole("textbox", { name: "Name", exact: true }));
|
||||
await user.type(within(editor).getByRole("textbox", { name: "Name", exact: true }), "Updated watch");
|
||||
}
|
||||
await user.click(within(editor).getByRole("button", { name: operation, exact: true }));
|
||||
await waitFor(() => expect(row).toHaveFocus());
|
||||
}
|
||||
expect(save).toHaveBeenCalledWith(task, expect.objectContaining({ name: "Updated watch" }));
|
||||
});
|
||||
|
||||
it("runs a linked task through the existing action and prevents duplicate actions while busy", async () => {
|
||||
const user = userEvent.setup();
|
||||
const action = vi.fn();
|
||||
const { rerender } = render(<Harness onAction={action} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
await user.click(screen.getByRole("button", { name: "More actions" }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Run now" }));
|
||||
expect(action).toHaveBeenCalledWith("run", task);
|
||||
rerender(<Harness actionKey="run:private-job-id" />);
|
||||
for (const name of ["Edit", "Pause", "More actions"]) {
|
||||
expect(screen.getByRole("button", { name })).toBeDisabled();
|
||||
}
|
||||
rerender(<Harness error="Unable to run task" />);
|
||||
expect(within(screen.getByRole("dialog")).getByRole("alert")).toHaveTextContent("Unable to run task");
|
||||
});
|
||||
|
||||
it("does not allow running a pending task or resuming an unlinked task", async () => {
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<Harness payload={{ jobs: [{ ...task, state: { pending: true } }] }} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
await user.click(screen.getByRole("button", { name: "More actions" }));
|
||||
expect(screen.getByRole("menuitem", { name: "Run now" })).toHaveAttribute("aria-disabled", "true");
|
||||
await user.keyboard("{Escape}");
|
||||
rerender(<Harness payload={{ jobs: [{ ...task, enabled: false, origin: null }] }} />);
|
||||
expect(screen.getByRole("button", { name: "Resume" })).toBeDisabled();
|
||||
expect(screen.queryByRole("link", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps local trigger commands and excludes the scheduled-run action", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [{
|
||||
...task, kind: "local_trigger", schedule: { kind: "local" },
|
||||
trigger: { id: "trigger-1", command: "nanobot trigger run trigger-1" },
|
||||
}] }} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
expect(screen.getByText("Command")).toBeVisible();
|
||||
expect(within(screen.getByRole("dialog")).getByText("nanobot trigger run trigger-1")).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Copy" })).toBeEnabled();
|
||||
await user.click(screen.getByRole("button", { name: "More actions" }));
|
||||
expect(screen.queryByRole("menuitem", { name: "Run now" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows paused failures honestly and does not fabricate successful runs", () => {
|
||||
render(<Harness payload={{ jobs: [{
|
||||
...task, enabled: false, state: { last_status: "error", last_error: "Connection interrupted" },
|
||||
}, { ...systemTask, state: { last_status: "error" } }] }} />);
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
expect(row).toHaveTextContent("Needs attention");
|
||||
expect(row).toHaveTextContent("Paused");
|
||||
expect(screen.getByRole("button", { name: /System tasks 1 Needs attention/ })).toBeVisible();
|
||||
fireEvent.click(row);
|
||||
expect(within(screen.getByRole("dialog")).getByText("Failed")).toBeVisible();
|
||||
expect(within(screen.getByRole("dialog")).queryByText(/Completed/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("allows expanding long instructions without exposing technical metadata by default", () => {
|
||||
render(<Harness payload={{ jobs: [{ ...task, payload: { message: "Long instructions. ".repeat(50) }, state: {} }] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(within(dialog).getByText("Not run yet")).toBeVisible();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Show full message" }));
|
||||
expect(within(dialog).getByRole("button", { name: "Show less" })).toHaveAttribute("aria-expanded", "true");
|
||||
const disclosure = within(dialog).getByRole("button", { name: "More details" });
|
||||
expect(disclosure).toHaveAttribute("aria-expanded", "false");
|
||||
fireEvent.click(within(dialog).getByText("More details"));
|
||||
expect(disclosure).toHaveAttribute("aria-expanded", "true");
|
||||
expect(within(dialog).getByText(task.id)).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
import { act, fireEvent, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { Disclosure, DisclosureContent } from "@/components/ui/disclosure";
|
||||
import { ExpandableText } from "@/components/ui/expandable-text";
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("shared disclosures", () => {
|
||||
it("releases disposable content only after all closing transitions finish", async () => {
|
||||
const closed = vi.fn();
|
||||
const { container, rerender } = render(<DisclosureContent open onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
let finishHeight!: () => void;
|
||||
let finishOpacity!: () => void;
|
||||
const height = new Promise<void>((resolve) => { finishHeight = resolve; });
|
||||
const opacity = new Promise<void>((resolve) => { finishOpacity = resolve; });
|
||||
Object.defineProperty(container.firstElementChild, "getAnimations", {
|
||||
value: () => [{ finished: height }, { finished: opacity }],
|
||||
});
|
||||
rerender(<DisclosureContent open={false} onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
expect(closed).not.toHaveBeenCalled();
|
||||
expect(container.firstElementChild).toHaveAttribute("inert");
|
||||
await act(async () => { finishHeight(); });
|
||||
expect(closed).not.toHaveBeenCalled();
|
||||
await act(async () => { finishOpacity(); });
|
||||
expect(closed).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it.each(["reopen", "unmount"])("does not release content after %s interrupts a close", async (action) => {
|
||||
const closed = vi.fn();
|
||||
let finish!: () => void;
|
||||
const finished = new Promise<void>((resolve) => { finish = resolve; });
|
||||
const { container, rerender, unmount } = render(<DisclosureContent open onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
Object.defineProperty(container.firstElementChild, "getAnimations", { value: () => [{ finished }] });
|
||||
rerender(<DisclosureContent open={false} onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
if (action === "reopen") rerender(<DisclosureContent open onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
else unmount();
|
||||
await act(async () => { finish(); });
|
||||
expect(closed).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("finishes immediately without motion and also handles a cancelled transition", async () => {
|
||||
const closed = vi.fn();
|
||||
const { container, rerender } = render(<DisclosureContent open onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
const animations = vi.fn((): Array<{ finished: Promise<void> }> => []);
|
||||
Object.defineProperty(container.firstElementChild, "getAnimations", { value: animations });
|
||||
rerender(<DisclosureContent open={false} onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
expect(closed).toHaveBeenCalledOnce();
|
||||
rerender(<DisclosureContent open onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
let cancel!: () => void;
|
||||
const finished = new Promise<void>((_resolve, reject) => { cancel = () => reject(new Error("motion disabled")); });
|
||||
animations.mockReturnValue([{ finished }]);
|
||||
rerender(<DisclosureContent open={false} onExitComplete={closed}>Diff</DisclosureContent>);
|
||||
await act(async () => { cancel(); });
|
||||
expect(closed).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("animates both ways without discarding form drafts, and hides collapsed controls", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Disclosure summary="More details"><input aria-label="Draft" defaultValue="initial" /></Disclosure>);
|
||||
const toggle = screen.getByRole("button", { name: "More details" });
|
||||
const content = document.getElementById(toggle.getAttribute("aria-controls")!)!;
|
||||
expect(content).toHaveClass("inline-disclosure");
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
expect(content).toHaveAttribute("inert");
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
|
||||
toggle.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
||||
expect(content).not.toHaveAttribute("inert");
|
||||
const input = screen.getByRole("textbox", { name: "Draft" });
|
||||
await user.clear(input);
|
||||
await user.type(input, "unsaved draft");
|
||||
await user.click(toggle);
|
||||
expect(toggle).toHaveFocus();
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
expect(content).toHaveAttribute("aria-hidden", "true");
|
||||
expect(content).toHaveAttribute("inert");
|
||||
expect(input).toBeInTheDocument();
|
||||
await user.keyboard(" ");
|
||||
expect(screen.getByRole("textbox", { name: "Draft" })).toBe(input);
|
||||
expect(input).toHaveValue("unsaved draft");
|
||||
});
|
||||
|
||||
it("keeps independent IDs and handles rapid reversals without timers or stale closing state", () => {
|
||||
render(<><Disclosure summary="First">One</Disclosure><Disclosure summary="Second">Two</Disclosure></>);
|
||||
const first = screen.getByRole("button", { name: "First" });
|
||||
const second = screen.getByRole("button", { name: "Second" });
|
||||
expect(first.getAttribute("aria-controls")).not.toBe(second.getAttribute("aria-controls"));
|
||||
const content = document.getElementById(first.getAttribute("aria-controls")!)!;
|
||||
for (let index = 0; index < 7; index++) fireEvent.click(first);
|
||||
expect(content).toHaveAttribute("data-state", "open");
|
||||
expect(second).toHaveAttribute("aria-expanded", "false");
|
||||
fireEvent.click(first);
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("expandable text", () => {
|
||||
it("measures natural text height, handles resize and content changes, and preserves one text node", () => {
|
||||
let fullHeight = 280;
|
||||
let resize: ResizeObserverCallback | undefined;
|
||||
const disconnect = vi.fn();
|
||||
vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockImplementation(() => fullHeight);
|
||||
const getStyle = window.getComputedStyle.bind(window);
|
||||
vi.spyOn(window, "getComputedStyle").mockImplementation((node) => node.tagName === "P"
|
||||
? { lineHeight: "20px" } as CSSStyleDeclaration : getStyle(node));
|
||||
vi.stubGlobal("ResizeObserver", class {
|
||||
constructor(callback: ResizeObserverCallback) { resize = callback; }
|
||||
observe() {}
|
||||
disconnect = disconnect;
|
||||
});
|
||||
const { container, rerender, unmount } = render(
|
||||
<ExpandableText lines={6} expanded={false}>Long instructions</ExpandableText>,
|
||||
);
|
||||
const viewport = container.firstElementChild!;
|
||||
const text = screen.getByText("Long instructions");
|
||||
expect(viewport).toHaveStyle({ height: "120px" });
|
||||
rerender(<ExpandableText lines={6} expanded>Long instructions</ExpandableText>);
|
||||
expect(viewport).toHaveStyle({ height: "280px" });
|
||||
expect(screen.getByText("Long instructions")).toBe(text);
|
||||
fullHeight = 380;
|
||||
act(() => resize?.([], {} as ResizeObserver));
|
||||
expect(viewport).toHaveStyle({ height: "380px" });
|
||||
rerender(<ExpandableText lines={6} expanded={false}>Long instructions</ExpandableText>);
|
||||
expect(viewport).toHaveStyle({ height: "120px" });
|
||||
fullHeight = 40;
|
||||
rerender(<ExpandableText lines={6} expanded={false}>Short replacement</ExpandableText>);
|
||||
expect(viewport).toHaveStyle({ height: "40px" });
|
||||
expect(container.querySelectorAll("p")).toHaveLength(1);
|
||||
unmount();
|
||||
expect(disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -840,12 +840,19 @@ describe("MessageBubble", () => {
|
||||
render(<MessageBubble message={message} />);
|
||||
const toggle = screen.getByRole("button", { name: /used 2 tools/i });
|
||||
|
||||
expect(screen.queryByText('weather("get")')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('search "hk weather"')).not.toBeInTheDocument();
|
||||
const content = document.getElementById(toggle.getAttribute("aria-controls")!)!;
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
expect(content).toHaveAttribute("inert");
|
||||
expect(screen.queryByRole("list")).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(toggle);
|
||||
expect(screen.getByText('weather("get")')).toBeInTheDocument();
|
||||
expect(screen.getByText('search "hk weather"')).toBeInTheDocument();
|
||||
expect(content).toHaveAttribute("data-state", "open");
|
||||
fireEvent.click(toggle);
|
||||
expect(content).toHaveAttribute("data-state", "closed");
|
||||
expect(content).toHaveAttribute("aria-hidden", "true");
|
||||
expect(screen.getByText('weather("get")')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders video media as an inline player", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { act, cleanup, render, screen } from "@testing-library/react";
|
||||
import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
|
||||
@@ -6,8 +6,8 @@ import i18n from "@/i18n";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
function renderAutomations(channel: string) {
|
||||
return render(
|
||||
function renderAutomationDetail(channel: string) {
|
||||
render(
|
||||
<AutomationsSettings
|
||||
payload={{ jobs: [{
|
||||
id: "task-1",
|
||||
@@ -30,15 +30,16 @@ function renderAutomations(channel: string) {
|
||||
onAction={vi.fn()}
|
||||
onRequestEdit={vi.fn()}
|
||||
onRequestDelete={vi.fn()}
|
||||
onBackToChat={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Scheduled task/ }));
|
||||
return within(screen.getByRole("dialog", { name: "Scheduled task" }));
|
||||
}
|
||||
|
||||
describe("automation channel identity", () => {
|
||||
it("uses channel-owned names in the list and details when the language changes", async () => {
|
||||
renderAutomations("email");
|
||||
expect(screen.getAllByText("Email")).toHaveLength(2);
|
||||
it("uses channel-owned names in the detail when the language changes", async () => {
|
||||
const detail = renderAutomationDetail("email");
|
||||
expect(detail.getByText("Email")).toBeVisible();
|
||||
|
||||
for (const [locale, name] of [
|
||||
["zh-CN", "电子邮件"],
|
||||
@@ -46,15 +47,15 @@ describe("automation channel identity", () => {
|
||||
["es", "Correo electrónico"],
|
||||
]) {
|
||||
await act(() => i18n.changeLanguage(locale));
|
||||
expect(screen.getAllByText(name)).toHaveLength(2);
|
||||
expect(screen.queryByText("Email")).not.toBeInTheDocument();
|
||||
expect(detail.getByText(name)).toBeVisible();
|
||||
expect(detail.queryByText("Email")).not.toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves aliases through the owning channel namespace", async () => {
|
||||
await i18n.changeLanguage("zh-CN");
|
||||
renderAutomations("wechat");
|
||||
expect(screen.getAllByText("微信")).toHaveLength(2);
|
||||
const detail = renderAutomationDetail("wechat");
|
||||
expect(detail.getByText("微信")).toBeVisible();
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -62,7 +63,7 @@ describe("automation channel identity", () => {
|
||||
["cli", "CLI"],
|
||||
["extension-chat", "extension-chat"],
|
||||
])("preserves the label for %s", (channel, label) => {
|
||||
renderAutomations(channel);
|
||||
expect(screen.getAllByText(label)).toHaveLength(2);
|
||||
const detail = renderAutomationDetail(channel);
|
||||
expect(detail.getByText(label)).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -180,7 +180,10 @@ describe("Settings system domains", () => {
|
||||
|
||||
expect(screen.getByRole("heading", { name: "Automations" })).toBeInTheDocument();
|
||||
expect(await screen.findByText("No automations yet.")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Open a chat" }));
|
||||
expect(screen.getByText("Tell nanobot in a chat what you'd like it to do on a schedule.")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Create in chat" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back to chat" }));
|
||||
expect(onBackToChat).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -209,11 +212,50 @@ describe("Settings system domains", () => {
|
||||
showSidebar: false,
|
||||
});
|
||||
|
||||
expect(await screen.findByRole("heading", { name: "Daily summary" })).toBeInTheDocument();
|
||||
expect(await screen.findByRole("button", { name: /Daily summary/ })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Search and filter" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Paused 0" }));
|
||||
expect(await screen.findByText("No automations match this view.")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Clear filters" }));
|
||||
expect(await screen.findByRole("heading", { name: "Daily summary" })).toBeInTheDocument();
|
||||
expect(await screen.findByRole("button", { name: /Daily summary/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("wraps automation filters and keeps every option selectable", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
if (String(input) === "/api/settings") return jsonResponse(settingsPayload());
|
||||
if (String(input) === "/api/webui/automations") {
|
||||
return jsonResponse({ jobs: [
|
||||
{
|
||||
id: "heartbeat", name: "heartbeat", enabled: true, protected: true,
|
||||
schedule: { kind: "every", every_ms: 1_800_000 },
|
||||
payload: { message: "System-managed automation" }, state: {},
|
||||
},
|
||||
{
|
||||
id: "paused-job", name: "Paused reminder", enabled: false,
|
||||
schedule: { kind: "every", every_ms: 86_400_000 },
|
||||
payload: { message: "Check the repo" }, state: {},
|
||||
},
|
||||
] });
|
||||
}
|
||||
return jsonResponse({});
|
||||
}));
|
||||
renderSettingsView({ initialSection: "automations", initialSettings: settingsPayload(), showSidebar: false });
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Search and filter" }));
|
||||
const filters = screen.getByRole("group", { name: "Automations" });
|
||||
expect(filters).toHaveClass("flex-wrap");
|
||||
expect(within(filters).getAllByRole("button")).toHaveLength(4);
|
||||
expect(within(filters).getByRole("button", { name: "All 1" })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(within(filters).queryByRole("button", { name: /System/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "true");
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
|
||||
fireEvent.click(within(filters).getByRole("button", { name: "Paused 1" }));
|
||||
expect(within(filters).getByRole("button", { name: "Paused 1" })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(screen.getByRole("button", { name: /Paused reminder/ })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
expect(within(filters).getAllByRole("button", { pressed: true })).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("coalesces focus refreshes while automations are already loading", async () => {
|
||||
|
||||
@@ -1312,6 +1312,9 @@ describe("ThreadComposer", () => {
|
||||
const { container, rerender } = render(composer(false));
|
||||
const drawer = container.querySelector("[data-composer-workspace-drawer]");
|
||||
|
||||
expect(drawer).toHaveClass("inline-disclosure");
|
||||
expect(drawer?.firstElementChild).toHaveClass("inline-disclosure-clip");
|
||||
expect(drawer?.firstElementChild?.firstElementChild).toHaveClass("inline-disclosure-content");
|
||||
expect(drawer).toHaveAttribute("data-state", "open");
|
||||
expect(drawer).not.toHaveAttribute("aria-hidden");
|
||||
expect(container.querySelector("[data-composer-workspace-compact]")).not.toBeInTheDocument();
|
||||
|
||||
Reference in new issue
Block a user