Files
AgentHub/client/src/components/__tests__/RouteErrorBoundary.test.tsx
T
nntrivi2001 198fbb7980 fix: event-loop freezes, plugin-install boot crash, tmux attach/scrollbar, Codex transcripts
- GET /api/workflows: one LEAD() window pass in a read worker (read-pool.js,
  workflow-stats.js); idx_events_session restored, idx_events_tool added
- compat-sqlite gains function/pluck/readonly so a plugin install without a
  better-sqlite3 build boots again; antigravity-usage uses db.js's Database
- install-hooks adds no checkout hooks while the agenthub plugin is enabled
  (events were doubled)
- terminal attach runs the live tmux server's own binary; the pane scrollbar
  gets a visible 2-column style, and claude panes start with
  CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN=1 so tmux keeps history to scroll
- Codex sessions' conversation in GET /api/sessions/:id/transcript
- Codex/Antigravity sessions claimed by their workspace without hooks
- UI-audit follow-ups, docs and OpenAPI
2026-10-05 17:01:05 +07:00

83 lines
3.0 KiB
TypeScript

/**
* @file RouteErrorBoundary.test.tsx
* @description The route error boundary: a failed lazy chunk (stale assets after
* a self-update) reloads the page once; any other error — or a second chunk
* failure — shows the themed Reload fallback instead of a blank app.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render, screen } from "@testing-library/react";
import { RouteErrorBoundary, isChunkLoadError, reloadOnce } from "../RouteErrorBoundary";
function Boom({ error }: { error: Error }): never {
throw error;
}
let reload: ReturnType<typeof vi.fn>;
beforeEach(() => {
sessionStorage.clear();
reload = vi.fn();
vi.spyOn(console, "error").mockImplementation(() => {});
});
afterEach(() => vi.restoreAllMocks());
describe("RouteErrorBoundary", () => {
it("recognises dynamic-import failures", () => {
expect(
isChunkLoadError(new TypeError("Failed to fetch dynamically imported module: /a.js"))
).toBe(true);
expect(isChunkLoadError(Object.assign(new Error("x"), { name: "ChunkLoadError" }))).toBe(true);
expect(isChunkLoadError(new Error("Importing a module script failed."))).toBe(true);
expect(isChunkLoadError(new Error("boom"))).toBe(false);
});
it("reloads once on a chunk error, never twice in a row", () => {
expect(reloadOnce(reload)).toBe(true);
expect(reloadOnce(reload)).toBe(false);
expect(reload).toHaveBeenCalledTimes(1);
});
it("shows a Reload fallback for an ordinary render error", () => {
render(
<RouteErrorBoundary reload={reload}>
<Boom error={new Error("boom")} />
</RouteErrorBoundary>
);
expect(screen.getByRole("alert")).toHaveTextContent(/something went wrong/i);
expect(screen.getByRole("button", { name: /reload/i })).toBeInTheDocument();
expect(reload).not.toHaveBeenCalled();
});
it("clears the error when the route changes, so the next page renders", () => {
const { rerender } = render(
<RouteErrorBoundary reload={reload} resetKey="/workspace">
<Boom error={new Error("boom")} />
</RouteErrorBoundary>
);
expect(screen.getByRole("alert")).toBeInTheDocument();
rerender(
<RouteErrorBoundary reload={reload} resetKey="/workspace">
<p>settings page</p>
</RouteErrorBoundary>
);
expect(screen.getByRole("alert")).toBeInTheDocument();
rerender(
<RouteErrorBoundary reload={reload} resetKey="/settings/general">
<p>settings page</p>
</RouteErrorBoundary>
);
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getByText("settings page")).toBeInTheDocument();
});
it("reloads on a chunk error the first time", () => {
render(
<RouteErrorBoundary reload={reload}>
<Boom error={new TypeError("Failed to fetch dynamically imported module: /x.js")} />
</RouteErrorBoundary>
);
expect(reload).toHaveBeenCalledTimes(1);
});
});