Phase 1 of #2126. Six hooks move out of `clients/web/src/App.tsx`, taking its component body from 4,891 to 4,267 lines with no behavior change: - useThemeToggle — the light/dark toggle - useTabUiState — the nine per-screen `ui` objects, the active tab, the pinned-Protocol ids, and the session reset - useInspectorStores — the twelve state managers as one create/destroy lifecycle, their `core/react` hooks, and the pagination-mode selection - useExportActions — the eleven Clear / Export / Replay handlers - useProgressToasts — `notifications/progress` toasts - useTaskToasts — task-status toasts, the cancel confirmation, the taskId -> progress map, and the in-flight tool-call taskId ref Holding the stores in one slot collapses `setupClientForServer`'s and `onConfirmRemove`'s dependency arrays from twelve entries to two stable callbacks; `destroyStores` reads the live set through a ref mirror rather than the state it also writes. All six hooks are at 100% on all four coverage dimensions, no `v8 ignore` needed. Also refreshes the now-stale "~4.5k-line" description of App.tsx in AGENTS.md and the coverage `include` comment. Signed-off-by: cliffhall <cliff@futurescale.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { act } from "react";
|
|
import { useComputedColorScheme } from "@mantine/core";
|
|
import { renderWithMantine } from "../test/renderWithMantine";
|
|
import { useThemeToggle } from "./useThemeToggle";
|
|
|
|
/**
|
|
* Renders the hook alongside the resolved scheme, so each assertion reads what
|
|
* the user would actually be looking at rather than what was stored.
|
|
*/
|
|
function harness(colorScheme?: "light" | "dark") {
|
|
let toggle: (() => void) | undefined;
|
|
let scheme = "";
|
|
function Probe() {
|
|
toggle = useThemeToggle().onToggleTheme;
|
|
scheme = useComputedColorScheme("light");
|
|
return null;
|
|
}
|
|
renderWithMantine(<Probe />, colorScheme ? { colorScheme } : undefined);
|
|
return {
|
|
scheme: () => scheme,
|
|
toggle: () => {
|
|
act(() => toggle?.());
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("useThemeToggle", () => {
|
|
it("switches a light scheme to dark", () => {
|
|
const h = harness();
|
|
expect(h.scheme()).toBe("light");
|
|
h.toggle();
|
|
expect(h.scheme()).toBe("dark");
|
|
});
|
|
|
|
it("switches a dark scheme back to light", () => {
|
|
const h = harness("dark");
|
|
expect(h.scheme()).toBe("dark");
|
|
h.toggle();
|
|
expect(h.scheme()).toBe("light");
|
|
});
|
|
});
|