feat(webui): refine automation views and scheduling controls
This commit is contained in:
1 parent
c25b2048ef
commit
e7da868574
23 files changed
+1131
-601
No files matched your search
@@ -0,0 +1,133 @@
|
||||
import { useState } from "react";
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AutomationRunAtPicker, parseAutomationRunAt } from "@/components/settings/system/AutomationRunAtPicker";
|
||||
import { AutomationEditDialog } from "@/components/settings/system/AutomationsSettings";
|
||||
import i18n from "@/i18n";
|
||||
import type { SessionAutomationJob } from "@/lib/types";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
function Harness({ initial = "2032-09-12T09:37" }: { initial?: string }) {
|
||||
const [value, setValue] = useState(initial);
|
||||
return <AutomationRunAtPicker value={value} onChange={setValue} />;
|
||||
}
|
||||
|
||||
function dayName(value: string) {
|
||||
return new Intl.DateTimeFormat("en", { dateStyle: "full" }).format(parseAutomationRunAt(`${value}T12:00`)!);
|
||||
}
|
||||
|
||||
describe("Automation run time picker", () => {
|
||||
it("uses text fields and a themed calendar without native date or time controls", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
expect(screen.getByRole("textbox", { name: "Run date" })).toHaveValue("2032-09-12");
|
||||
expect(screen.getByRole("textbox", { name: "Run time" })).toHaveValue("09:37");
|
||||
expect(document.querySelector('input[type="datetime-local"], input[type="date"], input[type="time"]')).toBeNull();
|
||||
const trigger = screen.getByRole("button", { name: "Choose date" });
|
||||
await user.click(trigger);
|
||||
const calendar = screen.getByRole("dialog", { name: "Choose date" });
|
||||
expect(within(calendar).getByRole("grid", { name: "September 2032" })).toBeVisible();
|
||||
expect(within(calendar).getByRole("button", { name: dayName("2032-09-12") })).toHaveFocus();
|
||||
await user.click(within(calendar).getByRole("button", { name: dayName("2032-09-17") }));
|
||||
expect(screen.getByRole("textbox", { name: "Run date" })).toHaveValue("2032-09-17");
|
||||
expect(screen.getByRole("textbox", { name: "Run time" })).toHaveValue("09:37");
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("moves focus across month boundaries and clamps PageDown to a leap month's last day", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness initial="2032-01-31T09:37" />);
|
||||
await user.click(screen.getByRole("button", { name: "Choose date" }));
|
||||
await user.keyboard("{PageDown}");
|
||||
expect(screen.getByRole("button", { name: dayName("2032-02-29") })).toHaveFocus();
|
||||
await user.keyboard("{ArrowRight}");
|
||||
expect(screen.getByRole("button", { name: dayName("2032-03-01") })).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("textbox", { name: "Run date" })).toHaveValue("2032-03-01");
|
||||
expect(screen.getByRole("textbox", { name: "Run time" })).toHaveValue("09:37");
|
||||
});
|
||||
|
||||
it("supports week navigation and Escape without selecting a different date", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness initial="2032-03-03T09:37" />);
|
||||
const trigger = screen.getByRole("button", { name: "Choose date" });
|
||||
await user.click(trigger);
|
||||
await user.keyboard("{Home}");
|
||||
expect(screen.getByRole("button", { name: dayName("2032-03-01") })).toHaveFocus();
|
||||
await user.keyboard("{End}{ArrowDown}");
|
||||
expect(screen.getByRole("button", { name: dayName("2032-03-14") })).toHaveFocus();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
expect(screen.getByRole("textbox", { name: "Run date" })).toHaveValue("2032-03-03");
|
||||
});
|
||||
|
||||
it("preserves exact minutes when typing and opens the calendar at the typed month", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const date = screen.getByRole("textbox", { name: "Run date" });
|
||||
const time = screen.getByRole("textbox", { name: "Run time" });
|
||||
await user.clear(date);
|
||||
await user.type(date, "2033-01-02");
|
||||
await user.clear(time);
|
||||
await user.type(time, "23:59");
|
||||
await user.click(screen.getByRole("button", { name: "Choose date" }));
|
||||
expect(screen.getByRole("grid", { name: "January 2033" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: dayName("2033-01-02") })).toHaveFocus();
|
||||
expect(time).toHaveValue("23:59");
|
||||
});
|
||||
|
||||
it("keeps the editor open when dismissing its calendar and saves a local timestamp", async () => {
|
||||
const user = userEvent.setup();
|
||||
const save = vi.fn();
|
||||
const onOpenChange = vi.fn();
|
||||
const job: SessionAutomationJob = {
|
||||
id: "once", name: "One-time report", enabled: true,
|
||||
schedule: { kind: "at", at_ms: new Date(2099, 8, 12, 9, 37).getTime() },
|
||||
payload: { message: "Summarize project updates" }, state: {},
|
||||
};
|
||||
render(<AutomationEditDialog job={job} saving={false} onSave={save} onOpenChange={onOpenChange} />);
|
||||
await user.click(screen.getByRole("button", { name: "Choose date" }));
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.getByRole("dialog", { name: "Edit automation" })).toBeVisible();
|
||||
expect(onOpenChange).not.toHaveBeenCalled();
|
||||
await user.click(screen.getByRole("button", { name: "Choose date" }));
|
||||
await user.click(screen.getByRole("button", { name: dayName("2099-09-17") }));
|
||||
const time = screen.getByRole("textbox", { name: "Run time" });
|
||||
await user.clear(time);
|
||||
await user.type(time, "09:45");
|
||||
await user.click(screen.getByRole("button", { name: "Save", exact: true }));
|
||||
expect(save).toHaveBeenCalledWith(job, {
|
||||
name: job.name, message: job.payload.message,
|
||||
schedule: { kind: "at", at_ms: new Date(2099, 8, 17, 9, 45).getTime() },
|
||||
});
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Run date" }), { target: { value: "2099-02-31" } });
|
||||
expect(screen.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
|
||||
expect(screen.getByText("Choose a run time.")).toBeVisible();
|
||||
});
|
||||
|
||||
it("localizes the calendar and its field labels in Chinese", async () => {
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
expect(screen.getByRole("textbox", { name: "运行日期" })).toBeVisible();
|
||||
expect(screen.getByRole("textbox", { name: "运行时刻" })).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "选择日期" }));
|
||||
expect(screen.getByRole("grid", { name: "2032年9月" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "下个月" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Automation local date validation", () => {
|
||||
it.each(["", "2032-02-30T12:00", "2031-02-29T12:00", "2032-13-01T12:00", "2032-00-01T12:00",
|
||||
"2032-01-00T12:00", "2032-01-01T24:00", "2032-01-01T12:60", "2032-01-01T9:00", "2032-01-01T", "0000-01-01T12:00"])(
|
||||
"rejects an invalid local date or time: %s", (value) => expect(parseAutomationRunAt(value)).toBeNull(),
|
||||
);
|
||||
|
||||
it("accepts leap days, midnight, and years below 100 without changing the local fields", () => {
|
||||
expect(parseAutomationRunAt("2032-02-29T00:00")?.getTime()).toBe(new Date(2032, 1, 29, 0, 0).getTime());
|
||||
expect(parseAutomationRunAt("0099-01-01T00:00")?.getFullYear()).toBe(99);
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testi
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from "vitest";
|
||||
|
||||
import { AutomationDeleteDialog, AutomationEditDialog, AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
|
||||
import { AutomationDeleteDialog, AutomationDetailDialog, AutomationEditDialog, AutomationsSettings } from "@/components/settings/system/AutomationsSettings";
|
||||
import type { AutomationFilter } from "@/components/settings/system/AutomationsSettings";
|
||||
import i18n from "@/i18n";
|
||||
import type { SessionAutomationJob, SettingsPayload } from "@/lib/types";
|
||||
@@ -36,7 +36,8 @@ const modelSettings = {
|
||||
providers: [{ name: "openai", label: "OpenAI", configured: true }],
|
||||
} as SettingsPayload;
|
||||
type Props = Partial<React.ComponentProps<typeof AutomationsSettings>>;
|
||||
const SYSTEM_TASKS_OPEN_STORAGE_KEY = "nanobot-webui.automation-system-tasks-open";
|
||||
const SYSTEM_TASKS_OPEN_STORAGE_KEY = "nanobot-webui.automation-show-system-tasks";
|
||||
const VIEW_STORAGE_KEY = "nanobot-webui.automation-view";
|
||||
|
||||
function Harness({ payload = { jobs: [task, systemTask] }, ...props }: Props) {
|
||||
const [filter, setFilter] = useState<AutomationFilter>("all");
|
||||
@@ -48,8 +49,24 @@ function Harness({ payload = { jobs: [task, systemTask] }, ...props }: Props) {
|
||||
/>;
|
||||
}
|
||||
|
||||
function openFilters() {
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: /^Filter/ }), { button: 0, ctrlKey: false });
|
||||
return screen.getByRole("menu", { name: /^Filter/ });
|
||||
}
|
||||
|
||||
function selectFilter(name: string) {
|
||||
const menu = openFilters();
|
||||
fireEvent.click(within(menu).getByRole("menuitemradio", { name }));
|
||||
}
|
||||
|
||||
function renderDetail(job: SessionAutomationJob) {
|
||||
return render(<AutomationDetailDialog job={job} open locale="en" actionKey={null} error={null}
|
||||
onOpenChange={() => {}} onAction={() => {}} onRequestEdit={() => {}} onRequestDelete={() => {}} />);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
window.localStorage.removeItem(SYSTEM_TASKS_OPEN_STORAGE_KEY);
|
||||
window.localStorage.removeItem(VIEW_STORAGE_KEY);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -57,49 +74,130 @@ afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
window.localStorage.removeItem(SYSTEM_TASKS_OPEN_STORAGE_KEY);
|
||||
window.localStorage.removeItem(VIEW_STORAGE_KEY);
|
||||
});
|
||||
|
||||
describe("Automation task list and detail sheet", () => {
|
||||
it("avoids redundant headings and decorative uppercase group labels", () => {
|
||||
it("keeps view selection and filters in one persistent panel toolbar", () => {
|
||||
render(<Harness />);
|
||||
expect(screen.queryByRole("heading", { name: "Your automations" })).not.toBeInTheDocument();
|
||||
const month = new Intl.DateTimeFormat("en", { month: "long", year: "numeric" }).format(new Date());
|
||||
expect(screen.getByLabelText(month)).toBeVisible();
|
||||
const systemToggle = screen.getByRole("button", { name: "System tasks 1" });
|
||||
expect(systemToggle).toHaveClass("text-[13px]", "font-medium");
|
||||
expect(systemToggle).not.toHaveClass("uppercase", "tracking-[0.08em]");
|
||||
const views = screen.getByRole("group", { name: "Automation view" });
|
||||
const filters = screen.getByRole("button", { name: /^Filter/ });
|
||||
const toolbar = views.closest(".automation-panel-toolbar");
|
||||
expect(toolbar).not.toBeNull();
|
||||
expect(filters.closest(".automation-panel-toolbar")).toBe(toolbar);
|
||||
expect(toolbar?.closest(".automation-panel")).toContainElement(document.querySelector(".automation-calendar"));
|
||||
const tasksButton = screen.getByRole("button", { name: "Tasks", exact: true });
|
||||
tasksButton.focus();
|
||||
fireEvent.click(tasksButton);
|
||||
expect(screen.getByRole("button", { name: "Tasks", exact: true })).toBe(tasksButton);
|
||||
expect(tasksButton).toHaveFocus();
|
||||
expect(screen.getByRole("button", { name: /^Filter/ }).closest(".automation-panel-toolbar")).toBe(toolbar);
|
||||
expect(screen.queryByRole("heading", { level: 2 })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
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 triggerTask: SessionAutomationJob = {
|
||||
...task, id: "trigger-review", name: "Review on request", kind: "local_trigger",
|
||||
schedule: { kind: "local" }, state: {},
|
||||
payload: { kind: "local_trigger", message: "nanobot trigger trg_review \"message\"" },
|
||||
trigger: { id: "trg_review", command: "nanobot trigger trg_review \"message\"" },
|
||||
};
|
||||
|
||||
const second = render(<Harness />);
|
||||
expect(screen.getByRole("button", { name: "System tasks 1" })).toHaveAttribute("aria-expanded", "false");
|
||||
it("keeps undated triggers in Tasks and opens their shared details with keyboard focus restored", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [triggerTask, task] }} />);
|
||||
expect(screen.queryByRole("button", { name: /Review on request/ })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
const row = screen.getByRole("button", { name: /Review on request/ });
|
||||
expect(within(row).getByText("Triggered by command")).toBeVisible();
|
||||
expect(within(row).queryByText("Waiting for trigger")).not.toBeInTheDocument();
|
||||
expect(within(row).queryByText(/nanobot trigger/)).not.toBeInTheDocument();
|
||||
await user.click(row);
|
||||
const dialog = screen.getByRole("dialog", { name: "Review on request" });
|
||||
expect(within(dialog).getByText(triggerTask.trigger!.command)).toBeVisible();
|
||||
expect(within(dialog).getByRole("button", { name: "Copy", exact: true })).toBeVisible();
|
||||
expect(within(dialog).queryByText("Next")).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole("button", { name: "Run now" })).not.toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(row).toHaveFocus());
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "Review on request" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("puts trigger execution history on the calendar without a future placeholder", () => {
|
||||
render(<Harness payload={{ jobs: [{ ...triggerTask, state: {
|
||||
run_history: [{ run_at_ms: now, duration_ms: 60_000, status: "ok" }],
|
||||
} }] }} />);
|
||||
expect(screen.getByRole("button", { name: /Review on request.*Recorded/ })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: /Review on request.*Planned/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("defaults to Calendar on every visit regardless of the old saved view and shares filters", () => {
|
||||
window.localStorage.setItem(VIEW_STORAGE_KEY, "tasks");
|
||||
const first = render(<Harness payload={{ jobs: [triggerTask, task, systemTask] }} />);
|
||||
expect(screen.getByRole("button", { name: "Calendar", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
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");
|
||||
first.unmount();
|
||||
render(<Harness payload={{ jobs: [triggerTask, task, systemTask] }} />);
|
||||
expect(screen.getByRole("button", { name: "Calendar", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Tasks", exact: true })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(screen.getByRole("button", { name: /Review on request/ })).toBeVisible();
|
||||
selectFilter("Disabled 0");
|
||||
expect(screen.getByText("No automations match this view.")).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar", exact: true }));
|
||||
expect(screen.getByRole("button", { name: "Filter: Disabled" })).toBeVisible();
|
||||
expect(screen.queryByRole("switch", { name: "Show system tasks" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the system toggle usable when browser storage is unavailable", () => {
|
||||
it("highlights disabled, running and failed tasks without badges for healthy tasks", () => {
|
||||
render(<Harness payload={{ jobs: [triggerTask,
|
||||
{ ...task, id: "off", name: "Disabled task", enabled: false },
|
||||
{ ...task, id: "busy", name: "Running task", state: { pending: true } },
|
||||
{ ...task, id: "error", name: "Failed task", state: { last_status: "error" } },
|
||||
] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(within(screen.getByRole("button", { name: /Review on request/ })).queryByText("Active")).not.toBeInTheDocument();
|
||||
expect(within(screen.getByRole("button", { name: /Disabled task/ })).getByText("Disabled")).toBeVisible();
|
||||
expect(within(screen.getByRole("button", { name: /Running task/ })).getByText("Running now")).toBeVisible();
|
||||
expect(within(screen.getByRole("button", { name: /Failed task/ })).getByText("Failed")).toBeVisible();
|
||||
});
|
||||
|
||||
it("switches views even when browser storage is blocked", () => {
|
||||
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");
|
||||
render(<Harness payload={{ jobs: [triggerTask] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(screen.getByRole("button", { name: /Review on request/ })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Calendar", exact: true }));
|
||||
expect(screen.queryByRole("button", { name: /Review on request/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("excludes system tasks and their failures from both views even with the old preference enabled", () => {
|
||||
window.localStorage.setItem(SYSTEM_TASKS_OPEN_STORAGE_KEY, "true");
|
||||
const action = vi.fn();
|
||||
render(<Harness payload={{ jobs: [task, { ...systemTask, state: {
|
||||
...systemTask.state, last_status: "error",
|
||||
} }] }} onAction={action} />);
|
||||
for (const view of ["Calendar", "Tasks"]) {
|
||||
fireEvent.click(screen.getByRole("button", { name: view, exact: true }));
|
||||
expect(screen.queryByRole("switch", { name: "Show system tasks" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
|
||||
const menu = openFilters();
|
||||
expect(within(menu).getByRole("menuitemradio", { name: "All 1" })).toBeVisible();
|
||||
expect(within(menu).getByRole("menuitemradio", { name: "Needs attention 0" })).toBeVisible();
|
||||
fireEvent.keyDown(menu, { key: "Escape" });
|
||||
}
|
||||
expect(action).not.toHaveBeenCalled();
|
||||
expect(systemTask.enabled).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
it.each(["Close", "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.
|
||||
@@ -147,10 +245,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("group", { name: "Automations" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: /^Filter/ })).toBeVisible();
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /^Active/ })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: /heartbeat/ })).toBeVisible();
|
||||
expect(screen.queryByRole("menuitemradio")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Create in chat" })).not.toBeInTheDocument();
|
||||
const row = screen.getByRole("button", { name: /PR watch/ });
|
||||
await user.click(row);
|
||||
@@ -186,6 +284,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
const recorded = screen.getByRole("button", { name: /PR watch.*Recorded/ });
|
||||
expect(planned).toHaveAttribute("aria-haspopup", "dialog");
|
||||
expect(recorded).toHaveAttribute("aria-haspopup", "dialog");
|
||||
expect(planned.querySelector(".rounded-full")).toBeNull();
|
||||
expect(recorded.querySelector(".rounded-full")).toBeNull();
|
||||
expect(planned).not.toHaveClass("bg-muted/45");
|
||||
expect(recorded).toHaveClass("bg-muted/45", "rounded-compact");
|
||||
expect(screen.queryByRole("link", { name: /PR watch/ })).not.toBeInTheDocument();
|
||||
|
||||
await user.click(recorded);
|
||||
@@ -227,14 +329,28 @@ describe("Automation task list and detail sheet", () => {
|
||||
await waitFor(() => expect(more).toHaveFocus());
|
||||
});
|
||||
|
||||
it("keeps the calendar and filters available when a status has no matches", async () => {
|
||||
const user = userEvent.setup();
|
||||
it("keeps explicit running and error icons after removing calendar status dots", () => {
|
||||
const failedJob = {
|
||||
...task, id: "failed-job", name: "Failed check", enabled: false,
|
||||
state: { run_history: [{ run_at_ms: now - 60_000, status: "error", duration_ms: 1_000 }] },
|
||||
};
|
||||
const runningJob = { ...task, state: { ...task.state, pending: true } };
|
||||
render(<Harness payload={{ jobs: [runningJob, failedJob] }} />);
|
||||
const running = screen.getByRole("button", { name: /PR watch.*Running/ });
|
||||
const failed = screen.getByRole("button", { name: /Failed check.*Failed/ });
|
||||
expect(running.querySelector(".lucide-loader-circle")).not.toBeNull();
|
||||
expect(failed.querySelector(".lucide-circle-alert")).not.toBeNull();
|
||||
expect(running.querySelector(".rounded-full")).toBeNull();
|
||||
expect(failed.querySelector(".rounded-full")).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps the calendar and filters available when a status has no matches", () => {
|
||||
render(<Harness payload={{ jobs: [task] }} />);
|
||||
const month = screen.getByRole("heading", { level: 2 });
|
||||
await user.click(screen.getByRole("button", { name: "Paused 0" }));
|
||||
selectFilter("Disabled 0");
|
||||
expect(month).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: /PR watch.*Planned/ })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "All 1" }));
|
||||
selectFilter("All 1");
|
||||
expect(screen.getByRole("button", { name: /PR watch.*Planned/ })).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -321,7 +437,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
render(<Harness payload={{ jobs: [] }} onStartChat={() => {}} settingsSnapshot={modelSettings} />);
|
||||
expect(screen.getByRole("textbox", { name: "Describe an automation" })).toHaveAttribute(
|
||||
"placeholder",
|
||||
"What would you like nanobot to schedule?",
|
||||
"What would you like nanobot to automate?",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -329,7 +445,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
render(<Harness payload={{ jobs: [] }} onStartChat={() => {}} settingsSnapshot={modelSettings} />);
|
||||
expect(screen.getByRole("textbox", { name: "描述一个自动任务" })).toHaveAttribute(
|
||||
"placeholder", "想让 nanobot 定时帮你做什么?",
|
||||
"placeholder", "想让 nanobot 自动帮你做什么?",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -342,13 +458,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(calendar.querySelectorAll(".automation-calendar-day").length).toBeGreaterThanOrEqual(35);
|
||||
expect(screen.queryByRole("button", { name: "Create in chat" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("group", { name: "Automations" })).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();
|
||||
expect(screen.queryByRole("button", { name: /^Filter/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /heartbeat/ })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Tasks", exact: true }));
|
||||
expect(screen.getByText("No automations yet.")).toBeVisible();
|
||||
});
|
||||
|
||||
it("distinguishes a finished one-time task from a task with no scheduled run", () => {
|
||||
@@ -359,10 +472,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
});
|
||||
|
||||
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) }));
|
||||
renderDetail({ ...systemTask, id, name: id, state: { next_run_at_ms: now + 540_000 } });
|
||||
const dialog = screen.getByRole("dialog", { name: id });
|
||||
expect(dialog).toHaveClass("max-w-[440px]");
|
||||
expect(dialog).not.toHaveAttribute("aria-describedby");
|
||||
@@ -389,11 +499,10 @@ describe("Automation task list and detail sheet", () => {
|
||||
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/ }));
|
||||
it("keeps the shared protected detail read-only and does not infer purpose from a task name", () => {
|
||||
renderDetail({ ...systemTask, id: "other-system-job", name: "heartbeat",
|
||||
state: { last_run_at_ms: now - 60_000, last_status: "error", last_error: "Background check failed", next_run_at_ms: null },
|
||||
});
|
||||
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");
|
||||
@@ -403,8 +512,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
});
|
||||
|
||||
it.each([task, systemTask])("uses shared dialog styling and quiet detail rows for $name", (job) => {
|
||||
render(<Harness payload={{ jobs: [job] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: new RegExp(job.name) }));
|
||||
renderDetail(job);
|
||||
const dialog = screen.getByRole("dialog", { name: job.name });
|
||||
expect(dialog).toHaveClass("rounded-modal");
|
||||
expect(dialog).not.toHaveClass("rounded-[20px]");
|
||||
@@ -420,7 +528,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(details.parentElement).not.toHaveClass("border-t");
|
||||
expect(details).toHaveAttribute("aria-expanded", "false");
|
||||
if (!job.protected) {
|
||||
const taskActions = within(dialog).getByRole("button", { name: "Pause" }).parentElement;
|
||||
const taskActions = within(dialog).getByRole("button", { name: "Disable" }).parentElement;
|
||||
expect(within(dialog).getByRole("button", { name: "Run now" }).parentElement).toBe(taskActions);
|
||||
expect(within(dialog).getByRole("button", { name: "Delete" }).parentElement).toBe(taskActions);
|
||||
const edit = within(dialog).getByRole("button", { name: "Edit" });
|
||||
@@ -447,33 +555,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(within(dialog).getByText("Asia/Shanghai")).toBeVisible();
|
||||
});
|
||||
|
||||
it("uses the existing settings surfaces for the calendar and system task group", 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" },
|
||||
}] }} />);
|
||||
expect(screen.getByRole("heading", { name: "Automations" })).toHaveClass("font-normal", "text-[24px]");
|
||||
const taskBlock = screen.getByRole("button", { name: /PR watch.*Planned/ });
|
||||
expect(taskBlock).toHaveAttribute("aria-haspopup", "dialog");
|
||||
expect(screen.queryByRole("button", { name: "Manage PR watch" })).not.toBeInTheDocument();
|
||||
const list = screen.getByRole("list", { name: "System tasks" });
|
||||
expect(taskBlock.closest("section")).toHaveClass("rounded-panel", "bg-[hsl(var(--settings-surface))]");
|
||||
expect(list.closest(".bg-settings-surface")).not.toBe(taskBlock.closest("section"));
|
||||
const filters = screen.getByRole("group", { name: "Automations" });
|
||||
expect(filters.closest(".automation-calendar-header")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "All 1" }).parentElement).toHaveClass("segmented-control", "flex-wrap");
|
||||
const heartbeat = within(list).getByRole("button", { name: /heartbeat/ });
|
||||
expect(heartbeat).toHaveClass("rounded-control", "settings-hover");
|
||||
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 separators inside the date grid and omits an outside-month task list", () => {
|
||||
const outsideTask: SessionAutomationJob = {
|
||||
@@ -491,7 +573,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(header).toHaveClass("bg-foreground/[0.025]");
|
||||
expect(header).not.toHaveClass("border-b");
|
||||
expect(header?.querySelector(".automation-calendar-weekdays")).toBeInTheDocument();
|
||||
expect(calendar.querySelector(".automation-meta-row")).not.toHaveClass("border-t");
|
||||
expect(calendar.querySelector(".automation-meta-row")).toBeNull();
|
||||
expect(calendar.querySelector(":scope > details")).toBeNull();
|
||||
expect(screen.queryByRole("button", { name: /Paused backlog review/ })).not.toBeInTheDocument();
|
||||
expect(calendar).not.toHaveTextContent("·");
|
||||
@@ -510,50 +592,58 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(dialog).not.toHaveTextContent("·");
|
||||
});
|
||||
|
||||
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.each([
|
||||
["30 13 25 * *", "Monthly on day 25 at 13:30"],
|
||||
["0 0 1 * *", "Monthly on day 1 at 00:00"],
|
||||
["30 8 * * 1", "Every Monday at 08:30"],
|
||||
["0 19 * * 0", "Every Sunday at 19:00"],
|
||||
["0 19 * * 7", "Every Sunday at 19:00"],
|
||||
["0 10 * * SAT", "Every Saturday at 10:00"],
|
||||
["0 10 * * 8", "Custom schedule"],
|
||||
["30 13 25 * 1", "Custom schedule"],
|
||||
["*/15 9-17 * * 1,3,5", "Custom schedule"],
|
||||
["0 9 0 * *", "Custom schedule"],
|
||||
])("keeps %s out of read-only details", (expr, summary) => {
|
||||
render(<Harness payload={{ jobs: [{ ...task, schedule: { kind: "cron", expr } }] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
expect(within(dialog).getByText(summary)).toBeVisible();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "More details" }));
|
||||
expect(dialog).not.toHaveTextContent(expr);
|
||||
expect(dialog).not.toHaveTextContent("Linked chat");
|
||||
});
|
||||
|
||||
it("keeps status filters immediately available", async () => {
|
||||
it("localizes the monthly summary and retains the expression in the editor", async () => {
|
||||
const language = i18n.language;
|
||||
onTestFinished(() => i18n.changeLanguage(language));
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
const job: SessionAutomationJob = { ...task, schedule: { kind: "cron", expr: "30 13 25 * *" } };
|
||||
const { unmount } = render(<Harness payload={{ jobs: [job] }} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
expect(screen.getByText("每月 25 日 13:30")).toBeVisible();
|
||||
unmount();
|
||||
render(<AutomationEditDialog job={job} saving={false} onOpenChange={() => {}} onSave={vi.fn()} />);
|
||||
expect(screen.getByDisplayValue("30 13 25 * *")).toBeVisible();
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("opens an icon-only filter with the keyboard and restores focus on Escape", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const filterButton = screen.getByRole("button", { name: "Filter", exact: true });
|
||||
expect(filterButton).toHaveTextContent("");
|
||||
expect(filterButton.querySelector(".lucide-list-filter")).not.toBeNull();
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
filterButton.focus();
|
||||
fireEvent.keyDown(filterButton, { key: "Enter" });
|
||||
expect(screen.getByRole("menuitemradio", { name: "All 1" })).toHaveAttribute("aria-checked", "true");
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(filterButton).toHaveFocus();
|
||||
});
|
||||
|
||||
it("reveals status filters on demand and shows the applied condition", () => {
|
||||
render(<Harness payload={{ jobs: [task, {
|
||||
...task,
|
||||
id: "paused",
|
||||
@@ -562,16 +652,16 @@ describe("Automation task list and detail sheet", () => {
|
||||
state: { last_run_at_ms: now - 60_000, last_status: "ok" },
|
||||
}, systemTask] }} />);
|
||||
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Paused 1" }));
|
||||
selectFilter("Disabled 1");
|
||||
expect(screen.queryByRole("button", { name: /PR watch/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /Weekly review/ })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Paused 1" })).toHaveAttribute("aria-pressed", "true");
|
||||
await user.click(screen.getByRole("button", { name: "All 2" }));
|
||||
expect(screen.getByRole("button", { name: "Filter: Disabled" })).toBeVisible();
|
||||
selectFilter("All 2");
|
||||
expect(screen.queryByRole("button", { name: "Next run", exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /PR watch.*Planned/ })).toBeVisible();
|
||||
});
|
||||
|
||||
it("uses live renamed chat titles in details without changing the bound task", async () => {
|
||||
it("omits redundant chat metadata while preserving the bound task and chat action", async () => {
|
||||
const user = userEvent.setup();
|
||||
const action = vi.fn();
|
||||
const payload = { jobs: [task] };
|
||||
@@ -580,15 +670,13 @@ describe("Automation task list and detail sheet", () => {
|
||||
titleOverrides={{ "websocket:demo": longTitle }} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
const chatLabel = within(dialog).getByText(longTitle);
|
||||
expect(chatLabel.closest("a")).toBeNull();
|
||||
expect(chatLabel).toHaveClass("truncate");
|
||||
expect(chatLabel).toHaveAttribute("title", longTitle);
|
||||
expect(within(dialog).queryByText(longTitle)).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByText("Linked chat")).not.toBeInTheDocument();
|
||||
expect(dialog.querySelector(".lucide-chevron-right")).toBeNull();
|
||||
rerender(<Harness payload={payload} onAction={action}
|
||||
titleOverrides={{ "websocket:demo": "新会话名称" }} />);
|
||||
expect(within(dialog).getByText("新会话名称")).toBe(chatLabel);
|
||||
await user.click(within(dialog).getByRole("button", { name: "Pause" }));
|
||||
expect(within(dialog).queryByText("新会话名称")).not.toBeInTheDocument();
|
||||
await user.click(within(dialog).getByRole("button", { name: "Disable" }));
|
||||
expect(action).toHaveBeenCalledWith("disable", expect.objectContaining({
|
||||
id: task.id, payload: task.payload,
|
||||
origin: expect.objectContaining({ session_key: "websocket:demo" }),
|
||||
@@ -597,7 +685,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
await user.click(within(dialog).getByRole("button", { name: "Close" }));
|
||||
rerender(<Harness payload={payload} titleOverrides={{}} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
expect(screen.getByText("nanobot-development").closest("a")).toBeNull();
|
||||
expect(screen.queryByText("nanobot-development")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Open a chat" })).toHaveAttribute("href", "#/chat/websocket%3Ademo");
|
||||
});
|
||||
|
||||
@@ -605,16 +693,37 @@ describe("Automation task list and detail sheet", () => {
|
||||
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" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Disable" }));
|
||||
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" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Enable" }));
|
||||
expect(action).toHaveBeenLastCalledWith("enable", { ...task, enabled: false });
|
||||
rerender(<Harness payload={{ jobs: [] }} />);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("uses enable and disable terminology throughout the Chinese automation flow", async () => {
|
||||
const language = i18n.language;
|
||||
onTestFinished(() => i18n.changeLanguage(language));
|
||||
await act(() => i18n.changeLanguage("zh-CN"));
|
||||
const action = vi.fn();
|
||||
const { rerender } = render(<Harness payload={{ jobs: [task] }} onAction={action} />);
|
||||
expect(screen.getByRole("button", { name: "筛选", exact: true })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
const dialog = screen.getByRole("dialog", { name: "PR watch" });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "停用", exact: true }));
|
||||
expect(action).toHaveBeenLastCalledWith("disable", task);
|
||||
const disabledTask = { ...task, enabled: false };
|
||||
rerender(<Harness payload={{ jobs: [disabledTask] }} onAction={action} />);
|
||||
expect(within(dialog).getByText("已停用")).toBeVisible();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "启用", exact: true }));
|
||||
expect(action).toHaveBeenLastCalledWith("enable", disabledTask);
|
||||
expect(dialog).not.toHaveTextContent("暂停");
|
||||
expect(dialog).not.toHaveTextContent("恢复");
|
||||
expect(i18n.t("settings.automations.status.paused")).toBe("已停用");
|
||||
});
|
||||
|
||||
it("returns focus to the page heading when the inspected row is no longer present", async () => {
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<Harness filter="active" />);
|
||||
@@ -636,14 +745,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
it("uses chevrons only for disclosures, while task rows open dialogs", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
const toggle = screen.getByRole("button", { name: "System tasks 1" });
|
||||
const chevron = toggle.querySelector("svg");
|
||||
expect(chevron).toHaveClass("lucide-chevron-down", "rotate-180");
|
||||
await user.click(toggle);
|
||||
expect(chevron).not.toHaveClass("rotate-180");
|
||||
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
await user.click(toggle);
|
||||
for (const name of [/PR watch/, /heartbeat/]) {
|
||||
for (const name of [/PR watch/]) {
|
||||
const row = screen.getByRole("button", { name });
|
||||
expect(row).toHaveAttribute("aria-haspopup", "dialog");
|
||||
expect(row.querySelector(".lucide-chevron-right, .lucide-chevron-down")).toBeNull();
|
||||
@@ -790,7 +892,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Run now" }));
|
||||
expect(action).toHaveBeenCalledWith("run", task);
|
||||
rerender(<Harness actionKey="run:private-job-id" />);
|
||||
for (const name of ["Edit", "Pause", "Run now", "Delete"]) {
|
||||
for (const name of ["Edit", "Disable", "Run now", "Delete"]) {
|
||||
expect(screen.getByRole("button", { name })).toBeDisabled();
|
||||
}
|
||||
rerender(<Harness error="Unable to run task" />);
|
||||
@@ -805,7 +907,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
await user.click(screen.getByRole("button", { name: /PR watch/ }));
|
||||
expect(screen.getByRole("button", { name: "Run now" })).toBeDisabled();
|
||||
rerender(<Harness payload={{ jobs: [{ ...task, enabled: false, origin: null }] }} />);
|
||||
expect(screen.getByRole("button", { name: "Resume" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Enable" })).toBeDisabled();
|
||||
expect(screen.queryByRole("link", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -830,7 +932,7 @@ describe("Automation task list and detail sheet", () => {
|
||||
},
|
||||
}, { ...systemTask, state: { last_status: "error" } }] }} />);
|
||||
const row = screen.getByRole("button", { name: /PR watch.*Failed/ });
|
||||
expect(screen.getByRole("button", { name: /System tasks 1 Needs attention/ })).toBeVisible();
|
||||
expect(within(openFilters()).getByRole("menuitemradio", { name: "Needs attention 1" })).toBeVisible();
|
||||
fireEvent.click(row);
|
||||
expect(within(screen.getByRole("dialog")).getByText("Failed")).toBeVisible();
|
||||
expect(within(screen.getByRole("dialog")).queryByText(/Completed/)).not.toBeInTheDocument();
|
||||
|
||||
@@ -81,7 +81,7 @@ describe("SessionInfoPopover", () => {
|
||||
expect(detail).toHaveClass("max-w-[520px]", "rounded-modal");
|
||||
expect(within(detail).getByText("Instructions")).toBeInTheDocument();
|
||||
expect(within(detail).getByText("Check the project status")).toBeInTheDocument();
|
||||
await user.click(within(detail).getByRole("button", { name: "Done" }));
|
||||
await user.click(within(detail).getByRole("button", { name: "Close" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog", { name: "Morning check" })).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Session details" })).toHaveFocus();
|
||||
});
|
||||
@@ -103,14 +103,14 @@ describe("SessionInfoPopover", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Session details" }));
|
||||
await user.click(await screen.findByRole("button", { name: /Morning check/ }));
|
||||
const detail = screen.getByRole("dialog", { name: "Morning check" });
|
||||
await user.click(within(detail).getByRole("button", { name: "Pause" }));
|
||||
await user.click(within(detail).getByRole("button", { name: "Disable" }));
|
||||
|
||||
expect(requestMutation).toHaveBeenCalledWith(
|
||||
"automation.disable",
|
||||
{ id: "job-1" },
|
||||
20_000,
|
||||
);
|
||||
expect(await within(detail).findByRole("button", { name: "Resume" })).toBeInTheDocument();
|
||||
expect(await within(detail).findByRole("button", { name: "Enable" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("returns from the shared editor to the same task detail", async () => {
|
||||
|
||||
@@ -40,6 +40,11 @@ const agentPlugin = {
|
||||
source: "agent-plugin",
|
||||
};
|
||||
|
||||
function selectAutomationFilter(name: string) {
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: /^Filter/ }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitemradio", { name }));
|
||||
}
|
||||
|
||||
describe("Settings system domains", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
@@ -164,6 +169,24 @@ describe("Settings system domains", () => {
|
||||
expect(screen.getByTestId("settings-section-transition")).not.toHaveClass("settings-feature-page");
|
||||
});
|
||||
|
||||
it.each(["apps", "skills", "automations", "channels"] as const)(
|
||||
"keeps the standalone %s semantic heading and follows the main navigation state",
|
||||
(initialSection) => {
|
||||
renderSettingsView({ initialSection, initialSettings: settingsPayload(), showSidebar: false, mainNavigationExpanded: true });
|
||||
const page = screen.getByTestId("settings-section-transition");
|
||||
expect(page).toHaveAttribute("data-main-navigation-expanded", "true");
|
||||
const heading = within(page).getByRole("heading", { level: 1 });
|
||||
expect(heading.parentElement).toHaveClass("settings-feature-header");
|
||||
expect(heading).not.toHaveAttribute("aria-hidden");
|
||||
},
|
||||
);
|
||||
|
||||
it("does not hide a standalone heading when the navigation is collapsed or absent", () => {
|
||||
renderSettingsView({ initialSection: "skills", initialSettings: settingsPayload(), showSidebar: false, mainNavigationExpanded: false });
|
||||
expect(screen.getByTestId("settings-section-transition")).toHaveAttribute("data-main-navigation-expanded", "false");
|
||||
expect(screen.getByRole("heading", { name: "Skills", level: 1 })).toBeVisible();
|
||||
});
|
||||
|
||||
it("uses the inline section heading layout to align Apps titles and counts", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
@@ -238,7 +261,7 @@ describe("Settings system domains", () => {
|
||||
const input = screen.getByRole("textbox", { name: "Describe an automation" });
|
||||
expect(input).toHaveAttribute(
|
||||
"placeholder",
|
||||
"What would you like nanobot to schedule?",
|
||||
"What would you like nanobot to automate?",
|
||||
);
|
||||
fireEvent.change(input, { target: { value: "Summarize updates every weekday at 9" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
@@ -278,14 +301,14 @@ describe("Settings system domains", () => {
|
||||
});
|
||||
|
||||
expect(await screen.findByRole("button", { name: /Daily summary/ })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Paused 0" }));
|
||||
selectAutomationFilter("Disabled 0");
|
||||
expect(screen.queryByRole("button", { name: /Daily summary/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Today" })).toBeVisible();
|
||||
fireEvent.click(screen.getByRole("button", { name: "All 1" }));
|
||||
selectAutomationFilter("All 1");
|
||||
expect(await screen.findByRole("button", { name: /Daily summary/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("wraps automation filters and keeps every option selectable", async () => {
|
||||
it("reveals status filters on demand 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") {
|
||||
@@ -293,7 +316,7 @@ describe("Settings system domains", () => {
|
||||
{
|
||||
id: "heartbeat", name: "heartbeat", enabled: true, protected: true,
|
||||
schedule: { kind: "every", every_ms: 1_800_000 },
|
||||
payload: { message: "System-managed automation" }, state: {},
|
||||
payload: { message: "System-managed automation" }, state: { next_run_at_ms: Date.now() + 60_000 },
|
||||
},
|
||||
{
|
||||
id: "paused-job", name: "Paused reminder", enabled: false,
|
||||
@@ -307,20 +330,18 @@ describe("Settings system domains", () => {
|
||||
}));
|
||||
renderSettingsView({ initialSection: "automations", initialSettings: settingsPayload(), showSidebar: false });
|
||||
|
||||
const filters = await screen.findByRole("group", { name: "Automations" });
|
||||
expect(within(filters).getByRole("button", { name: "All 1" }).parentElement).toHaveClass("segmented-control", "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");
|
||||
const trigger = await screen.findByRole("button", { name: "Filter", exact: true });
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false });
|
||||
const menu = screen.getByRole("menu", { name: "Filter" });
|
||||
expect(within(menu).getAllByRole("menuitemradio")).toHaveLength(4);
|
||||
expect(within(menu).getByRole("menuitemradio", { name: "All 1" })).toHaveAttribute("aria-checked", "true");
|
||||
expect(within(menu).queryByRole("menuitemradio", { name: /System/ })).not.toBeInTheDocument();
|
||||
fireEvent.click(within(menu).getByRole("menuitemradio", { name: "Disabled 1" }));
|
||||
expect(screen.getByRole("button", { name: "Filter: Disabled" })).toBeVisible();
|
||||
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 () => {
|
||||
|
||||
@@ -138,6 +138,7 @@ export function renderSettingsView(
|
||||
| "runtime";
|
||||
initialSettings?: SettingsPayload;
|
||||
showSidebar?: boolean;
|
||||
mainNavigationExpanded?: boolean;
|
||||
onBackToChat?: () => void;
|
||||
onSettingsChange?: (payload: SettingsPayload) => void;
|
||||
onStartAutomationChat?: React.ComponentProps<typeof SettingsView>["onStartAutomationChat"];
|
||||
@@ -152,6 +153,7 @@ export function renderSettingsView(
|
||||
initialSection={options.initialSection ?? "apps"}
|
||||
initialSettings={options.initialSettings}
|
||||
showSidebar={options.showSidebar}
|
||||
mainNavigationExpanded={options.mainNavigationExpanded}
|
||||
onToggleTheme={() => {}}
|
||||
onBackToChat={options.onBackToChat ?? (() => {})}
|
||||
onModelNameChange={() => {}}
|
||||
|
||||
Reference in new issue
Block a user