Files
tech-log-frontend/tests/features/tech-log/evidence-asset-resolver.test.tsx
T
DongHyeonkaandClaude Opus 5 7dda6c7923 refactor: v4 편집기가 걷어낸 화면의 잔해를 지운다
즉시 미리보기(`InstantPreview`)와 동작 원리 띠(`MechanismMap`)는 파일로만 남아 있었다.
아무 화면도 부르지 않는데 규칙과 검사는 그대로여서, 고칠 때마다 살아 있는 코드처럼 따라왔다.

함께 죽어 있던 것들:
- `createAssetCatalogResolver` — 즉시 미리보기만 쓰던 픽셀 해석기
- `mergeAssetCatalog` 와 편집기의 자료 목록 — 그 목록을 읽던 화면이 없어졌다
  (`DocumentEditor` 는 이미 `assets: _assets` 로 받아만 두고 있었다)
- 분할 편집기·미리보기 모드·예전 검증 패널의 CSS 규칙

검사는 지우지 않고 살아 있는 쪽으로 옮겼다. 자료 열쇠 합의 검사는 이제 목 어댑터의 투영과
공개 화면이 실제로 쓰는 해석기를 맞대고 본다 — READY 검사를 빼 보면 144개 조합 중 16개가
어긋난다.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 17:44:09 +09:00

135 lines
4.4 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "vitest";
import { findResolvableAsset } from "../../../src/features/tech-log/domain/content-format/asset-evidence-catalog.ts";
import {
createResolvedAssetResolver,
MISSING_EVIDENCE_ASSET,
} from "../../../src/features/tech-log/presentation/shared/public-render/asset-resolvers.ts";
/** 서버가 블록에 붙여 보내는 서술자. 화면이 그림을 그릴 때 읽는 것은 이것뿐이다. */
function figure(asset: Record<string, unknown>) {
return [{ type: "EVIDENCE_FIGURE", key: String(asset["assetKey"]), asset }] as never;
}
const READY = {
id: "11111111-1111-4111-8111-111111111111",
assetKey: "boundary",
kind: "DIAGRAM",
mediaType: "image/svg+xml",
originalFilename: "b.svg",
byteSize: 10,
width: 1080,
height: 420,
altText: "경계",
decorative: false,
managementStatus: "READY",
publicPath: "/media/boundary.svg",
usageCount: 0,
version: 1,
createdAt: "2026-08-14T01:00:00.000Z",
updatedAt: "2026-08-14T01:00:00.000Z",
} as never;
test("고를 수 있는 자료를 열쇠로 찾는다", () => {
const found = findResolvableAsset([READY], "boundary");
assert.equal(found?.publicPath, "/media/boundary.svg");
assert.equal(found?.width, 1080);
assert.equal(found?.height, 420);
});
test("falls back to the static registry for the legacy hardcoded key", () => {
const resolve = createResolvedAssetResolver([]);
const asset = resolve("fetch-strategy-boundary");
assert.equal(asset.src, "/media/fetch-strategy-boundary.svg");
});
test("returns the placeholder instead of throwing on an unknown key", () => {
const resolve = createResolvedAssetResolver([]);
assert.deepEqual(resolve("does-not-exist"), MISSING_EVIDENCE_ASSET);
});
test("격리된 자료는 고르지 않는다", () => {
assert.equal(
findResolvableAsset([{ ...(READY as object), managementStatus: "QUARANTINED" } as never], "boundary"),
undefined,
);
});
test("resolves from the server render model blocks", () => {
const resolve = createResolvedAssetResolver([
{
type: "EVIDENCE_FIGURE",
key: "boundary",
asset: {
assetId: "11111111-1111-4111-8111-111111111111",
assetKey: "boundary",
mediaType: "image/svg+xml",
publicPath: "/media/boundary.svg",
width: 800,
height: 300,
decorative: false,
},
},
]);
assert.equal(resolve("boundary").src, "/media/boundary.svg");
assert.equal(resolve("boundary").width, 800);
});
test("같은 열쇠를 가진 격리 자료보다 쓸 수 있는 자료가 이긴다", () => {
const found = findResolvableAsset(
[{ ...(READY as object), managementStatus: "QUARANTINED" } as never, READY],
"boundary",
);
assert.equal(found?.publicPath, "/media/boundary.svg");
});
test("keeps the legacy key's hand-authored labels when a server block resolves it via descriptor (today's real Preview/Snapshot path)", () => {
const resolve = createResolvedAssetResolver([
{
type: "EVIDENCE_FIGURE",
key: "fetch-strategy-boundary",
asset: {
assetId: "00000000-0000-4000-8000-000000000001",
assetKey: "fetch-strategy-boundary",
mediaType: "image/svg+xml",
publicPath: "/media/fetch-strategy-boundary.svg",
width: 1080,
height: 420,
decorative: false,
},
},
]);
assert.deepEqual(resolve("fetch-strategy-boundary"), {
src: "/media/fetch-strategy-boundary.svg",
width: 1080,
height: 420,
triggerLabel: "Fetch Join과 Batch Fetch 비교 다이어그램 크게 보기",
dialogLabel: "Fetch Join과 Batch Fetch의 페이징 경계 확대",
});
});
test("a colliding backend descriptor's publicPath wins over the legacy src, but the legacy labels still win", () => {
const resolve = createResolvedAssetResolver(
figure({
assetId: "11111111-1111-4111-8111-111111111111",
assetKey: "fetch-strategy-boundary",
mediaType: "image/svg+xml",
publicPath: "/media/should-win.svg",
width: 999,
height: 111,
decorative: false,
}),
);
const asset = resolve("fetch-strategy-boundary");
assert.equal(asset.src, "/media/should-win.svg");
assert.equal(asset.width, 999);
assert.equal(asset.height, 111);
assert.equal(asset.triggerLabel, "Fetch Join과 Batch Fetch 비교 다이어그램 크게 보기");
assert.equal(asset.dialogLabel, "Fetch Join과 Batch Fetch의 페이징 경계 확대");
});