작성자가 처음 만나는 화면인데 사이트가 쓰지 않는 말을 쓰고 있었다 — 테두리를 두른 둥근
카드, 파란 채움 버튼, 파란 mono eyebrow. 나머지 화면은 상자를 두지 않고 글자의 굵기와
색으로만 격을 나눈다(805d400 에서 Studio 전체를 그렇게 바꿨는데, 이 화면만 「유일한
행동이니 채워 둔다」는 이유로 예외였다). 처음 만나는 화면이 예외면 그 사이트가 아닌 것처럼
보인다.
홈의 머리(`.home-identity`)와 같은 배치로 세운다 — shell 왼쪽 끝에 kicker·제목·설명이 서고,
헤어라인 아래에 「로그인 시작」과 돌아갈 곳이 한 줄로 온다. 상자도 채움도 없고 반응은
hover 밑줄뿐이다.
- 제목에 초점을 줄 때(page-header.tsx 의 라우트 초점) 파란 사각형이 제목을 두르고 있었다.
`:focus-visible` 일 때만 바깥쪽으로 표시한다.
- kicker 를 「SIGN IN」에서 「STUDIO」로 바꾼다. 사이트의 다른 머리말은 Topic·Explore 처럼
어디인지를 말하고, 「SIGN IN」이면 바로 아래 제목과 같은 말을 두 번 한다.
- 제목이 그 자리에서 이유를 말하게 하고(「기록을 쓰려면 로그인이 필요합니다」) 설명에서
겹치던 첫 문장을 뺀다.
router 컴포넌트 검사가 「세션이 필요합니다.」라는 옛 제목을 그대로 적어 두어, 그 말이 바뀐
뒤로 계속 빨간 채 지나가고 있었다 — 잡아야 할 것(보호된 라우트가 로그인 관문으로 떨어진다)은
멀쩡한데 검사만 낡았다. 문구가 아니라 `data-surface` 를 묻게 한다.
438 lines
14 KiB
TypeScript
438 lines
14 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
import { z } from "zod";
|
|
import {
|
|
createMemoryRouter,
|
|
matchRoutes,
|
|
Outlet,
|
|
RouterProvider,
|
|
} from "react-router-dom";
|
|
|
|
import { createExternalAuthSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts";
|
|
import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts";
|
|
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 { TECH_LOG_FEATURE_ID } from "../../src/features/tech-log/application/tech-log-feature-input.ts";
|
|
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
|
|
import { renderWithQueryProviders } from "../helpers/query-providers.tsx";
|
|
import {
|
|
AppRouter,
|
|
createGroupedRouteObjects,
|
|
} from "../../src/presentation/routes/app-router.tsx";
|
|
import { createTestApplication } from "../helpers/create-test-application.ts";
|
|
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
|
import {
|
|
ROUTE_CODECS,
|
|
ROUTE_RUNTIME,
|
|
} from "../../src/features/installed-feature-runtimes.tsx";
|
|
import { LocaleProvider } from "../../src/presentation/i18n/index.ts";
|
|
import { SessionProvider } from "../../src/presentation/providers/session-provider.tsx";
|
|
import { ThemeProvider } from "../../src/presentation/providers/theme-provider.tsx";
|
|
import { useRouteInput } from "../../src/presentation/routes/route-input.tsx";
|
|
|
|
function StudioFallbackFixture() {
|
|
const input = useRouteInput();
|
|
return <h1>{String(input.params["*"])}</h1>;
|
|
}
|
|
|
|
const reviewFixtureCodecs = Object.freeze({
|
|
ReviewFixtureParams: z
|
|
.object({ reviewId: z.string().min(1) })
|
|
.strict(),
|
|
ReviewFixtureSearch: z
|
|
.object({
|
|
filter: z.preprocess(
|
|
(value) => (Array.isArray(value) ? value[0] : value),
|
|
z.string().trim().min(1).optional(),
|
|
),
|
|
})
|
|
.strip(),
|
|
});
|
|
|
|
const groupedFixtureCodecs = Object.freeze({
|
|
none: ROUTE_CODECS.none,
|
|
NotFoundSplat: ROUTE_CODECS.NotFoundSplat,
|
|
});
|
|
|
|
const reviewFixtureRegistry = Object.freeze({
|
|
REVIEW_FIXTURE: Object.freeze({
|
|
...ROUTE_REGISTRY.TECH_LOG_HOME,
|
|
routeId: "REVIEW_FIXTURE",
|
|
path: "/review/:reviewId",
|
|
paramsSchema: "ReviewFixtureParams",
|
|
searchSchema: "ReviewFixtureSearch",
|
|
}),
|
|
});
|
|
|
|
function ReviewRouteFixture() {
|
|
const input = useRouteInput<"REVIEW_FIXTURE">();
|
|
expectTypeOf(input.routeId).toEqualTypeOf<"REVIEW_FIXTURE">();
|
|
return (
|
|
<section>
|
|
<h1>{input.routeId}</h1>
|
|
<p data-testid="review-param">{String(input.params.reviewId)}</p>
|
|
<p data-testid="review-search">{JSON.stringify(input.search)}</p>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
const reviewFixtureRuntime = Object.freeze({
|
|
REVIEW_FIXTURE: Object.freeze({
|
|
moduleId: "review-fixture",
|
|
Component: ReviewRouteFixture,
|
|
}),
|
|
});
|
|
|
|
function compileTimeGroupedRouteContract() {
|
|
// @ts-expect-error A grouped route composition must provide its codec registry.
|
|
createGroupedRouteObjects(
|
|
reviewFixtureRegistry,
|
|
reviewFixtureRuntime,
|
|
{ PUBLIC: <Outlet />, STUDIO: <Outlet /> },
|
|
"type-test-build",
|
|
);
|
|
return createGroupedRouteObjects(
|
|
reviewFixtureRegistry,
|
|
reviewFixtureRuntime,
|
|
{ PUBLIC: <Outlet />, STUDIO: <Outlet /> },
|
|
"type-test-build",
|
|
reviewFixtureCodecs,
|
|
);
|
|
}
|
|
void compileTimeGroupedRouteContract;
|
|
|
|
/**
|
|
* Studio routes are `session-required`, so a Studio assertion needs a session
|
|
* that says so — with the anonymous adapter the router correctly renders the
|
|
* sign-in surface instead of the page, which is what the gate is for.
|
|
*/
|
|
function createSignedInSessionAdapter() {
|
|
return createExternalAuthSessionAdapter({
|
|
readState: () => "authenticated" as const,
|
|
subscribe: () => () => {},
|
|
beginSignIn: async () => {},
|
|
signOut: async () => {},
|
|
attachCredential: async () => ({ headers: {} }),
|
|
recoverSession: async () => "restored" as const,
|
|
notifyUnauthenticated: () => {},
|
|
});
|
|
}
|
|
|
|
function renderRouter(session = createAnonymousSessionAdapter()) {
|
|
const techLog = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT);
|
|
return render(
|
|
renderWithQueryProviders(
|
|
<ApplicationProvider
|
|
application={createTestApplication({
|
|
session,
|
|
featureInputs: { [TECH_LOG_FEATURE_ID]: techLog.input },
|
|
})}
|
|
>
|
|
<AppRouter />
|
|
</ApplicationProvider>,
|
|
),
|
|
);
|
|
}
|
|
|
|
describe("generic application router", () => {
|
|
it("renders and canonicalizes an isolated non-installed route codec contract", async () => {
|
|
expect(ROUTE_REGISTRY).not.toHaveProperty("REVIEW_FIXTURE");
|
|
expect(ROUTE_CODECS).not.toHaveProperty("ReviewFixtureParams");
|
|
expect(ROUTE_CODECS).not.toHaveProperty("ReviewFixtureSearch");
|
|
|
|
const routes = createGroupedRouteObjects(
|
|
reviewFixtureRegistry,
|
|
reviewFixtureRuntime,
|
|
{ PUBLIC: <Outlet />, STUDIO: <Outlet /> },
|
|
"test-build",
|
|
reviewFixtureCodecs,
|
|
);
|
|
const router = createMemoryRouter(routes, {
|
|
initialEntries: [
|
|
"/review/non-empty?filter=%20first%20&filter=second&unknown=drop",
|
|
],
|
|
});
|
|
|
|
render(
|
|
renderWithQueryProviders(
|
|
<ApplicationProvider application={createTestApplication()}>
|
|
<LocaleProvider>
|
|
<ThemeProvider>
|
|
<SessionProvider>
|
|
<RouterProvider router={router} />
|
|
</SessionProvider>
|
|
</ThemeProvider>
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
),
|
|
);
|
|
|
|
expect(
|
|
await screen.findByRole("heading", { name: "REVIEW_FIXTURE" }),
|
|
).toBeVisible();
|
|
expect(screen.getByTestId("review-param")).toHaveTextContent("non-empty");
|
|
expect(screen.getByTestId("review-search")).toHaveTextContent(
|
|
'{"filter":"first"}',
|
|
);
|
|
await waitFor(() =>
|
|
expect(router.state.location).toMatchObject({
|
|
pathname: "/review/non-empty",
|
|
search: "?filter=first",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("assembles generic Public and Studio parents with Studio catch-all precedence", () => {
|
|
const registry = {
|
|
TECH_LOG_HOME: ROUTE_REGISTRY.TECH_LOG_HOME,
|
|
STUDIO_FIXTURE: {
|
|
...ROUTE_REGISTRY.NOT_FOUND,
|
|
routeId: "STUDIO_FIXTURE",
|
|
path: "/studio/*",
|
|
layoutGroup: "STUDIO" as const,
|
|
},
|
|
NOT_FOUND: ROUTE_REGISTRY.NOT_FOUND,
|
|
};
|
|
const runtime = {
|
|
TECH_LOG_HOME: ROUTE_RUNTIME.TECH_LOG_HOME,
|
|
STUDIO_FIXTURE: ROUTE_RUNTIME.NOT_FOUND,
|
|
NOT_FOUND: ROUTE_RUNTIME.NOT_FOUND,
|
|
};
|
|
const routes = createGroupedRouteObjects(
|
|
registry,
|
|
runtime,
|
|
{
|
|
PUBLIC: <div data-layout="public" />,
|
|
STUDIO: <div data-layout="studio" />,
|
|
},
|
|
"test-build",
|
|
groupedFixtureCodecs,
|
|
);
|
|
|
|
expect(routes.map((route) => route.id)).toEqual([
|
|
"STUDIO_LAYOUT",
|
|
"PUBLIC_LAYOUT",
|
|
]);
|
|
expect(
|
|
matchRoutes(routes, "/studio/unknown")?.map((match) => match.route.id),
|
|
).toEqual(["STUDIO_LAYOUT", "STUDIO_FIXTURE"]);
|
|
expect(
|
|
matchRoutes(routes, "/publicly-unknown")?.map((match) => match.route.id),
|
|
).toEqual(["PUBLIC_LAYOUT", "NOT_FOUND"]);
|
|
|
|
const installedRoutes = createGroupedRouteObjects(
|
|
ROUTE_REGISTRY,
|
|
ROUTE_RUNTIME,
|
|
{
|
|
PUBLIC: <div data-layout="public" />,
|
|
STUDIO: <div data-layout="studio" />,
|
|
},
|
|
"test-build",
|
|
groupedFixtureCodecs,
|
|
);
|
|
expect(installedRoutes[1]?.children?.at(-1)?.id).toBe("NOT_FOUND");
|
|
});
|
|
|
|
it("rejects a grouped registry whose leaf runtime is missing", () => {
|
|
expect(() =>
|
|
createGroupedRouteObjects(
|
|
ROUTE_REGISTRY,
|
|
{},
|
|
{
|
|
PUBLIC: <div data-layout="public" />,
|
|
STUDIO: <div data-layout="studio" />,
|
|
},
|
|
"test-build",
|
|
groupedFixtureCodecs,
|
|
),
|
|
).toThrow("Missing route runtime: TECH_LOG_HOME");
|
|
});
|
|
|
|
it("renders a non-installed Studio wildcard leaf without rewriting its URL", async () => {
|
|
const routes = createGroupedRouteObjects(
|
|
{
|
|
STUDIO_FIXTURE: {
|
|
...ROUTE_REGISTRY.NOT_FOUND,
|
|
routeId: "STUDIO_FIXTURE",
|
|
path: "/studio/*",
|
|
layoutGroup: "STUDIO",
|
|
},
|
|
},
|
|
{
|
|
STUDIO_FIXTURE: {
|
|
moduleId: "studio-fixture",
|
|
Component: StudioFallbackFixture,
|
|
},
|
|
},
|
|
{
|
|
PUBLIC: <Outlet />,
|
|
STUDIO: (
|
|
<section data-testid="studio-layout">
|
|
<Outlet />
|
|
</section>
|
|
),
|
|
},
|
|
"test-build",
|
|
groupedFixtureCodecs,
|
|
);
|
|
const router = createMemoryRouter(routes, {
|
|
initialEntries: ["/studio/unknown/path"],
|
|
});
|
|
|
|
render(
|
|
renderWithQueryProviders(
|
|
<ApplicationProvider application={createTestApplication()}>
|
|
<LocaleProvider>
|
|
<ThemeProvider>
|
|
<SessionProvider>
|
|
<RouterProvider router={router} />
|
|
</SessionProvider>
|
|
</ThemeProvider>
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
),
|
|
);
|
|
|
|
expect(await screen.findByTestId("studio-layout")).toBeVisible();
|
|
expect(
|
|
await screen.findByRole("heading", { name: "unknown/path" }),
|
|
).toBeVisible();
|
|
expect(router.state.location.pathname).toBe("/studio/unknown/path");
|
|
});
|
|
|
|
it("applies authorization from a non-installed route definition", async () => {
|
|
const routes = createGroupedRouteObjects(
|
|
{
|
|
PROTECTED_FIXTURE: {
|
|
...ROUTE_REGISTRY.TECH_LOG_HOME,
|
|
routeId: "PROTECTED_FIXTURE",
|
|
path: "/private-fixture",
|
|
access: "session-required",
|
|
searchSchema: null,
|
|
},
|
|
},
|
|
{
|
|
PROTECTED_FIXTURE: {
|
|
moduleId: "protected-fixture",
|
|
Component: StudioFallbackFixture,
|
|
},
|
|
},
|
|
{
|
|
PUBLIC: <Outlet />,
|
|
STUDIO: <Outlet />,
|
|
},
|
|
"test-build",
|
|
groupedFixtureCodecs,
|
|
);
|
|
const router = createMemoryRouter(routes, {
|
|
initialEntries: ["/private-fixture"],
|
|
});
|
|
|
|
render(
|
|
renderWithQueryProviders(
|
|
<ApplicationProvider application={createTestApplication()}>
|
|
<LocaleProvider>
|
|
<ThemeProvider>
|
|
<SessionProvider>
|
|
<RouterProvider router={router} />
|
|
</SessionProvider>
|
|
</ThemeProvider>
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
),
|
|
);
|
|
|
|
/*
|
|
문구가 아니라 동작을 묻는다. 「세션이 필요합니다.」라는 옛 제목을 그대로 적어 두었더니
|
|
그 말이 바뀐 뒤로 이 검사는 계속 빨간 채로 지나갔다 — 잡아야 할 것(보호된 라우트가
|
|
로그인 관문으로 떨어진다)은 멀쩡한데 검사만 낡은 상태였다. 관문임을 말하는 것은
|
|
`data-surface` 이고, 그 값은 계약이다.
|
|
*/
|
|
const gate = await screen.findByRole("heading", { level: 1 });
|
|
expect(gate).toBeVisible();
|
|
expect(gate.closest("[data-surface]")).toHaveAttribute(
|
|
"data-surface",
|
|
"authentication-required",
|
|
);
|
|
});
|
|
|
|
it("renders the installed TechLog home in the Public layout", async () => {
|
|
const user = userEvent.setup();
|
|
window.history.pushState({}, "", "/");
|
|
renderRouter();
|
|
|
|
expect(
|
|
await screen.findByRole("heading", { name: "TechLog", level: 1 }),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("navigation", { name: "주요 탐색" })).toBeVisible();
|
|
await user.click(
|
|
within(screen.getByRole("navigation", { name: "주요 탐색" })).getByRole(
|
|
"link",
|
|
{ name: "프로젝트" },
|
|
),
|
|
);
|
|
expect(
|
|
await screen.findByRole("heading", { name: "프로젝트", level: 1 }),
|
|
).toBeVisible();
|
|
expect(window.location.pathname).toBe("/projects");
|
|
});
|
|
|
|
it("keeps the unreachable client-side Public fallback inside its accessible shell", async () => {
|
|
window.history.pushState({}, "", "/missing");
|
|
renderRouter();
|
|
|
|
expect(
|
|
await screen.findByRole("heading", { name: "페이지를 찾을 수 없습니다." }),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("navigation", { name: "주요 탐색" })).toBeVisible();
|
|
expect(screen.queryByText("Not Found", { exact: true })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps a signed-out visitor out of the Studio layout entirely", async () => {
|
|
window.history.pushState({}, "", "/studio");
|
|
renderRouter();
|
|
|
|
// Not merely "no data": the Studio surface itself must not mount. Every
|
|
// TechLog route used to register as `access: "public"`, so a signed-out
|
|
// visitor who typed /studio got the shell, the navigation, and the page —
|
|
// and the page then issued Studio API calls.
|
|
await screen.findByRole("heading", { name: /세션|로그인/ });
|
|
expect(
|
|
screen.queryByRole("heading", { name: "작업 흐름" }),
|
|
).not.toBeInTheDocument();
|
|
expect(
|
|
screen.queryByRole("navigation", { name: "Studio 주 탐색" }),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps Studio routes inside the persistent Studio layout", async () => {
|
|
window.history.pushState({}, "", "/studio");
|
|
renderRouter(createSignedInSessionAdapter());
|
|
|
|
expect(
|
|
await screen.findByRole("heading", { name: "작업 흐름" }),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("navigation", { name: "Studio 주 탐색" })).toBeVisible();
|
|
expect(screen.getByRole("link", { name: "공개 사이트 보기" })).toHaveAttribute(
|
|
"href",
|
|
"/",
|
|
);
|
|
});
|
|
|
|
it("gives the Studio wildcard precedence over the Public not-found route", async () => {
|
|
window.history.pushState({}, "", "/studio/missing");
|
|
renderRouter(createSignedInSessionAdapter());
|
|
|
|
expect(
|
|
await screen.findByRole("heading", {
|
|
name: "Studio 화면을 찾을 수 없습니다",
|
|
}),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("navigation", { name: "Studio 주 탐색" })).toBeVisible();
|
|
expect(window.location.pathname).toBe("/studio/missing");
|
|
});
|
|
});
|