// @vitest-environment jsdom import assert from "node:assert/strict"; import { renderHook } from "@testing-library/react"; import type { ReactNode } from "react"; import { test } from "vitest"; import type { StudioAssetGateway } from "../../../src/features/tech-log/application/ports/studio-asset-gateway.ts"; import { StudioContext, useStudioAssetGateway, type StudioContextValue, } from "../../../src/features/tech-log/presentation/studio/use-studio.ts"; /** * I3 (Task 7 fix round 1). `StudioContextValue.assetGateway` stays nullable * so the many test harnesses that render `StudioProvider` without a * `createAssetGateway` prop keep compiling — but that nullability would let * Asset UI (Task 11) write `if (!assetGateway) return null` and ship a * confusingly empty screen with the type checker satisfied. This pins the * throwing accessor Asset UI must use instead. */ function contextValue( assetGateway: StudioAssetGateway | null, ): StudioContextValue { return { gateway: {} as never, assetGateway, // 이 테스트는 Asset 접근자만 고정한다 — 관리 게이트웨이는 쓰이지 않으므로 자리만 채운다. managementGateway: {} as never, resolvePublishedLabel: () => undefined, now: () => new Date("2026-08-14T01:00:00.000Z"), editor: null, requestAnnouncement: "", setRequestAnnouncement: () => {}, navigateInternal: () => {}, beginEditor: () => {}, updateEditorDraft: () => {}, setEditorStatus: () => {}, clearEditor: () => {}, }; } function wrapperFor(assetGateway: StudioAssetGateway | null) { return function Wrapper({ children }: { children: ReactNode }) { return ( {children} ); }; } test("returns the asset gateway when the provider supplied one", () => { const assetGateway = {} as StudioAssetGateway; const { result } = renderHook(() => useStudioAssetGateway(), { wrapper: wrapperFor(assetGateway), }); assert.equal(result.current, assetGateway); }); test("throws a clear error instead of returning null when no asset gateway was supplied", () => { assert.throws( () => renderHook(() => useStudioAssetGateway(), { wrapper: wrapperFor(null) }), /useStudioAssetGateway must be used within a StudioProvider that was given a createAssetGateway prop/, ); });