Files
fusion/packages/dashboard/app/hooks/__tests__/useMainPanelTaskDetail.test.ts
gsxdsm f6f9e822f5 refactor(dashboard): extract task-detail, board-scroll, popped-out hooks
Extract three AppInner state clusters into hooks:
- useMainPanelTaskDetail: the main-panel task-detail snapshot + initial tab;
  setTask accepts the SetStateAction updater form so the embedded detail can
  patch the snapshot on task updates.
- useBoardScrollRestore: the board scroll snapshot refs, capture, and the
  double-requestAnimationFrame restore effect keyed on taskView; exposes
  requestRestore for App to schedule a restore on detail close.
- usePoppedOutTasks: the popped-out task-detail windows (dedupe-by-id popOut,
  close-by-id).

App keeps the navigation-history composition (openTaskDetailInMainPanel /
closeTaskDetailMainPanel) and now consumes the hooks' primitives.
Behavior-preserving; App.test.tsx identical (5 pre-existing failures, none
introduced). Verified by typecheck, eslint, and 5 renderHook tests.

Completes U6 (App.tsx module-breakup plan).
2026-06-23 21:09:36 -07:00

31 lines
974 B
TypeScript

import { describe, expect, it } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useMainPanelTaskDetail } from "../useMainPanelTaskDetail";
const task = (id: string) => ({ id, title: id, status: "todo" } as never);
describe("useMainPanelTaskDetail", () => {
it("setTask accepts both a value and an updater", () => {
const { result } = renderHook(() => useMainPanelTaskDetail());
act(() => {
result.current.setTask(task("1"));
});
expect(result.current.task?.id).toBe("1");
act(() => {
result.current.setTask((previous) => (previous ? { ...previous, title: "renamed" } : previous));
});
expect(result.current.task?.title).toBe("renamed");
});
it("setInitialTab updates the tab", () => {
const { result } = renderHook(() => useMainPanelTaskDetail());
act(() => {
result.current.setInitialTab("changes");
});
expect(result.current.initialTab).toBe("changes");
});
});