180 lines
7.6 KiB
TypeScript
180 lines
7.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
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";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
|
|
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
|
|
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 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 "../../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" }>;
|
|
|
|
function decisionInput(): DecisionInput {
|
|
return {
|
|
kind: "PROJECT_DECISION",
|
|
title: "목록 페이징과 컬렉션 로딩을 분리합니다",
|
|
slug: "feed-pagination-boundary",
|
|
summary: "부모 페이지를 먼저 고정하고 연관 컬렉션을 별도로 조회합니다.",
|
|
topicId: FIXTURE_IDS.topicJpa,
|
|
projectId: FIXTURE_IDS.projectBackend,
|
|
relations: [
|
|
{
|
|
id: null,
|
|
targetId: FIXTURE_IDS.fetchJoinCase,
|
|
reason: "판단 근거",
|
|
order: 0,
|
|
},
|
|
],
|
|
decisionStatus: "ADOPTED",
|
|
decidedOn: "2026-08-11",
|
|
statement: "목록 조회와 컬렉션 로딩을 서로 다른 단계로 수행합니다.",
|
|
rationale: "Fetch Join이 DB LIMIT를 제거하는 문제를 피합니다.",
|
|
consequences: [
|
|
{
|
|
id: "99999999-9999-4999-8999-999999999991",
|
|
text: "목록 조회는 한 번의 SQL로 끝나지 않습니다.",
|
|
order: 0,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
function RouterStudioProvider({
|
|
gateway,
|
|
children,
|
|
}: Readonly<{ gateway: StudioGateway; children: ReactNode }>) {
|
|
const navigate = useNavigate();
|
|
return (
|
|
<StudioProvider now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
|
createManagementGateway={createManagementGatewayStub}
|
|
createGateway={() => gateway}
|
|
navigate={(href) => { void navigate(href); }}
|
|
>
|
|
{children}
|
|
</StudioProvider>
|
|
);
|
|
}
|
|
|
|
function LocationProbe() {
|
|
return <output aria-label="현재 경로">{useLocation().pathname}</output>;
|
|
}
|
|
|
|
describe("TechLog Studio project decision authoring", () => {
|
|
it("creates Decision as the fourth working-copy type", async () => {
|
|
const user = userEvent.setup();
|
|
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
|
render(
|
|
<MemoryRouter initialEntries={["/studio/documents/new"]}>
|
|
<RouterStudioProvider gateway={gateway}>
|
|
<NewDocumentForm />
|
|
<LocationProbe />
|
|
</RouterStudioProvider>
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
await user.click(screen.getByRole("radio", { name: /설계 결정/ }));
|
|
await user.click(screen.getByRole("button", { name: "작업본 만들기" }));
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByLabelText("현재 경로")).toHaveTextContent(
|
|
/^\/studio\/documents\/[0-9a-f-]+\/edit$/,
|
|
);
|
|
});
|
|
expect((await gateway.listDocuments({ kind: "PROJECT_DECISION" })).items)
|
|
.toHaveLength(1);
|
|
});
|
|
|
|
it("validates, previews, and publishes a project-scoped Decision", async () => {
|
|
const gateway = studioGatewayFromApplication(createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioApplication());
|
|
const document = await gateway.createDocument(decisionInput(), {
|
|
idempotencyKey: "create-project-decision",
|
|
});
|
|
const validation = await gateway.validateDocument(
|
|
document.id,
|
|
{ expectedVersion: document.version },
|
|
{ idempotencyKey: "validate-project-decision" },
|
|
);
|
|
expect(validation).toMatchObject({ status: "VALID", issues: [] });
|
|
|
|
const preview = await gateway.createPreview(
|
|
document.id,
|
|
{
|
|
expectedVersion: document.version,
|
|
validationId: validation.validationId,
|
|
},
|
|
{ idempotencyKey: "preview-project-decision" },
|
|
);
|
|
expect(preview.renderModel).toMatchObject({
|
|
kind: "PROJECT_DECISION",
|
|
status: "ADOPTED",
|
|
publicPath: "/projects/backend-skeleton/decisions#feed-pagination-boundary",
|
|
});
|
|
|
|
const published = await gateway.publishDocument(
|
|
document.id,
|
|
{
|
|
expectedVersion: document.version,
|
|
validationId: validation.validationId,
|
|
previewId: preview.previewId,
|
|
acknowledgedWarningCodes: [],
|
|
},
|
|
{ idempotencyKey: "publish-project-decision" },
|
|
);
|
|
expect(published.publication.publicPath).toBe(
|
|
"/projects/backend-skeleton/decisions#feed-pagination-boundary",
|
|
);
|
|
});
|
|
|
|
it("edits Decision fields on the single document surface without a preview mode", async () => {
|
|
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 now={() => new Date(DEFAULT_STUDIO_MOCK_NOW)}
|
|
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway}>
|
|
<DocumentEditorScreen documentId={document.id} />
|
|
</StudioProvider>
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
const decisionStatus = await screen.findByRole("group", { name: "결정 상태" });
|
|
expect(within(decisionStatus).getByRole("button", { name: "ADOPTED" })).toHaveAttribute("aria-pressed", "true");
|
|
expect(screen.getByLabelText("결정일")).toHaveValue("2026-08-11");
|
|
expect(screen.getByLabelText("결정문")).toHaveValue(
|
|
"목록 조회와 컬렉션 로딩을 서로 다른 단계로 수행합니다.",
|
|
);
|
|
expect(screen.getByLabelText("판단 이유")).toHaveValue(
|
|
"Fetch Join이 DB LIMIT를 제거하는 문제를 피합니다.",
|
|
);
|
|
expect(screen.getByLabelText("영향 1")).toHaveValue(
|
|
"목록 조회는 한 번의 SQL로 끝나지 않습니다.",
|
|
);
|
|
expect(screen.getByLabelText("근거 1 대상")).toHaveValue(
|
|
FIXTURE_IDS.fetchJoinCase,
|
|
);
|
|
expect(screen.getByLabelText("현재 문서")).toHaveTextContent("PROJECT_DECISION");
|
|
expect(screen.getByRole("main", { name: "문서 편집" })).toBeVisible();
|
|
expect(screen.queryByRole("button", { name: "나란히" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "미리보기" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("region", { name: "즉시 미리보기" })).not.toBeInTheDocument();
|
|
});
|
|
});
|