Files
tech-log-frontend/tests/features/tech-log/studio-shell-smoke.test.tsx
T
DongHyeonkaandClaude Opus 5 9545860605 feat: Studio 가 보고 대신 다음 한 걸음을 먼저 보여 준다
탐색 여섯 자리가 같은 무게로 늘어서 있었다. 「작업본」과 「릴리즈」가 같은 크기로
나란하면 어디부터 봐야 하는지를 화면이 말해 주지 않는다. 글을 쓰는 일·구조를 손보는
일·자료를 관리하는 일·내보내는 일 넷으로 묶는다. 이름과 순서는 계약이 갖고 있으므로
여기서는 묶음만 정하고, 표가 `Record` 라 탐색 항목이 늘면 컴파일러가 잡는다.

대시보드는 숫자 넷과 목록 셋으로 무엇이 얼마나 있는지를 보고했다. 작성자가 이 화면을
여는 이유는 보고를 읽으려는 것이 아니라 하던 일을 이어서 하려는 것인데, 그 다음 한
걸음은 세 목록 중 어딘가에 같은 크기로 섞여 있었다. 가장 최근에 손댄 것 하나를 맨 위에
세우고 그 작업본의 다음 화면으로 바로 보낸다.

작업본 목록의 「삭제」는 61줄에서 61번 반복돼 이 화면의 기본 동작처럼 보였다. 한 겹
안으로 넣는다. 계약이 주고 있었지만 화면이 쓰지 않던 `hasUnpublishedChanges` 도
드러낸다 — 작성자는 "이미 게시했는데 고친 게 아직 안 나갔다"를 목록에서 알 수 없었다.

다음 할 일의 이름과 갈 곳을 한 벌로 모았다. 대시보드와 목록이 각자 표를 들고 있었다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D
2026-09-15 20:27:41 +09:00

166 lines
7.9 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Outlet, RouterProvider, createMemoryRouter } from "react-router-dom";
import { afterEach, describe, expect, it, vi } 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 type { StudioGateway } from "../../../src/features/tech-log/application/ports/studio-gateway.ts";
import { StudioHomePage } from "../../../src/features/tech-log/presentation/studio/pages/studio-home-page.tsx";
import { StudioNotFoundPage } from "../../../src/features/tech-log/presentation/studio/pages/studio-not-found-page.tsx";
import { StudioShell } from "../../../src/features/tech-log/presentation/studio/studio-shell.tsx";
import { createExternalAuthSessionAdapter } from "../../../src/adapters/auth/external-session-adapter.ts";
import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx";
import { SessionProvider } from "../../../src/presentation/providers/session-provider.tsx";
import { createTestApplication } from "../../helpers/create-test-application.ts";
import { renderWithQueryProviders } from "../../helpers/query-providers.tsx";
afterEach(() => vi.restoreAllMocks());
async function renderStudio(
initialEntry: string,
createStudioGateway: () => StudioGateway,
) {
const router = createMemoryRouter(
[
{
path: "/studio",
element: (
<StudioShell>
<Outlet />
</StudioShell>
),
children: [
{ index: true, element: <StudioHomePage /> },
{ path: "documents", element: <p>작업본 라우트</p> },
{ path: "documents/new", element: <p>새 문서 라우트</p> },
{ path: "publications", element: <p>게시 기록 라우트</p> },
{ path: "*", element: <StudioNotFoundPage /> },
],
},
],
{ initialEntries: [initialEntry] },
);
const installed = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
const application = createTestApplication({
// The Studio shell draws its chrome only for an authenticated session — a
// signed-out visitor gets the sign-in surface and nothing else, which is
// what these tests are not about. In the real app AppRouter supplies both
// the session state and the provider; here the harness does.
session: createExternalAuthSessionAdapter({
readState: () => "authenticated" as const,
subscribe: () => () => {},
beginSignIn: async () => {},
signOut: async () => {},
attachCredential: async () => ({ headers: {} }),
recoverSession: async () => "restored" as const,
notifyUnauthenticated: () => {},
}),
featureInputs: {
"tech-log": { ...installed, createStudioGateway },
},
});
const view = render(
renderWithQueryProviders(
<ApplicationProvider application={application}>
<SessionProvider>
<RouterProvider router={router} />
</SessionProvider>
</ApplicationProvider>,
));
// 포트가 async 가 되면서 첫 페인트에는 데이터가 없다. 화면이 정착한 뒤
// 단언하도록 여기서 한 번 기다린다 — 각 테스트에 흩어 놓으면 빠뜨린 곳이 생긴다.
await screen.findByRole("main");
return { ...view, router };
}
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 createGateway = vi.fn(() => gateway);
const { container, router } = await renderStudio("/studio", createGateway);
expect(await screen.findByRole("heading", { level: 1, name: "작업 흐름" })).toBeVisible();
expect(createGateway).toHaveBeenCalledTimes(1);
expect(
Array.from(
container.querySelectorAll<HTMLAnchorElement>(".studio-desktop-navigation a"),
(link) => [link.textContent, link.getAttribute("href")],
),
/*
탐색은 넷으로 묶인다 — 글을 쓰는 일, 구조를 손보는 일, 자료를 관리하는 일, 내보내는 일.
여섯 자리가 같은 무게로 늘어서 있으면 어디부터 봐야 하는지를 화면이 말해 주지 않는다.
항목과 주소는 계약이 정하고 여기서는 묶음 순서만 바뀐다.
*/
).toEqual([
["작업본", "/studio/documents"],
["새 문서", "/studio/documents/new"],
["주제·프로젝트", "/studio/taxonomy"],
["Asset", "/studio/assets"],
["게시 기록", "/studio/publications"],
["릴리즈", "/studio/releases"],
["공개 사이트 보기", "/"],
]);
expect(
Array.from(
container.querySelectorAll(".studio-desktop-navigation .studio-nav-group-label"),
(label) => label.textContent,
),
).toEqual(["작업", "구조", "자료", "게시"]);
expect(screen.getByRole("link", { name: "공개 사이트 보기" })).toHaveAttribute("href", "/");
expect(screen.queryByText(/로그인|sign in/i)).not.toBeInTheDocument();
await user.click(within(screen.getByRole("navigation", { name: "Studio 주 탐색" })).getByRole("link", { name: "작업본" }));
expect(router.state.location.pathname).toBe("/studio/documents");
expect(screen.getByText("작업본 라우트")).toBeVisible();
expect(createGateway).toHaveBeenCalledTimes(1);
expect(screen.getAllByRole("link", { name: "작업본" })[0]).toHaveAttribute("aria-current", "page");
});
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();
vi.spyOn(first, "getDashboard").mockImplementation(({ signal } = {}) => {
firstSignal = signal;
return new Promise(() => {});
});
const secondDashboard = vi.spyOn(second, "getDashboard");
const createGateway = vi.fn()
.mockReturnValueOnce(first)
.mockReturnValueOnce(second);
await renderStudio("/studio", createGateway);
await waitFor(() => expect(firstSignal).toBeDefined());
await user.click(screen.getByRole("button", { name: "Studio 메뉴 열기" }));
expect(screen.getByRole("button", { name: "Studio 메뉴 닫기" })).toBeVisible();
window.dispatchEvent(new PageTransitionEvent("pageshow", { persisted: true }));
await waitFor(() => expect(createGateway).toHaveBeenCalledTimes(2));
expect(firstSignal?.aborted).toBe(true);
expect(screen.getByRole("button", { name: "Studio 메뉴 열기" })).toHaveAttribute("aria-expanded", "false");
expect(await screen.findByRole("heading", { level: 1, name: "작업 흐름" })).toBeVisible();
expect(secondDashboard).toHaveBeenCalledTimes(1);
});
it("keeps unknown Studio routes inside the Studio shell without authentication UI", async () => {
const createGateway = vi.fn(
() => createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
);
await renderStudio("/studio/does-not-exist", createGateway);
expect(screen.getByRole("banner")).toHaveClass("studio-header");
expect(screen.getByRole("heading", { level: 1, name: "Studio 화면을 찾을 수 없습니다" })).toBeVisible();
expect(screen.getByRole("link", { name: "작업본으로 돌아가기" })).toHaveAttribute("href", "/studio/documents");
expect(screen.queryByText(/로그인|sign in/i)).not.toBeInTheDocument();
});
});