Files
tech-log-frontend/tests/features/tech-log/use-studio-asset-gateway.test.tsx
T
DongHyeonka 11c2713139 feat: let Studio create the topics and projects publishing requires
Publishing needs a topic and nothing could create one. The backend now owns
that surface; this is its consumer — the management contract vendored, a
gateway over its nine operations, and one Studio screen that lists, creates,
and deletes topics and projects.

The screen adds no CSS. It reuses the classes the working-copy list already
uses, so it inherits Studio's spacing, type, and colour rather than growing a
second visual vocabulary beside them. Scope stops at list/create/delete:
renaming, phase changes, and visibility are implemented in the backend and
declared in the contract, but their screens are a separate design.

Two real defects surfaced while making the public port async, and both would
have shipped:

The search page and the header search dialog shared a query key. With an empty
query, `["tech-log","search",""]` was identical for both, so react-query
handed one surface the other's cache — different shapes — and the page died
reading a field that was not there. Keys now name the surface.

The explore filter's selects are uncontrolled and read `defaultValue`, which
React applies once. Their options arrive later now, so the first render had
nothing to match and the value stayed empty: a topic in the URL no longer
showed as selected. The form key includes whether the catalog has arrived, so
it remounts with the options present. Controlled inputs would be the other
answer, but this form submits to build a URL — the URL owns the value.

The route brought its own bookkeeping: a build chunk, a manual accessibility
evidence file, and the CI artifact baseline that counts them. The gate pins a
digest of its own shape precisely so a new route cannot slip in without that
count being reviewed.

Test harnesses that render public screens now assemble the query providers and
await the settled paint, because the screens they render became async.
2026-08-20 23:40:15 +09:00

68 lines
2.4 KiB
TypeScript

// @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 (
<StudioContext.Provider value={contextValue(assetGateway)}>
{children}
</StudioContext.Provider>
);
};
}
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/,
);
});