Address code-review findings on the App.tsx module-breakup: - Add behavior-preservation tests: useBoardScrollRestore real double-rAF restore path; useApprovalBanner clear-on-leave-awaiting + mailbox-refresh dedup; useCapacityRiskBanner threshold-change-clears + dismiss-persist assertion; useChatUnreadBadge room-message + cross-project filter; and a new sseSplitIntegration test co-mounting useMailboxUnread + useApprovalBanner to pin the KTD4 SSE split (no double-fire; awaiting-approval refresh exactly once via callback). - Add unmount/teardown assertions (stash interval clear, auth-token listener removal, dashboard-health cancelled flag). - Drop dead type-only re-exports (ApprovalBannerCandidate, CliActionDeps) from App.tsx — zero importers (verified). All hook tests green; App.test.tsx unchanged (5 pre-existing). typecheck + eslint clean. No production behavior change.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { renderHook, act } from "@testing-library/react";
|
|
import { AUTH_TOKEN_RECOVERY_REQUIRED_EVENT } from "../../auth";
|
|
import { useAuthTokenRecovery } from "../useAuthTokenRecovery";
|
|
|
|
describe("useAuthTokenRecovery", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
it("opens when the daemon auth-failure event fires", () => {
|
|
const { result } = renderHook(() => useAuthTokenRecovery());
|
|
|
|
expect(result.current.open).toBe(false);
|
|
|
|
act(() => {
|
|
window.dispatchEvent(new Event(AUTH_TOKEN_RECOVERY_REQUIRED_EVENT));
|
|
});
|
|
|
|
expect(result.current.open).toBe(true);
|
|
});
|
|
it("removes the daemon auth-failure listener on unmount", () => {
|
|
const addSpy = vi.spyOn(window, "addEventListener");
|
|
const removeSpy = vi.spyOn(window, "removeEventListener");
|
|
const { unmount } = renderHook(() => useAuthTokenRecovery());
|
|
|
|
const addedCall = addSpy.mock.calls.find(
|
|
([type]) => type === AUTH_TOKEN_RECOVERY_REQUIRED_EVENT,
|
|
);
|
|
expect(addedCall).toBeTruthy();
|
|
const addedHandler = addedCall![1] as EventListener;
|
|
|
|
unmount();
|
|
|
|
expect(removeSpy).toHaveBeenCalledWith(AUTH_TOKEN_RECOVERY_REQUIRED_EVENT, addedHandler);
|
|
});
|
|
});
|