Files
nanobot/webui/src/tests/session-automation-lazy.test.tsx
T
chengyongru 519ed81132 feat(webui): inspect file context in a live graph sidebar (#6562)
* feat(webui): inspect file context in a live graph sidebar

* refactor(webui): place preview controls in the shared sidebar header

* fix(webui): synchronize npm lockfile for graph dependencies

* fix(webui): preserve compacted context and refine graph inspection

* fix(context): harden provenance, request usage, and drawer lifecycle

* fix(webui): align source skeleton and browser fixtures

* perf(context): reuse source analysis and capture request graphs once

* perf(webui): compact graph history and render graph motion on canvas

* fix(webui): remove redundant context sidebar header

* style(webui): clarify context replay icon

* perf(webui): pace context replay on an adaptive timeline

* feat(webui): briefly reveal labels for new context nodes

* fix(webui): reveal new labels only for loaded context files

* fix(webui): restart graph animation clock after idle

* fix(webui): reveal labels when replay reverses node exit

* refactor(context): project file-use facts without retention tracking

* refactor(context): observe file reads outside agent execution

* fix(webui): animate context sidebar closing

* refactor(context): remove unused graph and usage panel code

* refactor(context): isolate prompt observation from execution metadata

* fix(webui): clarify cache rate and show context token usage

* fix(webui): abbreviate context token counts in thousands

* fix(webui): omit token unit from context usage details

* fix(webui): restore large source preview highlighting and panel elevation

* fix(webui): distinguish modifier scrolling from keyboard focus

* fix(webui): align preview tab and panel corner radii

* fix(webui): attach file tabs to the header divider

* fix(webui): use one action to toggle file preview mode

* fix(webui): use hover hint for context replay

* fix(webui): share composer layout between graph and file sidebars

* fix(webui): align sidebar bottom with composer surface

* fix(webui): restore mobile graph drawing and touch file details

* test(webui): align legacy cache assertions with current label

* perf(context): retain source analysis and bound graph animation work

* style(webui): add light elevation to user messages

* test(webui): await lazy graph scene before replay assertions

* fix(webui): align preview skeleton and browser contracts
2026-11-05 17:09:20 +08:00

97 lines
4.8 KiB
TypeScript

import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { SessionAutomationJob } from "@/lib/types";
const job: SessionAutomationJob = {
id: "job-1", name: "Morning check", enabled: true,
schedule: { kind: "every", every_ms: 3_600_000 },
payload: { message: "Check the project status" },
state: { next_run_at_ms: Date.now() + 3_600_000 },
};
let release: (() => void) | undefined;
let moduleLoad: Promise<unknown> | undefined;
async function loadView(fail = false) {
const loaded = vi.fn();
const gate = new Promise<void>((resolve) => { release = resolve; });
vi.doMock("@/components/settings/system/AutomationsSettings", (original) => {
loaded();
moduleLoad = gate.then(() => {
if (fail) throw new Error("Automation chunk unavailable");
return original<typeof import("@/components/settings/system/AutomationsSettings")>();
});
return moduleLoad;
});
const { initializeI18n, loadAllLocaleResources } = await import("@/i18n");
await initializeI18n();
await loadAllLocaleResources();
const { SessionInfoPopoverView } = await import("@/components/thread/SessionInfoPopoverView");
render(<><textarea aria-label="Unsent draft" defaultValue="Keep this draft" /><SessionInfoPopoverView jobs={[job]} loading={false} loadFailed={false} now={Date.now()}
onAction={async () => []} onEdit={async () => [job]}
/></>);
return loaded;
}
async function selectJob() {
fireEvent.click(screen.getByRole("button", { name: "Session details" }));
fireEvent.click(await screen.findByRole("button", { name: /Morning check/ }));
return screen.findByRole("dialog", { name: "Morning check" });
}
beforeEach(() => { vi.resetModules(); localStorage.clear(); });
afterEach(async () => {
cleanup();
await act(async () => { release?.(); await moduleLoad?.catch(() => {}); });
release = undefined;
moduleLoad = undefined;
vi.doUnmock("@/components/settings/system/AutomationsSettings");
vi.restoreAllMocks();
});
describe("session automation dialog loading", () => {
it("loads only on inspection and replaces a named loading dialog with the real controls", async () => {
const loaded = await loadView();
await vi.dynamicImportSettled();
expect(loaded).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Session details" }));
const row = await screen.findByRole("button", { name: /Morning check/ });
expect(loaded).not.toHaveBeenCalled();
fireEvent.click(row);
const pending = await screen.findByRole("dialog", { name: "Morning check" });
expect(within(pending).getByRole("status", { name: "Loading automations..." })).toHaveAttribute("aria-busy", "true");
await act(async () => { release?.(); await moduleLoad; });
await screen.findByText("Check the project status");
expect(screen.getAllByRole("dialog")).toHaveLength(1);
expect(screen.getByRole("button", { name: "Edit" })).toBeEnabled();
expect(screen.getByRole("textbox", { name: "Unsent draft", hidden: true })).toHaveValue("Keep this draft");
fireEvent.click(screen.getByRole("button", { name: "Close" }));
await waitFor(() => expect(screen.getByRole("button", { name: "Session details" })).toHaveFocus());
});
it("can close during download without a late dialog reopening", async () => {
const loaded = await loadView();
const dialog = await selectJob();
await waitFor(() => expect(loaded).toHaveBeenCalledOnce());
fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
await waitFor(() => expect(screen.getByRole("button", { name: "Session details" })).toHaveFocus());
await act(async () => { release?.(); await moduleLoad; });
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
expect(screen.getByRole("textbox", { name: "Unsent draft", hidden: true })).toHaveValue("Keep this draft");
await selectJob();
expect(await screen.findByText("Check the project status")).toBeVisible();
expect(loaded).toHaveBeenCalledOnce();
});
it("contains a failed chunk in a closeable dialog without losing the chat draft", async () => {
vi.spyOn(console, "error").mockImplementation(() => {});
await loadView(true);
await selectJob();
await act(async () => { release?.(); await moduleLoad?.catch(() => {}); });
expect(await screen.findByRole("alert")).toHaveTextContent("Could not load automations.");
expect(screen.getByRole("textbox", { name: "Unsent draft", hidden: true })).toHaveValue("Keep this draft");
fireEvent.click(screen.getByRole("button", { name: "Close" }));
await waitFor(() => expect(screen.getByRole("button", { name: "Session details" })).toHaveFocus());
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
});