refactor: 템플릿에서 기본적으로 제공하고 있는 워크 플로우에 디자인과 라우팅 흡수
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { afterEach, beforeEach, expect, test } from "vitest";
|
||||
import { act, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { act, render as testingRender, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
/*
|
||||
@@ -39,10 +39,32 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
import {
|
||||
AssetLibrary,
|
||||
AssetLibrary as AssetLibraryView,
|
||||
canHardDelete,
|
||||
} from "../../../src/features/tech-log/presentation/studio/components/asset-library.tsx";
|
||||
import { StudioGatewayError } from "../../../src/features/tech-log/application/ports/studio-gateway-error.ts";
|
||||
import type { StudioAssetGateway } from "../../../src/features/tech-log/application/ports/studio-asset-gateway.ts";
|
||||
import { createMockStudioGateway, DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
function AssetLibrary({ gateway }: Readonly<{ gateway: StudioAssetGateway }>) {
|
||||
return (
|
||||
<StudioProvider
|
||||
now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createGateway={() => createMockStudioGateway()}
|
||||
createAssetGateway={() => gateway}
|
||||
createManagementGateway={createManagementGatewayStub}
|
||||
>
|
||||
<AssetLibraryView />
|
||||
</StudioProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const ASSET = {
|
||||
id: "11111111-1111-4111-8111-111111111111",
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import type { ComponentProps, ReactNode } from "react";
|
||||
import { afterAll, beforeAll, expect, test } from "vitest";
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { act, fireEvent, render as testingRender, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
|
||||
import {
|
||||
AssetPicker,
|
||||
AssetPicker as AssetPickerView,
|
||||
buildEvidenceDirective,
|
||||
} from "../../../src/features/tech-log/presentation/studio/components/asset-picker.tsx";
|
||||
import {
|
||||
AssetUploadDialog,
|
||||
AssetUploadDialog as AssetUploadDialogView,
|
||||
stateForError,
|
||||
stateForUploaded,
|
||||
} from "../../../src/features/tech-log/presentation/studio/components/asset-upload-dialog.tsx";
|
||||
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
|
||||
import { createMockStudioGateway } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
import { projectWorkingCopy as mockProjectWorkingCopy } from "../../../src/features/tech-log/adapters/mock/project-public-render-model.ts";
|
||||
@@ -25,8 +26,64 @@ import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtur
|
||||
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
|
||||
import type { StudioAssetGateway } from "../../../src/features/tech-log/application/ports/studio-asset-gateway.ts";
|
||||
import { StudioGatewayError } from "../../../src/features/tech-log/application/ports/studio-gateway-error.ts";
|
||||
import type { StudioGateway } from "../../../src/features/tech-log/application/ports/studio-gateway.ts";
|
||||
import type { Asset } from "../../../src/features/tech-log/contracts/studio/contract.ts";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioAssetGatewayFromApplication, studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
function AssetTestProvider({
|
||||
gateway,
|
||||
children,
|
||||
}: Readonly<{
|
||||
gateway: StudioAssetGateway;
|
||||
children: ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<StudioProvider
|
||||
now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createGateway={() => createMockStudioGateway()}
|
||||
createAssetGateway={() => gateway}
|
||||
createManagementGateway={createManagementGatewayStub}
|
||||
>
|
||||
{children}
|
||||
</StudioProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function AssetPicker({
|
||||
gateway,
|
||||
onInsert,
|
||||
}: Readonly<{
|
||||
gateway: StudioAssetGateway;
|
||||
onInsert: (directive: string) => void;
|
||||
}>) {
|
||||
return (
|
||||
<AssetTestProvider gateway={gateway}>
|
||||
<AssetPickerView onInsert={onInsert} />
|
||||
</AssetTestProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function AssetUploadDialog({
|
||||
gateway,
|
||||
...props
|
||||
}: Readonly<
|
||||
ComponentProps<typeof AssetUploadDialogView> & {
|
||||
gateway: StudioAssetGateway;
|
||||
}
|
||||
>) {
|
||||
return (
|
||||
<AssetTestProvider gateway={gateway}>
|
||||
<AssetUploadDialogView {...props} />
|
||||
</AssetTestProvider>
|
||||
);
|
||||
}
|
||||
|
||||
// jsdom does not implement `<dialog>` -- same polyfill `studio-save-navigation.test.tsx`
|
||||
// and `studio-decision-authoring.test.tsx` already use for the other Studio dialogs.
|
||||
@@ -423,7 +480,7 @@ test("inserts evidence after the active document block without leaving the writi
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${FIXTURE_IDS.redisAdapterCase}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={FIXTURE_IDS.redisAdapterCase} />
|
||||
</StudioProvider>
|
||||
@@ -492,8 +549,8 @@ test("generates a fresh idempotency key for each upload attempt, even after a fa
|
||||
test("an asset uploaded through the mock composition previews live and passes mock validation for the same key", async () => {
|
||||
const user = userEvent.setup();
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const assetGateway = installed.createStudioAssetGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
const assetGateway = studioAssetGatewayFromApplication(installed.createStudioApplication());
|
||||
|
||||
const created = await gateway.createDocument(
|
||||
{
|
||||
@@ -516,7 +573,7 @@ test("an asset uploaded through the mock composition previews live and passes mo
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${created.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={created.id} />
|
||||
</StudioProvider>
|
||||
@@ -586,7 +643,7 @@ test("an asset uploaded through the mock composition previews live and passes mo
|
||||
// the gate for a genuinely dangling reference.
|
||||
test("a key backed by no asset and no catalog entry still fails mock validation", async () => {
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
|
||||
const created = await gateway.createDocument(
|
||||
{
|
||||
@@ -627,7 +684,7 @@ test("a key backed by no asset and no catalog entry still fails mock validation"
|
||||
// `Error` escaping a port whose contract is `StudioGatewayError` only.
|
||||
test("a directive key equal to a non-asset EVIDENCE catalog row's id is rejected on both mock paths, never as a raw Error", async () => {
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
|
||||
const created = await gateway.createDocument(
|
||||
{
|
||||
@@ -734,8 +791,8 @@ test("the mock's projectWorkingCopy wrapper rejects a non-asset EVIDENCE catalog
|
||||
// before round 2.
|
||||
test("EVIDENCE_ALT_REQUIRED respects Asset.decorative -- empty alt passes for a decorative Asset, fails for a non-decorative one", async () => {
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const assetGateway = installed.createStudioAssetGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
const assetGateway = studioAssetGatewayFromApplication(installed.createStudioApplication());
|
||||
|
||||
const decorative = await assetGateway.uploadAsset(
|
||||
{ file: new File(["<svg/>"], "deco.svg", { type: "image/svg+xml" }), kind: "IMAGE", decorative: true },
|
||||
@@ -1340,9 +1397,7 @@ async function uploadThroughDialog(
|
||||
}
|
||||
|
||||
async function createUploadCase(
|
||||
gateway: ReturnType<
|
||||
ReturnType<typeof createTechLogFeatureInstalledInput>["input"]["createStudioGateway"]
|
||||
>,
|
||||
gateway: StudioGateway,
|
||||
slug: string,
|
||||
title: string,
|
||||
) {
|
||||
@@ -1367,9 +1422,7 @@ async function createUploadCase(
|
||||
}
|
||||
|
||||
async function saveValidateAndPreview(
|
||||
gateway: ReturnType<
|
||||
ReturnType<typeof createTechLogFeatureInstalledInput>["input"]["createStudioGateway"]
|
||||
>,
|
||||
gateway: StudioGateway,
|
||||
created: { id: string; version: number },
|
||||
slug: string,
|
||||
bodyMarkdown: string,
|
||||
@@ -1401,13 +1454,13 @@ async function saveValidateAndPreview(
|
||||
test("an asset uploaded with alt text inserts that alt and the document validates as publishable, with no hand-editing", async () => {
|
||||
const user = userEvent.setup();
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const assetGateway = installed.createStudioAssetGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
const assetGateway = studioAssetGatewayFromApplication(installed.createStudioApplication());
|
||||
const created = await createUploadCase(gateway, "alt-text-publishable", "대체 텍스트 게시 가능");
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${created.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={created.id} />
|
||||
</StudioProvider>
|
||||
@@ -1447,13 +1500,13 @@ test("an asset uploaded with alt text inserts that alt and the document validate
|
||||
test("a decorative upload inserts an empty alt and the document is still publishable", async () => {
|
||||
const user = userEvent.setup();
|
||||
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const gateway = installed.createStudioGateway();
|
||||
const assetGateway = installed.createStudioAssetGateway();
|
||||
const gateway = studioGatewayFromApplication(installed.createStudioApplication());
|
||||
const assetGateway = studioAssetGatewayFromApplication(installed.createStudioApplication());
|
||||
const created = await createUploadCase(gateway, "decorative-publishable", "장식용 게시 가능");
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${created.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={created.id} />
|
||||
</StudioProvider>
|
||||
@@ -1704,7 +1757,7 @@ test("a Picker search never drops an already-inserted asset from the authored do
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${FIXTURE_IDS.redisAdapterCase}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={FIXTURE_IDS.redisAdapterCase} />
|
||||
</StudioProvider>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { setupServer } from "msw/node";
|
||||
|
||||
import { createAssetUploadTransport } from "../../../src/features/tech-log/adapters/http/asset-upload-transport.ts";
|
||||
import { createHttpStudioAssetGateway } from "../../../src/features/tech-log/adapters/http/http-studio-asset-gateway.ts";
|
||||
import { createTechLogHttpBinding } from "../../../src/features/tech-log/adapters/http/tech-log-http-binding.ts";
|
||||
import { createCsrfTokenProvider } from "../../../src/features/tech-log/adapters/http/studio-session-csrf.ts";
|
||||
import { isStudioGatewayError } from "../../../src/features/tech-log/application/ports/studio-gateway-error.ts";
|
||||
|
||||
@@ -252,11 +253,11 @@ test("an uncontracted 401 body still invalidates the cached CSRF token end to en
|
||||
},
|
||||
});
|
||||
const gateway = createHttpStudioAssetGateway({
|
||||
operations: {
|
||||
http: createTechLogHttpBinding({
|
||||
async execute() {
|
||||
throw new Error("not used by this test");
|
||||
},
|
||||
},
|
||||
}),
|
||||
csrf,
|
||||
upload: transport(),
|
||||
});
|
||||
|
||||
@@ -17,9 +17,7 @@ type TechLogFeatureInputExposesNoMissingOrAdditionalKeys = Assert<
|
||||
Equal<
|
||||
keyof ApplicationFeatureInputs["tech-log"],
|
||||
| "publicContent"
|
||||
| "createStudioGateway"
|
||||
| "createStudioAssetGateway"
|
||||
| "createManagementGateway"
|
||||
| "createStudioApplication"
|
||||
>
|
||||
>;
|
||||
type TechLogFeatureInputRegistryValueMatchesFeatureContract = Assert<
|
||||
|
||||
@@ -42,10 +42,10 @@ test("게이트웨이가 두 목록을 각자의 연산으로 부른다", async
|
||||
|
||||
const called: { operationId: string; input: unknown }[] = [];
|
||||
const gateway = createHttpManagementGateway({
|
||||
operations: {
|
||||
http: {
|
||||
execute: (operationId: string, input: unknown) => {
|
||||
called.push({ operationId, input });
|
||||
return Promise.resolve({ kind: "SUCCESS", value: { items: [] } });
|
||||
return Promise.resolve({ ok: true as const, value: { items: [] } });
|
||||
},
|
||||
},
|
||||
} as never);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtur
|
||||
import { isStudioGatewayError } from "../../../src/features/tech-log/application/ports/studio-gateway-error.ts";
|
||||
import { TECH_LOG_STUDIO_CONTRIBUTION } from "../../../src/features/tech-log/contracts/tech-log-studio-contract-contribution.ts";
|
||||
import { MUTATION_INTENT_BOUNDS } from "../../../src/contracts/mutation-intent.ts";
|
||||
import { createFailure, kindForStatus } from "../../../src/contracts/errors.ts";
|
||||
|
||||
const { handlers } = createTechLogStudioHandlers();
|
||||
const server = setupServer(...handlers);
|
||||
@@ -87,18 +88,27 @@ async function realDependencies() {
|
||||
if (contract.acceptedStatuses.includes(response.status)) {
|
||||
const value =
|
||||
contract.responseBody === "NONE" ? null : await response.json();
|
||||
return { kind: "SUCCESS" as const, value, effect: "APPLIED_CONFIRMED" as const };
|
||||
return { ok: true as const, value };
|
||||
}
|
||||
const problem = (await response.json()) as {
|
||||
code?: string;
|
||||
detail?: string;
|
||||
title?: string;
|
||||
error?: { code?: string; message?: string };
|
||||
};
|
||||
return {
|
||||
kind: "PROBLEM" as const,
|
||||
problem: await response.json(),
|
||||
metadata: { status: response.status },
|
||||
effect: "NOT_APPLIED" as const,
|
||||
ok: false as const,
|
||||
error: createFailure(kindForStatus(response.status), operationId, 0, {
|
||||
code: problem.code ?? problem.error?.code ?? problem.title ?? "CONTRACT_PROBLEM",
|
||||
detail: problem.detail ?? problem.error?.message,
|
||||
httpStatus: response.status,
|
||||
effect: "NOT_APPLIED",
|
||||
}),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return { operations } as never;
|
||||
return { http: operations } as never;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,24 +55,50 @@ test("게이트웨이가 종류마다 그 종류의 연산을 부른다", async
|
||||
"../../../src/features/tech-log/adapters/http/http-management-gateway.ts"
|
||||
);
|
||||
|
||||
const called: string[] = [];
|
||||
const called: Array<{
|
||||
operationId: string;
|
||||
idempotencyKey: string | undefined;
|
||||
}> = [];
|
||||
const gateway = createHttpManagementGateway({
|
||||
operations: {
|
||||
execute: (operationId: string) => {
|
||||
called.push(operationId);
|
||||
return Promise.resolve({ kind: "SUCCESS", value: undefined });
|
||||
http: {
|
||||
execute: (
|
||||
operationId: string,
|
||||
_input: unknown,
|
||||
context: Readonly<{
|
||||
intent?: Readonly<{ idempotencyKey?: string }>;
|
||||
}>,
|
||||
) => {
|
||||
called.push({
|
||||
operationId,
|
||||
idempotencyKey: context.intent?.idempotencyKey,
|
||||
});
|
||||
return Promise.resolve({ ok: true as const, value: undefined });
|
||||
},
|
||||
},
|
||||
} as never);
|
||||
|
||||
for (const kind of ["CASE", "REFERENCE", "QUESTION", "CONCEPT"] as const) {
|
||||
await gateway.deleteDocument(kind, "11111111-1111-4111-8111-111111111111", 1);
|
||||
await gateway.deleteDocument(
|
||||
kind,
|
||||
"11111111-1111-4111-8111-111111111111",
|
||||
1,
|
||||
{ idempotencyKey: `delete-${kind.toLowerCase()}-test` },
|
||||
);
|
||||
}
|
||||
|
||||
assert.deepEqual(called, [
|
||||
assert.deepEqual(called.map((entry) => entry.operationId), [
|
||||
"deleteCaseDraft",
|
||||
"deleteReferenceDraft",
|
||||
"deleteQuestion",
|
||||
"deleteConceptDraft",
|
||||
]);
|
||||
assert.deepEqual(
|
||||
called.map((entry) => entry.idempotencyKey),
|
||||
[
|
||||
"delete-case-test",
|
||||
"delete-reference-test",
|
||||
"delete-question-test",
|
||||
"delete-concept-test",
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtur
|
||||
import { createMockStudioGateway } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
|
||||
|
||||
import { studioAssetGatewayFromApplication, studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
// The staleness guards in `createPreview`/`publishDocument` compare the
|
||||
// validation's `dependencyRevision` against `dependencies.dependencyRevision
|
||||
// .current()`. While that default was a literal constant, it could not
|
||||
@@ -73,8 +74,8 @@ function expectStale(error: unknown) {
|
||||
// gateways.
|
||||
test("an Asset that turns non-decorative between validate and preview makes the validation stale", async () => {
|
||||
const { input } = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT);
|
||||
const assetGateway = input.createStudioAssetGateway();
|
||||
const gateway = input.createStudioGateway();
|
||||
const assetGateway = studioAssetGatewayFromApplication(input.createStudioApplication());
|
||||
const gateway = studioGatewayFromApplication(input.createStudioApplication());
|
||||
|
||||
const uploaded = await assetGateway.uploadAsset(
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { techLogNavigation } from "../../../src/features/tech-log/presentation/tech-log-navigation.ts";
|
||||
import { TECH_LOG_ROUTE_REGISTRY } from "../../../src/features/tech-log/contracts/tech-log-route-contract.ts";
|
||||
import { TECH_LOG_MESSAGE_CATALOGS } from "../../../src/features/tech-log/contracts/tech-log-message-catalog.ts";
|
||||
|
||||
/**
|
||||
* The headers used to repeat the route contract's navigation facts in their own
|
||||
@@ -12,7 +13,10 @@ import { TECH_LOG_ROUTE_REGISTRY } from "../../../src/features/tech-log/contract
|
||||
describe("TechLog navigation derivation", () => {
|
||||
it("derives the public menu in contract order", () => {
|
||||
expect(
|
||||
techLogNavigation("PUBLIC").map((entry) => [entry.label, entry.path]),
|
||||
techLogNavigation("PUBLIC").map((entry) => [
|
||||
TECH_LOG_MESSAGE_CATALOGS["ko-KR"][entry.messageKey],
|
||||
entry.path,
|
||||
]),
|
||||
).toEqual([
|
||||
["탐색", "/explore"],
|
||||
["주제", "/topics"],
|
||||
@@ -23,7 +27,10 @@ describe("TechLog navigation derivation", () => {
|
||||
|
||||
it("derives the studio menu in contract order", () => {
|
||||
expect(
|
||||
techLogNavigation("STUDIO").map((entry) => [entry.label, entry.path]),
|
||||
techLogNavigation("STUDIO").map((entry) => [
|
||||
TECH_LOG_MESSAGE_CATALOGS["ko-KR"][entry.messageKey],
|
||||
entry.path,
|
||||
]),
|
||||
).toEqual([
|
||||
["작업본", "/studio/documents"],
|
||||
["게시 기록", "/studio/publications"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { test } from "vitest";
|
||||
|
||||
import type { components } from "../../../src/features/tech-log/contracts/public/generated.ts";
|
||||
import { createHttpPublicContentGateway } from "../../../src/features/tech-log/adapters/http/http-public-content-gateway.ts";
|
||||
import { createTechLogHttpBinding } from "../../../src/features/tech-log/adapters/http/tech-log-http-binding.ts";
|
||||
|
||||
type QuestionDetail = components["schemas"]["QuestionDetailResponse"];
|
||||
|
||||
@@ -21,15 +22,15 @@ type QuestionDetail = components["schemas"]["QuestionDetailResponse"];
|
||||
*/
|
||||
function gatewayReturning(value: unknown) {
|
||||
return createHttpPublicContentGateway({
|
||||
operations: {
|
||||
http: createTechLogHttpBinding({
|
||||
execute: () =>
|
||||
Promise.resolve({
|
||||
kind: "SUCCESS" as const,
|
||||
value,
|
||||
value: value as never,
|
||||
metadata: { status: 200 },
|
||||
effect: "NOT_APPLICABLE" as const,
|
||||
}),
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,9 @@ describe("TechLog Public shell", () => {
|
||||
const dialog = screen.getByRole("dialog", { name: "TechLog 검색" });
|
||||
const input = within(dialog).getByRole("searchbox", { name: "검색어" });
|
||||
expect(dialog).toHaveAttribute("open");
|
||||
expect(dialog).toHaveAttribute("aria-labelledby", `${dialog.id}-title`);
|
||||
const labelledBy = dialog.getAttribute("aria-labelledby");
|
||||
expect(labelledBy).toBeTruthy();
|
||||
expect(document.getElementById(labelledBy!)).toHaveTextContent("TechLog 검색");
|
||||
expect(input).toHaveFocus();
|
||||
|
||||
await user.keyboard("{Escape}");
|
||||
|
||||
@@ -171,15 +171,25 @@ describe("TechLog route boundary contract", () => {
|
||||
["TECH_LOG_STUDIO_RELEASES", "STUDIO", "릴리즈", 50],
|
||||
]);
|
||||
|
||||
const routeMessageCount = Object.keys(TECH_LOG_ROUTE_REGISTRY).length * 2;
|
||||
for (const locale of ["ko-KR", "en-US"] as const) {
|
||||
const catalog: Readonly<Record<string, string>> =
|
||||
TECH_LOG_MESSAGE_CATALOGS[locale];
|
||||
expect(Object.keys(catalog)).toHaveLength(74);
|
||||
for (const [routeId, title] of Object.entries(expectedTitles)) {
|
||||
expect(catalog[`route.${routeId}.title`]).toBe(title);
|
||||
expect(catalog[`route.${routeId}.navigation`]).toBe(title);
|
||||
const routeMessages = Object.entries(catalog).filter(([key]) =>
|
||||
key.startsWith("route."),
|
||||
);
|
||||
expect(routeMessages).toHaveLength(routeMessageCount);
|
||||
for (const routeId of Object.keys(TECH_LOG_ROUTE_REGISTRY)) {
|
||||
expect(catalog[`route.${routeId}.title`]).toBeTruthy();
|
||||
expect(catalog[`route.${routeId}.navigation`]).toBeTruthy();
|
||||
}
|
||||
}
|
||||
|
||||
const koreanCatalog: Readonly<Record<string, string>> =
|
||||
TECH_LOG_MESSAGE_CATALOGS["ko-KR"];
|
||||
for (const [routeId, title] of Object.entries(expectedTitles)) {
|
||||
expect(koreanCatalog[`route.${routeId}.title`]).toBe(title);
|
||||
}
|
||||
});
|
||||
|
||||
it("normalizes source search semantics and rejects empty path parameters", () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { createCsrfTokenProvider } from "../../../src/features/tech-log/adapters
|
||||
import type { TechLogFeatureInput } from "../../../src/features/tech-log/application/tech-log-feature-input.ts";
|
||||
import type { WorkingCopy } from "../../../src/features/tech-log/contracts/studio/contract.ts";
|
||||
|
||||
import { studioAssetGatewayFromApplication, studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
type Equal<Left, Right> =
|
||||
(<Value>() => Value extends Left ? 1 : 2) extends <Value>() =>
|
||||
Value extends Right ? 1 : 2
|
||||
@@ -71,11 +72,6 @@ function installedInputs(
|
||||
throw new Error("platform executor is not used by composition tests");
|
||||
},
|
||||
},
|
||||
contractOperations: {
|
||||
async execute() {
|
||||
throw new Error("reference executor is not used by composition tests");
|
||||
},
|
||||
},
|
||||
apiBaseUrl: "http://composition.test/",
|
||||
requestTimeoutMs: 10_000,
|
||||
csrf: createCsrfTokenProvider({
|
||||
@@ -91,9 +87,7 @@ test("installs TechLog beside the retained reference feature through application
|
||||
|
||||
assert.deepEqual(Object.keys(installed), ["reference-feature", "tech-log"]);
|
||||
assert.deepEqual(Object.keys(installed["tech-log"]).sort(), [
|
||||
"createManagementGateway",
|
||||
"createStudioAssetGateway",
|
||||
"createStudioGateway",
|
||||
"createStudioApplication",
|
||||
"publicContent",
|
||||
]);
|
||||
assert.equal(Object.isFrozen(installed), true);
|
||||
@@ -106,8 +100,8 @@ test("installs TechLog beside the retained reference feature through application
|
||||
});
|
||||
|
||||
test("selects the mock gateway by default and the HTTP gateway when switched", async () => {
|
||||
const mockGateway = installedInputs("MOCK")["tech-log"].createStudioGateway();
|
||||
const httpGateway = installedInputs("HTTP")["tech-log"].createStudioGateway();
|
||||
const mockGateway = studioGatewayFromApplication(installedInputs("MOCK")["tech-log"].createStudioApplication());
|
||||
const httpGateway = studioGatewayFromApplication(installedInputs("HTTP")["tech-log"].createStudioApplication());
|
||||
|
||||
// The mock reads an in-memory fixture immediately. HTTP defers to the
|
||||
// (here, throwing) contract executor, so it rejects instead.
|
||||
@@ -117,8 +111,8 @@ test("selects the mock gateway by default and the HTTP gateway when switched", a
|
||||
|
||||
test("each createStudioGateway call owns an isolated mutable Studio session", async () => {
|
||||
const installed = installedInputs();
|
||||
const first = installed["tech-log"].createStudioGateway();
|
||||
const second = installed["tech-log"].createStudioGateway();
|
||||
const first = studioGatewayFromApplication(installed["tech-log"].createStudioApplication());
|
||||
const second = studioGatewayFromApplication(installed["tech-log"].createStudioApplication());
|
||||
|
||||
assert.notEqual(first, second);
|
||||
const firstBefore = await first.getDocument(FIXTURE_IDS.fetchJoinCase);
|
||||
@@ -156,7 +150,7 @@ test("each createStudioGateway call owns an isolated mutable Studio session", as
|
||||
test("each Studio session gets its own asset gateway instance", () => {
|
||||
const installed = installedInputs("HTTP");
|
||||
assert.notEqual(
|
||||
installed["tech-log"].createStudioAssetGateway(),
|
||||
installed["tech-log"].createStudioAssetGateway(),
|
||||
studioAssetGatewayFromApplication(installed["tech-log"].createStudioApplication()),
|
||||
studioAssetGatewayFromApplication(installed["tech-log"].createStudioApplication()),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
createTechLogStudioApplication,
|
||||
} from "../../../src/features/tech-log/application/studio-application.ts";
|
||||
import type { ManagementGateway } from "../../../src/features/tech-log/application/ports/management-gateway.ts";
|
||||
import type { StudioAssetGateway } from "../../../src/features/tech-log/application/ports/studio-asset-gateway.ts";
|
||||
import type { StudioGateway } from "../../../src/features/tech-log/application/ports/studio-gateway.ts";
|
||||
|
||||
describe("TechLog Studio application boundary", () => {
|
||||
it("exposes application capabilities without exposing outbound gateway objects", async () => {
|
||||
const dashboard = { marker: "dashboard" };
|
||||
const saved = { marker: "saved" };
|
||||
const assetPage = { marker: "asset-page" };
|
||||
const topics = [{ marker: "topic" }];
|
||||
|
||||
const studio = {
|
||||
getDashboard: vi.fn(async () => dashboard),
|
||||
saveDocument: vi.fn(async () => saved),
|
||||
} as unknown as StudioGateway;
|
||||
const assets = {
|
||||
listAssets: vi.fn(async () => assetPage),
|
||||
} as unknown as StudioAssetGateway;
|
||||
const management = {
|
||||
listTopics: vi.fn(async () => topics),
|
||||
} as unknown as ManagementGateway;
|
||||
|
||||
const application = createTechLogStudioApplication({
|
||||
studio,
|
||||
assets,
|
||||
management,
|
||||
});
|
||||
|
||||
expect("documents" in application).toBe(false);
|
||||
expect("assets" in application).toBe(false);
|
||||
expect("management" in application).toBe(false);
|
||||
|
||||
await expect(application.workspaceQueries.getDashboard()).resolves.toBe(dashboard);
|
||||
await expect(
|
||||
application.documentCommands.saveDocument(
|
||||
"document-1",
|
||||
{} as Parameters<StudioGateway["saveDocument"]>[1],
|
||||
{ idempotencyKey: "save-1" },
|
||||
),
|
||||
).resolves.toBe(saved);
|
||||
await expect(application.assetQueries.listAssets({})).resolves.toBe(assetPage);
|
||||
await expect(application.managementQueries.listTopics()).resolves.toBe(topics);
|
||||
|
||||
expect(studio.getDashboard).toHaveBeenCalledTimes(1);
|
||||
expect(studio.saveDocument).toHaveBeenCalledWith(
|
||||
"document-1",
|
||||
{},
|
||||
{ idempotencyKey: "save-1" },
|
||||
);
|
||||
expect(assets.listAssets).toHaveBeenCalledWith({}, undefined);
|
||||
expect(management.listTopics).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
isStudioGatewayError,
|
||||
StudioGatewayError,
|
||||
} from "../../../src/features/tech-log/application/ports/studio-gateway-error.ts";
|
||||
import { createFailure } from "../../../src/contracts/errors.ts";
|
||||
|
||||
const READY_ASSET = {
|
||||
id: "11111111-1111-4111-8111-111111111111",
|
||||
@@ -32,7 +33,7 @@ function deps(outcomes: Record<string, unknown>) {
|
||||
return {
|
||||
calls,
|
||||
dependencies: {
|
||||
operations: {
|
||||
http: {
|
||||
async execute(operationId: string, input: unknown) {
|
||||
calls.push({ operationId, input });
|
||||
const outcome = outcomes[operationId];
|
||||
@@ -57,9 +58,8 @@ function deps(outcomes: Record<string, unknown>) {
|
||||
test("lists assets through the canonical operation", async () => {
|
||||
const { calls, dependencies } = deps({
|
||||
listStudioAssets: {
|
||||
kind: "SUCCESS",
|
||||
ok: true,
|
||||
value: { items: [READY_ASSET], nextCursor: null },
|
||||
effect: "APPLIED_CONFIRMED",
|
||||
},
|
||||
});
|
||||
const gateway = createHttpStudioAssetGateway(dependencies as never);
|
||||
@@ -83,9 +83,8 @@ test("gets a single asset detail through the canonical operation", async () => {
|
||||
};
|
||||
const { calls, dependencies } = deps({
|
||||
getStudioAsset: {
|
||||
kind: "SUCCESS",
|
||||
ok: true,
|
||||
value: detail,
|
||||
effect: "APPLIED_CONFIRMED",
|
||||
},
|
||||
});
|
||||
const gateway = createHttpStudioAssetGateway(dependencies as never);
|
||||
@@ -209,16 +208,13 @@ test("does not invalidate the cached CSRF token for an unrelated upload failure"
|
||||
test("surfaces ASSET_IN_USE from a rejected delete", async () => {
|
||||
const { dependencies } = deps({
|
||||
deleteStudioAsset: {
|
||||
kind: "PROBLEM",
|
||||
problem: {
|
||||
type: "https://techlog.local/problems/asset-in-use",
|
||||
title: "ASSET_IN_USE",
|
||||
status: 409,
|
||||
detail: "사용 중인 Asset은 삭제할 수 없습니다.",
|
||||
ok: false,
|
||||
error: createFailure("CONFLICT", "deleteStudioAsset", 0, {
|
||||
code: "ASSET_IN_USE",
|
||||
},
|
||||
metadata: { status: 409 },
|
||||
effect: "NOT_APPLIED",
|
||||
detail: "사용 중인 Asset은 삭제할 수 없습니다.",
|
||||
httpStatus: 409,
|
||||
effect: "NOT_APPLIED",
|
||||
}),
|
||||
},
|
||||
});
|
||||
const gateway = createHttpStudioAssetGateway(dependencies as never);
|
||||
@@ -236,9 +232,8 @@ test("surfaces ASSET_IN_USE from a rejected delete", async () => {
|
||||
test("sends expectedVersion when updating metadata", async () => {
|
||||
const { calls, dependencies } = deps({
|
||||
updateStudioAsset: {
|
||||
kind: "SUCCESS",
|
||||
ok: true,
|
||||
value: { ...READY_ASSET, version: 2, decorative: true, altText: null },
|
||||
effect: "APPLIED_CONFIRMED",
|
||||
},
|
||||
});
|
||||
const gateway = createHttpStudioAssetGateway(dependencies as never);
|
||||
|
||||
@@ -13,9 +13,16 @@ import {
|
||||
attachStudioSessionCredentials,
|
||||
invalidateTechLogCsrfOnOutcome,
|
||||
} from "../../../src/features/tech-log/adapters/http/studio-session-credentials.ts";
|
||||
import type { StudioOperationExecutor } from "../../../src/features/tech-log/adapters/http/http-studio-gateway.ts";
|
||||
import { TECH_LOG_STUDIO_CONTRIBUTION } from "../../../src/features/tech-log/contracts/tech-log-studio-contract-contribution.ts";
|
||||
import { REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION } from "../../../src/features/reference-feature/contracts/reference-feature-contract-contribution.ts";
|
||||
import type { InstalledHttpOperationExecutor } from "../../../src/adapters/http/index.ts";
|
||||
import { createTechLogHttpBinding } from "../../../src/features/tech-log/adapters/http/tech-log-http-binding.ts";
|
||||
import {
|
||||
TECH_LOG_STUDIO_CONTRIBUTION,
|
||||
TECH_LOG_STUDIO_SESSION_CONTRACT,
|
||||
} from "../../../src/features/tech-log/contracts/tech-log-studio-contract-contribution.ts";
|
||||
import {
|
||||
LIST_REFERENCE_RESOURCES_CONTRACT,
|
||||
REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION,
|
||||
} from "../../../src/features/reference-feature/contracts/reference-feature-contract-contribution.ts";
|
||||
|
||||
/**
|
||||
* I1 (Task 7 fix round 1). C1 was a self-referential CSRF bootstrap cycle
|
||||
@@ -72,16 +79,12 @@ function scopeSnapshot() {
|
||||
* afterward.
|
||||
*/
|
||||
function composeStudioRuntime() {
|
||||
// Both contributions, exactly as `installed-contract-contributions.ts`
|
||||
// composes them: `contractOperations.execute` is one executor shared by
|
||||
// every installed feature, so a reference-feature operation's outcome
|
||||
// travels through the same code path a Studio operation's does.
|
||||
const composed = composeContractContributions([
|
||||
TECH_LOG_STUDIO_CONTRIBUTION,
|
||||
REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION,
|
||||
]);
|
||||
|
||||
let contractOperations: StudioOperationExecutor = Object.freeze({
|
||||
let contractOperations: InstalledHttpOperationExecutor = Object.freeze({
|
||||
async execute() {
|
||||
throw new Error("contractOperations used before assignment");
|
||||
},
|
||||
@@ -90,7 +93,7 @@ function composeStudioRuntime() {
|
||||
const techLogCsrf = createCsrfTokenProvider({
|
||||
async execute(options) {
|
||||
const outcome = await contractOperations.execute(
|
||||
"getStudioSession",
|
||||
TECH_LOG_STUDIO_SESSION_CONTRACT,
|
||||
{},
|
||||
{
|
||||
routeId: "TECH_LOG_STUDIO",
|
||||
@@ -100,13 +103,19 @@ function composeStudioRuntime() {
|
||||
if (outcome.kind !== "SUCCESS") {
|
||||
throw new Error("studio session is unavailable");
|
||||
}
|
||||
const value = outcome.value as { csrfToken: string; csrfHeaderName: string };
|
||||
return { csrfToken: value.csrfToken, csrfHeaderName: value.csrfHeaderName };
|
||||
const value = outcome.value as {
|
||||
csrfToken: string;
|
||||
csrfHeaderName: string;
|
||||
};
|
||||
return {
|
||||
csrfToken: value.csrfToken,
|
||||
csrfHeaderName: value.csrfHeaderName,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const contractHttp = createContractHttpExecutor({
|
||||
baseUrl: `${BASE}/`,
|
||||
baseUrl: BASE + "/",
|
||||
maxRetryAttempts: 0,
|
||||
authProfiles: INSTALLED_REST_AUTH_PROFILES,
|
||||
async attachCredentials(operation, authContext) {
|
||||
@@ -115,9 +124,6 @@ function composeStudioRuntime() {
|
||||
authContext,
|
||||
techLogCsrf,
|
||||
);
|
||||
// `attachStudioSessionCredentials` returns null for a non-Studio
|
||||
// profile so the caller falls through to its own credential logic --
|
||||
// the bearer path in the composition root, this stand-in here.
|
||||
return (
|
||||
outcome ??
|
||||
Object.freeze({
|
||||
@@ -129,30 +135,37 @@ function composeStudioRuntime() {
|
||||
});
|
||||
|
||||
contractOperations = Object.freeze({
|
||||
async execute(operationId, input, executionContext) {
|
||||
const operation = composed.httpByOperationId.get(operationId);
|
||||
if (!operation) throw new Error(`no such operation: ${operationId}`);
|
||||
const outcome = await contractHttp.execute(operation, input, {
|
||||
routeId: executionContext.routeId,
|
||||
scope: scopeSnapshot(),
|
||||
...(executionContext.signal ? { signal: executionContext.signal } : {}),
|
||||
...(executionContext.intent ? { intent: executionContext.intent } : {}),
|
||||
});
|
||||
// Fix round 2, item 1. Same production call as
|
||||
// `bootstrap/runtime-adapters.ts`'s `contractOperations.execute` — not
|
||||
// a reimplementation of it. Final fix wave item 8 added the auth
|
||||
// profile: this executor serves every installed feature, so the call
|
||||
// has to be told which one produced the outcome.
|
||||
async execute(operation, input, executionContext) {
|
||||
const installed = composed.httpByOperationId.get(
|
||||
operation.contract.operationId,
|
||||
);
|
||||
if (!installed) {
|
||||
throw new Error("no such operation: " + operation.contract.operationId);
|
||||
}
|
||||
const outcome = await contractHttp.execute(
|
||||
installed as typeof operation,
|
||||
input,
|
||||
{
|
||||
routeId: executionContext.routeId,
|
||||
scope: scopeSnapshot(),
|
||||
...(executionContext.signal ? { signal: executionContext.signal } : {}),
|
||||
...(executionContext.intent ? { intent: executionContext.intent } : {}),
|
||||
},
|
||||
);
|
||||
invalidateTechLogCsrfOnOutcome(
|
||||
outcome.kind,
|
||||
operation.frontend.authProfileId,
|
||||
installed.frontend.authProfileId,
|
||||
techLogCsrf,
|
||||
);
|
||||
return outcome;
|
||||
},
|
||||
});
|
||||
|
||||
return { contractOperations, techLogCsrf };
|
||||
return {
|
||||
contractOperations,
|
||||
techLogHttp: createTechLogHttpBinding(contractOperations),
|
||||
techLogCsrf,
|
||||
};
|
||||
}
|
||||
|
||||
test(
|
||||
@@ -193,23 +206,22 @@ test(
|
||||
}),
|
||||
);
|
||||
|
||||
const { contractOperations, techLogCsrf } = composeStudioRuntime();
|
||||
const { techLogHttp, techLogCsrf } = composeStudioRuntime();
|
||||
|
||||
// JSON path: a plain read that uses `TECH_LOG_STUDIO_SESSION` and
|
||||
// therefore requires the CSRF header — this is what C1 made impossible
|
||||
// (unbounded recursion, zero dispatched requests).
|
||||
const dashboardOutcome = await contractOperations.execute(
|
||||
const dashboardOutcome = await techLogHttp.execute(
|
||||
"getStudioDashboard",
|
||||
{},
|
||||
{ routeId: "TECH_LOG_STUDIO" },
|
||||
);
|
||||
assert.equal(dashboardOutcome.kind, "SUCCESS");
|
||||
assert.equal(dashboardOutcome.ok, true);
|
||||
assert.equal(jsonRequestHeader, "csrf-token-1");
|
||||
|
||||
// Multipart path: bypasses `contractOperations` entirely but reads the
|
||||
// token from the same `techLogCsrf` instance.
|
||||
const assetGateway = createHttpStudioAssetGateway({
|
||||
operations: contractOperations,
|
||||
http: techLogHttp,
|
||||
csrf: techLogCsrf,
|
||||
upload: createAssetUploadTransport({ baseUrl: `${BASE}/`, timeoutMs: 10_000 }),
|
||||
});
|
||||
@@ -268,22 +280,16 @@ test(
|
||||
}),
|
||||
);
|
||||
|
||||
const { contractOperations } = composeStudioRuntime();
|
||||
const { techLogHttp } = composeStudioRuntime();
|
||||
|
||||
const first = await contractOperations.execute(
|
||||
"getStudioDashboard",
|
||||
{},
|
||||
{ routeId: "TECH_LOG_STUDIO" },
|
||||
);
|
||||
assert.equal(first.kind, "FORBIDDEN");
|
||||
const first = await techLogHttp.execute("getStudioDashboard", {});
|
||||
assert.equal(first.ok, false);
|
||||
if (first.ok) throw new Error("expected dashboard request to fail");
|
||||
assert.equal(first.error.kind, "FORBIDDEN");
|
||||
assert.equal(dashboardHeaders[0], "csrf-token-1");
|
||||
|
||||
const second = await contractOperations.execute(
|
||||
"getStudioDashboard",
|
||||
{},
|
||||
{ routeId: "TECH_LOG_STUDIO" },
|
||||
);
|
||||
assert.equal(second.kind, "SUCCESS");
|
||||
const second = await techLogHttp.execute("getStudioDashboard", {});
|
||||
assert.equal(second.ok, true);
|
||||
assert.equal(dashboardHeaders[1], "csrf-token-2");
|
||||
|
||||
// Two fresh session fetches: the cache was discarded after the 403, not
|
||||
@@ -331,31 +337,23 @@ test(
|
||||
http.get(`${BASE}/api/reference-resources`, () => new HttpResponse(null, { status: 403 })),
|
||||
);
|
||||
|
||||
const { contractOperations } = composeStudioRuntime();
|
||||
const { contractOperations, techLogHttp } = composeStudioRuntime();
|
||||
|
||||
const first = await contractOperations.execute(
|
||||
"getStudioDashboard",
|
||||
{},
|
||||
{ routeId: "TECH_LOG_STUDIO" },
|
||||
);
|
||||
assert.equal(first.kind, "SUCCESS");
|
||||
const first = await techLogHttp.execute("getStudioDashboard", {});
|
||||
assert.equal(first.ok, true);
|
||||
assert.equal(dashboardHeaders[0], "csrf-token-1");
|
||||
|
||||
// Someone else's 403, on a feature that has nothing to do with the Studio
|
||||
// session.
|
||||
const rejected = await contractOperations.execute(
|
||||
"LIST_REFERENCE_RESOURCES",
|
||||
LIST_REFERENCE_RESOURCES_CONTRACT,
|
||||
{ limit: 10 },
|
||||
{ routeId: "REFERENCE_FEATURE" },
|
||||
);
|
||||
assert.equal(rejected.kind, "FORBIDDEN");
|
||||
|
||||
const second = await contractOperations.execute(
|
||||
"getStudioDashboard",
|
||||
{},
|
||||
{ routeId: "TECH_LOG_STUDIO" },
|
||||
);
|
||||
assert.equal(second.kind, "SUCCESS");
|
||||
const second = await techLogHttp.execute("getStudioDashboard", {});
|
||||
assert.equal(second.ok, true);
|
||||
assert.equal(dashboardHeaders[1], "csrf-token-1");
|
||||
assert.equal(sessionCalls, 1);
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { render as testingRender, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { ReactNode } from "react";
|
||||
import { MemoryRouter, useLocation, useNavigate } from "react-router-dom";
|
||||
@@ -13,8 +13,15 @@ import type { StudioGateway } from "../../../src/features/tech-log/application/p
|
||||
import type { WorkingCopyInput } from "../../../src/features/tech-log/contracts/studio/contract.ts";
|
||||
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
||||
import { NewDocumentForm } from "../../../src/features/tech-log/presentation/studio/components/new-document-form.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
type DecisionInput = Extract<WorkingCopyInput, { kind: "PROJECT_DECISION" }>;
|
||||
|
||||
@@ -54,7 +61,7 @@ function RouterStudioProvider({
|
||||
}: Readonly<{ gateway: StudioGateway; children: ReactNode }>) {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub}
|
||||
createGateway={() => gateway}
|
||||
navigate={(href) => { void navigate(href); }}
|
||||
@@ -71,7 +78,7 @@ function LocationProbe() {
|
||||
describe("TechLog Studio project decision authoring", () => {
|
||||
it("creates Decision as the fourth working-copy type", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
render(
|
||||
<MemoryRouter initialEntries={["/studio/documents/new"]}>
|
||||
<RouterStudioProvider gateway={gateway}>
|
||||
@@ -94,7 +101,7 @@ describe("TechLog Studio project decision authoring", () => {
|
||||
});
|
||||
|
||||
it("validates, previews, and publishes a project-scoped Decision", async () => {
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const document = await gateway.createDocument(decisionInput(), {
|
||||
idempotencyKey: "create-project-decision",
|
||||
});
|
||||
@@ -135,13 +142,13 @@ describe("TechLog Studio project decision authoring", () => {
|
||||
});
|
||||
|
||||
it("edits Decision fields on the single document surface without a preview mode", async () => {
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const document = await gateway.createDocument(decisionInput(), {
|
||||
idempotencyKey: "edit-project-decision",
|
||||
});
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${document.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway}>
|
||||
<DocumentEditorScreen documentId={document.id} />
|
||||
</StudioProvider>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { fireEvent, render as testingRender, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { ReactNode } from "react";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
@@ -11,23 +11,32 @@ import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-contex
|
||||
import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtures.ts";
|
||||
import type { StudioGateway } from "../../../src/features/tech-log/application/ports/studio-gateway.ts";
|
||||
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioAssetGatewayFromApplication, studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
function renderEditor(
|
||||
documentId: string,
|
||||
gateway: StudioGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
|
||||
gateway: StudioGateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication()),
|
||||
) {
|
||||
// CASE editors mount the Asset Picker (Task 10), which uses the throwing
|
||||
// `useStudioAssetGateway()` accessor -- a test harness that renders it must
|
||||
// supply `createAssetGateway`, the same as `StudioShell` always does.
|
||||
const assetGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT)
|
||||
.input.createStudioAssetGateway();
|
||||
const assetGateway = studioAssetGatewayFromApplication(
|
||||
createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT)
|
||||
.input.createStudioApplication(),
|
||||
);
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${documentId}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={documentId} />
|
||||
</StudioProvider>
|
||||
@@ -53,7 +62,7 @@ function markdownSource(container: HTMLElement): HTMLTextAreaElement {
|
||||
describe("TechLog Studio document editor", () => {
|
||||
it("loads the Case as one document surface and owns dirty state without an editor preview mode", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const calls = { save: 0, validate: 0, preview: 0, publish: 0 };
|
||||
const gateway = {
|
||||
...base,
|
||||
@@ -278,7 +287,7 @@ describe("TechLog Studio document editor", () => {
|
||||
);
|
||||
unknown.unmount();
|
||||
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const getDocument = vi
|
||||
.fn<StudioGateway["getDocument"]>()
|
||||
.mockRejectedValueOnce(new Error("offline"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { fireEvent, render as testingRender, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import {
|
||||
@@ -23,8 +23,15 @@ import type { WorkingCopyInput } from "../../../src/features/tech-log/contracts/
|
||||
import { PublicationEventPreviewScreen } from "../../../src/features/tech-log/presentation/studio/components/publication-event-preview-screen.tsx";
|
||||
import { PublicationList } from "../../../src/features/tech-log/presentation/studio/components/publication-list.tsx";
|
||||
import { PublishScreen } from "../../../src/features/tech-log/presentation/studio/components/publish-screen.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
const originalShowModal = HTMLDialogElement.prototype.showModal;
|
||||
const originalClose = HTMLDialogElement.prototype.close;
|
||||
@@ -81,12 +88,12 @@ afterEach(() => {
|
||||
|
||||
function renderInStudio(
|
||||
node: React.ReactNode,
|
||||
gateway: StudioGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
|
||||
gateway: StudioGateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication()),
|
||||
navigate: (href: string) => void = () => undefined,
|
||||
) {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={["/studio"]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} navigate={navigate}>
|
||||
{node}
|
||||
</StudioProvider>
|
||||
@@ -154,7 +161,7 @@ describe("TechLog Studio publication flow", () => {
|
||||
});
|
||||
|
||||
it("publishes a current warning preview only after every warning is acknowledged", async () => {
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const document = await warningReadyDocument(gateway);
|
||||
const destinations: string[] = [];
|
||||
renderInStudio(
|
||||
@@ -183,7 +190,7 @@ describe("TechLog Studio publication flow", () => {
|
||||
|
||||
it("keeps the publish pending state, preserves gateway command order, and retries with a new key", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const document = await warningReadyDocument(base);
|
||||
const first = deferred<never>();
|
||||
const calls: string[] = [];
|
||||
@@ -241,7 +248,7 @@ describe("TechLog Studio publication flow", () => {
|
||||
|
||||
it("filters publication events and recovers a failed history read", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const listPublications = vi
|
||||
.fn<StudioGateway["listPublications"]>()
|
||||
.mockRejectedValueOnce(new Error("offline"))
|
||||
@@ -267,7 +274,7 @@ describe("TechLog Studio publication flow", () => {
|
||||
|
||||
it("unpublishes only the selected current row after the source confirmation", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
renderInStudio(<PublicationList />, gateway);
|
||||
await user.click(
|
||||
await screen.findByRole("button", { name: /Redis Adapter.*게시 취소/ }),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { fireEvent, render as testingRender, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { useEffect } from "react";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
@@ -18,12 +18,19 @@ import type {
|
||||
} from "../../../src/features/tech-log/contracts/studio/contract.ts";
|
||||
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
||||
import { GuardedStudioLink } from "../../../src/features/tech-log/presentation/studio/components/guarded-studio-link.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import {
|
||||
useStudio,
|
||||
useStudioEditorSession,
|
||||
} from "../../../src/features/tech-log/presentation/studio/use-studio.ts";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioAssetGatewayFromApplication, studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
const originalShowModal = HTMLDialogElement.prototype.showModal;
|
||||
const originalClose = HTMLDialogElement.prototype.close;
|
||||
@@ -83,11 +90,13 @@ function renderEditor(documentId: string, gateway: StudioGateway) {
|
||||
// CASE editors mount the Asset Picker (Task 10), which uses the throwing
|
||||
// `useStudioAssetGateway()` accessor -- a test harness that renders it must
|
||||
// supply `createAssetGateway`, the same as `StudioShell` always does.
|
||||
const assetGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT)
|
||||
.input.createStudioAssetGateway();
|
||||
const assetGateway = studioAssetGatewayFromApplication(
|
||||
createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT)
|
||||
.input.createStudioApplication(),
|
||||
);
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${documentId}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
||||
<DocumentEditorScreen documentId={documentId} />
|
||||
<Announcement />
|
||||
@@ -112,7 +121,7 @@ async function getSavedDocument(gateway: StudioGateway) {
|
||||
describe("TechLog Studio save workflow", () => {
|
||||
it("shows save pending and success states and creates a fresh idempotency key for each command", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const first = deferred<void>();
|
||||
const keys: string[] = [];
|
||||
let calls = 0;
|
||||
@@ -152,7 +161,7 @@ describe("TechLog Studio save workflow", () => {
|
||||
|
||||
it("keeps the local draft and disables overwrite after a revision conflict", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
renderEditor(FIXTURE_IDS.conflictCase, gateway);
|
||||
|
||||
await user.clear(await screen.findByLabelText("제목"));
|
||||
@@ -169,7 +178,7 @@ describe("TechLog Studio save workflow", () => {
|
||||
|
||||
it("surfaces a save error and retries with a new user-command key without losing input", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const keys: string[] = [];
|
||||
const retryable = new StudioGatewayError({
|
||||
type: "https://techlog.local/problems/studio-unavailable",
|
||||
@@ -211,12 +220,12 @@ describe("TechLog Studio save workflow", () => {
|
||||
describe("TechLog Studio dirty navigation", () => {
|
||||
it("opens the source modal dialog, protects browser unload, and restores focus when staying", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const destinations: string[] = [];
|
||||
const saved = await getSavedDocument(gateway);
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${saved.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} navigate={(href) => destinations.push(href)}>
|
||||
<DirtyNavigationProbe saved={saved} />
|
||||
</StudioProvider>
|
||||
@@ -249,12 +258,12 @@ describe("TechLog Studio dirty navigation", () => {
|
||||
|
||||
it("discards the draft and follows the pending internal destination", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const destinations: string[] = [];
|
||||
const saved = await getSavedDocument(gateway);
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${saved.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} navigate={(href) => destinations.push(href)}>
|
||||
<DirtyNavigationProbe saved={saved} />
|
||||
</StudioProvider>
|
||||
@@ -273,7 +282,7 @@ describe("TechLog Studio dirty navigation", () => {
|
||||
|
||||
it("saves the draft before following the pending destination", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const pending = deferred<WorkingCopyDetail>();
|
||||
let key = "";
|
||||
const gateway = {
|
||||
@@ -287,7 +296,7 @@ describe("TechLog Studio dirty navigation", () => {
|
||||
const saved = await getSavedDocument(base);
|
||||
render(
|
||||
<MemoryRouter initialEntries={[`/studio/documents/${saved.id}/edit`]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} navigate={(href) => destinations.push(href)}>
|
||||
<DirtyNavigationProbe saved={saved} />
|
||||
</StudioProvider>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { fireEvent, render as testingRender, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { ReactNode } from "react";
|
||||
import { MemoryRouter, useLocation, useNavigate } from "react-router-dom";
|
||||
@@ -13,10 +13,17 @@ import type { DocumentPage } from "../../../src/features/tech-log/contracts/stud
|
||||
import { DocumentList } from "../../../src/features/tech-log/presentation/studio/components/document-list.tsx";
|
||||
import { NewDocumentForm } from "../../../src/features/tech-log/presentation/studio/components/new-document-form.tsx";
|
||||
import { StudioDashboard } from "../../../src/features/tech-log/presentation/studio/components/studio-dashboard.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx";
|
||||
import { createTestApplication } from "../../helpers/create-test-application.ts";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioGatewayFromApplication, withStudioGateway } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
@@ -30,7 +37,7 @@ function RouterStudioProvider({
|
||||
}: Readonly<{ children: ReactNode; gateway: StudioGateway }>) {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub}
|
||||
createGateway={() => gateway}
|
||||
navigate={(href) => {
|
||||
@@ -47,7 +54,13 @@ function renderScreen(children: ReactNode, gateway: StudioGateway) {
|
||||
return render(
|
||||
<ApplicationProvider
|
||||
application={createTestApplication({
|
||||
featureInputs: { "tech-log": { ...input, createStudioGateway: () => gateway } },
|
||||
featureInputs: {
|
||||
"tech-log": {
|
||||
...input,
|
||||
createStudioApplication: () =>
|
||||
withStudioGateway(input.createStudioApplication(), gateway),
|
||||
},
|
||||
},
|
||||
})}
|
||||
>
|
||||
<MemoryRouter initialEntries={["/studio"]}>
|
||||
@@ -59,7 +72,7 @@ function renderScreen(children: ReactNode, gateway: StudioGateway) {
|
||||
|
||||
describe("TechLog Studio index screens", () => {
|
||||
it("shows the source dashboard totals, workflow sections, status links, and sample rows", async () => {
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
|
||||
const { container } = renderScreen(<StudioDashboard />, gateway);
|
||||
|
||||
@@ -87,7 +100,7 @@ describe("TechLog Studio index screens", () => {
|
||||
});
|
||||
|
||||
it("searches and filters documents and renders the source empty state", async () => {
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
renderScreen(<DocumentList />, gateway);
|
||||
|
||||
expect(await screen.findByText("7개 중 7개 표시 중")).toBeVisible();
|
||||
@@ -102,7 +115,7 @@ describe("TechLog Studio index screens", () => {
|
||||
});
|
||||
|
||||
it("cancels an obsolete list request and moves between numbered pages", async () => {
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const all = await base.listDocuments({ limit: 20 });
|
||||
let obsoleteSignal: AbortSignal | undefined;
|
||||
const meta = (number: number) => ({
|
||||
@@ -135,7 +148,7 @@ describe("TechLog Studio index screens", () => {
|
||||
|
||||
it("shows a retry action after a list failure and recovers", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const recovered = await base.listDocuments({ limit: 20 });
|
||||
const gateway = {
|
||||
...base,
|
||||
@@ -154,7 +167,7 @@ describe("TechLog Studio index screens", () => {
|
||||
|
||||
it("creates the selected Question in the same session and redirects to its editor", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
renderScreen(
|
||||
<>
|
||||
<NewDocumentForm />
|
||||
|
||||
@@ -17,6 +17,7 @@ import { SessionProvider } from "../../../src/presentation/providers/session-pro
|
||||
import { createTestApplication } from "../../helpers/create-test-application.ts";
|
||||
import { renderWithQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
|
||||
import { studioGatewayFromApplication, withStudioGateway } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
async function renderStudio(
|
||||
@@ -59,7 +60,14 @@ async function renderStudio(
|
||||
notifyUnauthenticated: () => {},
|
||||
}),
|
||||
featureInputs: {
|
||||
"tech-log": { ...installed, createStudioGateway },
|
||||
"tech-log": {
|
||||
...installed,
|
||||
createStudioApplication: () =>
|
||||
withStudioGateway(
|
||||
installed.createStudioApplication(),
|
||||
createStudioGateway(),
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
const view = render(
|
||||
@@ -79,7 +87,7 @@ async function renderStudio(
|
||||
describe("TechLog Studio shell", () => {
|
||||
it("creates one application-provided gateway for child navigation and exposes the source header", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const createGateway = vi.fn(() => gateway);
|
||||
|
||||
const { container, router } = await renderStudio("/studio", createGateway);
|
||||
@@ -119,8 +127,8 @@ describe("TechLog Studio shell", () => {
|
||||
it("recreates the provider generation and cancels obsolete work after a persisted pageshow", async () => {
|
||||
const user = userEvent.setup();
|
||||
let firstSignal: AbortSignal | undefined;
|
||||
const first = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const second = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const first = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const second = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
vi.spyOn(first, "getDashboard").mockImplementation(({ signal } = {}) => {
|
||||
firstSignal = signal;
|
||||
return new Promise(() => {});
|
||||
@@ -146,7 +154,7 @@ describe("TechLog Studio shell", () => {
|
||||
|
||||
it("keeps unknown Studio routes inside the Studio shell without authentication UI", async () => {
|
||||
const createGateway = vi.fn(
|
||||
() => createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
|
||||
() => studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication()),
|
||||
);
|
||||
|
||||
await renderStudio("/studio/does-not-exist", createGateway);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { fireEvent, render as testingRender, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
@@ -12,8 +12,15 @@ import type { StudioGateway } from "../../../src/features/tech-log/application/p
|
||||
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
||||
import { PublicPreviewScreen } from "../../../src/features/tech-log/presentation/studio/components/public-preview-screen.tsx";
|
||||
import { ValidationScreen } from "../../../src/features/tech-log/presentation/studio/components/validation-screen.tsx";
|
||||
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
|
||||
import { studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
function render(ui: Parameters<typeof testingRender>[0]) {
|
||||
return testingRender(ui, { wrapper: TestQueryProviders });
|
||||
}
|
||||
|
||||
class NoopIntersectionObserver implements IntersectionObserver {
|
||||
readonly root = null;
|
||||
@@ -41,11 +48,11 @@ afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
function renderStudio(
|
||||
child: React.ReactNode,
|
||||
gateway: StudioGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
|
||||
gateway: StudioGateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication()),
|
||||
) {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={["/studio"]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway}>{child}</StudioProvider>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
@@ -54,7 +61,7 @@ function renderStudio(
|
||||
describe("TechLog Studio validation workflow", () => {
|
||||
it("reruns stale saved validation, reports exact freshness copy, and creates a new key per command", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const keys: string[] = [];
|
||||
const gateway = {
|
||||
...base,
|
||||
@@ -83,7 +90,7 @@ describe("TechLog Studio validation workflow", () => {
|
||||
|
||||
it("orders validation issues and links each JSON pointer to the affected editor field", async () => {
|
||||
const user = userEvent.setup();
|
||||
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const view = renderStudio(
|
||||
<ValidationScreen documentId={FIXTURE_IDS.edgeTokenQuestion} />,
|
||||
gateway,
|
||||
@@ -112,7 +119,7 @@ describe("TechLog Studio validation workflow", () => {
|
||||
});
|
||||
|
||||
it("aborts a route-obsolete validation read without surfacing an abort error", async () => {
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
let firstSignal: AbortSignal | undefined;
|
||||
const getDocument = vi
|
||||
.fn<StudioGateway["getDocument"]>()
|
||||
@@ -132,7 +139,7 @@ describe("TechLog Studio validation workflow", () => {
|
||||
|
||||
view.rerender(
|
||||
<MemoryRouter initialEntries={["/studio"]}>
|
||||
<StudioProvider
|
||||
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway}>
|
||||
<ValidationScreen documentId={FIXTURE_IDS.stateNonceReference} />
|
||||
</StudioProvider>
|
||||
@@ -148,7 +155,7 @@ describe("TechLog Studio validation workflow", () => {
|
||||
describe("TechLog Studio Public Preview workflow", () => {
|
||||
it("creates a missing preview, shows the current state, and renders the shared Public document", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const keys: string[] = [];
|
||||
const gateway = {
|
||||
...base,
|
||||
@@ -204,7 +211,7 @@ describe("TechLog Studio Public Preview workflow", () => {
|
||||
});
|
||||
|
||||
it("shows retryable preview-load errors and retries the read", async () => {
|
||||
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
||||
const base = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
||||
const getDocument = vi
|
||||
.fn<StudioGateway["getDocument"]>()
|
||||
.mockRejectedValueOnce(new Error("offline"))
|
||||
|
||||
@@ -20,13 +20,12 @@ let styleElement: HTMLStyleElement;
|
||||
|
||||
beforeAll(() => {
|
||||
styleElement = document.createElement("style");
|
||||
styleElement.textContent = readFileSync(
|
||||
resolve(
|
||||
process.cwd(),
|
||||
"src/features/tech-log/presentation/styles/globals.css",
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
styleElement.textContent = [
|
||||
"src/features/tech-log/presentation/styles/tech-log-theme.css",
|
||||
"src/features/tech-log/presentation/styles/globals.css",
|
||||
]
|
||||
.map((file) => readFileSync(resolve(process.cwd(), file), "utf8"))
|
||||
.join("\n");
|
||||
document.head.append(styleElement);
|
||||
});
|
||||
|
||||
@@ -75,17 +74,39 @@ describe("TechLog consumer-visible style contract", () => {
|
||||
const main = view.getByRole("main");
|
||||
const wordmark = view.getByRole("link", { name: "TechLog 홈" });
|
||||
|
||||
expect(rootStyle.getPropertyValue("--canvas")).toBe("#f7f7f5");
|
||||
expect(rootStyle.getPropertyValue("--ink")).toBe("#17181b");
|
||||
expect(rootStyle.getPropertyValue("--signal")).toBe("#3e5cc7");
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-surface")).toBe("#f7f7f5");
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-content")).toBe("#17181b");
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-action")).toBe("#3e5cc7");
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-success-content")).toBe("#176b5b");
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-success-surface")).toBe("#edf7f3");
|
||||
expect(rootStyle.getPropertyValue("--color-surface")).toBe(
|
||||
"var(--techlog-theme-surface)",
|
||||
);
|
||||
expect(rootStyle.getPropertyValue("--color-content")).toBe(
|
||||
"var(--techlog-theme-content)",
|
||||
);
|
||||
expect(rootStyle.getPropertyValue("--color-action")).toBe(
|
||||
"var(--techlog-theme-action)",
|
||||
);
|
||||
expect(rootStyle.getPropertyValue("--canvas")).toBe("var(--color-surface)");
|
||||
expect(rootStyle.getPropertyValue("--ink")).toBe("var(--color-content)");
|
||||
expect(rootStyle.getPropertyValue("--signal")).toBe("var(--color-action)");
|
||||
expect(rootStyle.getPropertyValue("--evidence")).toBe(
|
||||
"var(--color-success-content)",
|
||||
);
|
||||
expect(rootStyle.getPropertyValue("--shell")).toBe("1180px");
|
||||
// 장문 한글 본문은 약 720~760px의 읽기 단을 기준으로 한다. 코드·표·근거 자료도 같은 단을 따른다.
|
||||
expect(rootStyle.getPropertyValue("--body-copy")).toBe("47rem");
|
||||
expect(rootStyle.color).toBe("var(--ink)");
|
||||
expect(rootStyle.background).toBe("var(--canvas)");
|
||||
expect(bodyStyle.color).toBe("var(--ink)");
|
||||
expect(
|
||||
rootStyle
|
||||
.getPropertyValue("--techlog-palette-28b516db")
|
||||
.replaceAll(" ", ""),
|
||||
).toBe("rgba(255,255,255,0.45)");
|
||||
expect(bodyStyle.background).toContain(
|
||||
"linear-gradient(to bottom, rgba(255, 255, 255, 0.45), transparent 420px)",
|
||||
"linear-gradient(to bottom, var(--techlog-palette-28b516db), transparent 420px)",
|
||||
);
|
||||
expect(bodyStyle.background).toContain("var(--canvas)");
|
||||
expect(bodyStyle.fontFamily).toContain("Pretendard Variable");
|
||||
@@ -203,13 +224,13 @@ describe("TechLog consumer-visible style contract", () => {
|
||||
name: "TechLog 검색 열기",
|
||||
});
|
||||
const closeButton = view.container.querySelector<HTMLElement>(
|
||||
".dialog-close",
|
||||
".ui-dialog__close",
|
||||
);
|
||||
const searchField = view.container.querySelector<HTMLElement>(
|
||||
".search-field",
|
||||
);
|
||||
const dialogInner = view.container.querySelector<HTMLElement>(
|
||||
".search-dialog-inner",
|
||||
const dialogSurface = view.container.querySelector<HTMLElement>(
|
||||
".search-dialog .ui-dialog__surface",
|
||||
);
|
||||
|
||||
expect(getComputedStyle(wordmark).minHeight).toBe("44px");
|
||||
@@ -219,10 +240,14 @@ describe("TechLog consumer-visible style contract", () => {
|
||||
expect(getComputedStyle(closeButton!).minHeight).toBe("44px");
|
||||
expect(getComputedStyle(searchField!).minHeight).toBe("56px");
|
||||
expect(getComputedStyle(searchField!).marginTop).toBe("24px");
|
||||
expect(getComputedStyle(searchField!).backgroundColor).toBe(
|
||||
"rgb(255, 255, 255)",
|
||||
const rootStyle = getComputedStyle(document.documentElement);
|
||||
expect(rootStyle.getPropertyValue("--techlog-theme-surface-elevated")).toBe(
|
||||
"#ffffff",
|
||||
);
|
||||
expect(getComputedStyle(dialogInner!).padding).toBe("27px 28px 22px");
|
||||
expect(rootStyle.getPropertyValue("--color-surface-elevated")).toBe(
|
||||
"var(--techlog-theme-surface-elevated)",
|
||||
);
|
||||
expect(getComputedStyle(dialogSurface!).padding).toBe("27px 28px 22px");
|
||||
});
|
||||
|
||||
it("preserves footer spacing and fatal-action sizing", async () => {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
|
||||
import type { ManagementGateway } from "../../../src/features/tech-log/application/ports/management-gateway.ts";
|
||||
import type {
|
||||
ProjectIndexPage,
|
||||
TopicEdit,
|
||||
} from "../../../src/features/tech-log/contracts/management/contract.ts";
|
||||
import { TaxonomyManager } from "../../../src/features/tech-log/presentation/studio/components/taxonomy-manager.tsx";
|
||||
import { StudioProvider } from "../../helpers/studio-test-provider.tsx";
|
||||
import { DEFAULT_STUDIO_MOCK_NOW } from "../../../src/features/tech-log/adapters/mock/mock-studio-gateway.ts";
|
||||
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
||||
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
|
||||
import { TestQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
|
||||
import { studioGatewayFromApplication } from "../../helpers/studio-application-gateway-adapter.ts";
|
||||
describe("TechLog taxonomy projection", () => {
|
||||
it("renders project-topic structure from the project index without per-project detail requests", async () => {
|
||||
const topicId = "11111111-1111-4111-8111-111111111111";
|
||||
const projectId = "22222222-2222-4222-8222-222222222222";
|
||||
const listTopics = vi
|
||||
.fn<ManagementGateway["listTopics"]>()
|
||||
.mockResolvedValue([
|
||||
{
|
||||
id: topicId,
|
||||
name: "인증 경계",
|
||||
slug: "auth-boundary",
|
||||
status: "ACTIVE",
|
||||
} as TopicEdit,
|
||||
]);
|
||||
const listProjects = vi
|
||||
.fn<ManagementGateway["listProjects"]>()
|
||||
.mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
id: projectId,
|
||||
name: "Keycloak Patterns",
|
||||
slug: "keycloak-patterns",
|
||||
topicIds: [topicId],
|
||||
phase: "BUILDING",
|
||||
workflowStatus: "DRAFT",
|
||||
targetVisibility: "PRIVATE",
|
||||
updatedAt: "2026-09-21T00:00:00Z",
|
||||
version: 3,
|
||||
publication: {
|
||||
state: "NEVER_PUBLISHED",
|
||||
hasUnpublishedChanges: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
page: {
|
||||
number: 0,
|
||||
size: 50,
|
||||
totalElements: 1,
|
||||
totalPages: 1,
|
||||
hasPrevious: false,
|
||||
hasNext: false,
|
||||
},
|
||||
} as ProjectIndexPage);
|
||||
const getProject = vi
|
||||
.fn<ManagementGateway["getProject"]>()
|
||||
.mockRejectedValue(new Error("taxonomy must not load project details"));
|
||||
const managementGateway = createManagementGatewayStub({
|
||||
listTopics,
|
||||
listProjects,
|
||||
getProject,
|
||||
});
|
||||
const studioGateway =
|
||||
studioGatewayFromApplication(createTechLogFeatureInstalledInput(
|
||||
MOCK_STUDIO_INSTALL_CONTEXT,
|
||||
).input.createStudioApplication());
|
||||
|
||||
render(
|
||||
<TestQueryProviders>
|
||||
<MemoryRouter>
|
||||
<StudioProvider
|
||||
now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
||||
createGateway={() => studioGateway}
|
||||
createManagementGateway={() => managementGateway}
|
||||
>
|
||||
<TaxonomyManager />
|
||||
</StudioProvider>
|
||||
</MemoryRouter>
|
||||
</TestQueryProviders>,
|
||||
);
|
||||
|
||||
expect(await screen.findByText("Keycloak Patterns")).toBeVisible();
|
||||
expect(screen.getByText("인증 경계")).toBeVisible();
|
||||
await waitFor(() => {
|
||||
expect(listTopics).toHaveBeenCalledTimes(1);
|
||||
expect(listProjects).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
expect(getProject).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -50,12 +50,26 @@ test("게이트웨이가 축 연산을 주제 id 와 함께 부른다", async ()
|
||||
"../../../src/features/tech-log/adapters/http/http-management-gateway.ts"
|
||||
);
|
||||
|
||||
const called: { operationId: string; input: unknown }[] = [];
|
||||
const called: Array<{
|
||||
operationId: string;
|
||||
input: unknown;
|
||||
idempotencyKey: string | undefined;
|
||||
}> = [];
|
||||
const gateway = createHttpManagementGateway({
|
||||
operations: {
|
||||
execute: (operationId: string, input: unknown) => {
|
||||
called.push({ operationId, input });
|
||||
return Promise.resolve({ kind: "SUCCESS", value: [] });
|
||||
http: {
|
||||
execute: (
|
||||
operationId: string,
|
||||
input: unknown,
|
||||
context: Readonly<{
|
||||
intent?: Readonly<{ idempotencyKey?: string }>;
|
||||
}>,
|
||||
) => {
|
||||
called.push({
|
||||
operationId,
|
||||
input,
|
||||
idempotencyKey: context.intent?.idempotencyKey,
|
||||
});
|
||||
return Promise.resolve({ ok: true as const, value: [] });
|
||||
},
|
||||
},
|
||||
} as never);
|
||||
@@ -63,9 +77,23 @@ test("게이트웨이가 축 연산을 주제 id 와 함께 부른다", async ()
|
||||
const topicId = "11111111-1111-4111-8111-111111111111";
|
||||
const variantId = "22222222-2222-4222-8222-222222222222";
|
||||
await gateway.listTopicVariants(topicId);
|
||||
await gateway.createTopicVariant(topicId, { slug: "bff", title: "BFF" });
|
||||
await gateway.updateTopicVariant(topicId, variantId, { slug: "bff", title: "BFF" });
|
||||
await gateway.deleteTopicVariant(topicId, variantId, 3);
|
||||
await gateway.createTopicVariant(
|
||||
topicId,
|
||||
{ slug: "bff", title: "BFF" },
|
||||
{ idempotencyKey: "variant-create-test" },
|
||||
);
|
||||
await gateway.updateTopicVariant(
|
||||
topicId,
|
||||
variantId,
|
||||
{ slug: "bff", title: "BFF" },
|
||||
{ idempotencyKey: "variant-update-test" },
|
||||
);
|
||||
await gateway.deleteTopicVariant(
|
||||
topicId,
|
||||
variantId,
|
||||
3,
|
||||
{ idempotencyKey: "variant-delete-test" },
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
called.map((entry) => entry.operationId),
|
||||
@@ -78,4 +106,13 @@ test("게이트웨이가 축 연산을 주제 id 와 함께 부른다", async ()
|
||||
for (const entry of called.slice(2)) {
|
||||
assert.equal((entry.input as { variantId?: string }).variantId, variantId, entry.operationId);
|
||||
}
|
||||
assert.deepEqual(
|
||||
called.map((entry) => entry.idempotencyKey),
|
||||
[
|
||||
undefined,
|
||||
"variant-create-test",
|
||||
"variant-update-test",
|
||||
"variant-delete-test",
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,29 +5,18 @@ 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 type { TechLogStudioApplication } from "../../../src/features/tech-log/application/studio-application.ts";
|
||||
import {
|
||||
StudioContext,
|
||||
useStudioAssetGateway,
|
||||
useStudioApplication,
|
||||
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,
|
||||
studioApplication: TechLogStudioApplication,
|
||||
): StudioContextValue {
|
||||
return {
|
||||
gateway: {} as never,
|
||||
assetGateway,
|
||||
// 이 테스트는 Asset 접근자만 고정한다 — 관리 게이트웨이는 쓰이지 않으므로 자리만 채운다.
|
||||
managementGateway: {} as never,
|
||||
studioApplication,
|
||||
resolvePublishedLabel: () => undefined,
|
||||
now: () => new Date("2026-08-14T01:00:00.000Z"),
|
||||
editor: null,
|
||||
@@ -41,27 +30,30 @@ function contextValue(
|
||||
};
|
||||
}
|
||||
|
||||
function wrapperFor(assetGateway: StudioAssetGateway | null) {
|
||||
function wrapperFor(studioApplication: TechLogStudioApplication) {
|
||||
return function Wrapper({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<StudioContext.Provider value={contextValue(assetGateway)}>
|
||||
<StudioContext.Provider value={contextValue(studioApplication)}>
|
||||
{children}
|
||||
</StudioContext.Provider>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
test("returns the asset gateway when the provider supplied one", () => {
|
||||
const assetGateway = {} as StudioAssetGateway;
|
||||
const { result } = renderHook(() => useStudioAssetGateway(), {
|
||||
wrapper: wrapperFor(assetGateway),
|
||||
test("exposes one Studio application capability instead of raw gateway context fields", () => {
|
||||
const studioApplication = Object.freeze({}) as unknown as TechLogStudioApplication;
|
||||
const { result } = renderHook(() => useStudioApplication(), {
|
||||
wrapper: wrapperFor(studioApplication),
|
||||
});
|
||||
assert.equal(result.current, assetGateway);
|
||||
assert.equal(result.current, studioApplication);
|
||||
});
|
||||
|
||||
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/,
|
||||
);
|
||||
|
||||
test("does not expose raw gateway fields through StudioContextValue", () => {
|
||||
const studioApplication = Object.freeze({}) as unknown as TechLogStudioApplication;
|
||||
const value = contextValue(studioApplication);
|
||||
assert.equal("gateway" in value, false);
|
||||
assert.equal("assetGateway" in value, false);
|
||||
assert.equal("managementGateway" in value, false);
|
||||
assert.equal(value.studioApplication, studioApplication);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user