Files
clean-architecture-frontend…/tests/component/design-system-links.test.tsx
T
DongHyeonka e3c8db48ae chore(features): 참조 기능과 예제 화면을 지우고 레지스트리를 다시 승인한다
소유자 결정(2026-11-07, design-docs repo-structure/README.md 3.4절)으로
템플릿 샘플을 지운다. 샘플이 맡던 시험 대상은 앞 커밋들이 옮겼다.

참조 기능과 예제 화면, 두 context, 그 시험, e2e 3개, 수동 접근성 기록
7개, 런타임 프로필 키, test:reference-feature(명령, 산출물, 게이트
참조), 커버리지 정책 행을 지웠다. removable-template-features 목록은
비우고 장치는 남겼다: test:sample-removal은 인자가 없으면 목록을
하나씩 지우고, 비면 SKIP을 출력하고 보고서에 건너뛴 사례를 남긴다.
기능 스위치 시험과 홈 시작 링크 스위치 시험은 시험 전용 fixture 기능으로
옮겼다. browser soak은 생성 기능을 넣은 빌드에서 돈다. 문서의 샘플
경로를 고쳤다. 날짜가 붙은 설계·리뷰 기록의 본문은 그대로 두었다.
레지스트리 기준선(update:registry-baseline, OWNER DongHyeonka), CI 계약
기준선과 workflow, 초기 JS 기록(194,354B, 17파일, 첫 기능 6,327B, 기능
539B, context 4B)을 다시 받았다.

위험: 레지스트리 행 삭제는 breaking이다. 샘플을 고쳐 쓰는 다운스트림은
수정/삭제 충돌을 만난다. 성능 lab의 기능 라우트 측정은 템플릿에
공개 기능 라우트가 없어 measured:false다. TEMPLATE_FIXTURE 출처는
플랫폼 코드에 남았다.

검증(desktop): check:types, lint, check:architecture, check:registries,
check:ci, verify:documentation, test:unit, test:component,
test:contract, test:integration, test:recipes, test:coverage(Risk
coverage PASS 378/378, 문턱 68개), test:e2e 183, test:a11y, test:visual,
test:storybook, test:browser-capabilities, test:feature-scaffold PASS(76
checks), test:sample-removal SKIP, build, check:bundle.
2026-11-08 14:07:58 +09:00

157 lines
4.7 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { ReactNode } from "react";
import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";
import { describe, expect, it, vi } from "vitest";
import {
Breadcrumbs,
LinkButton,
Pagination,
} from "../../src/presentation/design-system/index.ts";
import { StandardPage } from "../../src/presentation/templates/index.ts";
function LocationProbe() {
const location = useLocation();
return <output data-testid="location">{`${location.pathname}${location.search}`}</output>;
}
function renderInRouter(ui: ReactNode, entry = "/app/items?q=term&sort=name") {
return render(
<MemoryRouter basename="/app" initialEntries={[entry]}>
<Routes>
<Route
path="*"
element={
<>
{ui}
<LocationProbe />
</>
}
/>
</Routes>
</MemoryRouter>,
);
}
describe("design-system links inside the router", () => {
it("renders LinkButton `to` as a router link that keeps the basename", async () => {
const user = userEvent.setup();
renderInRouter(<LinkButton to="/examples/platform">States</LinkButton>);
const link = screen.getByRole("link", { name: "States" });
expect(link).toHaveAttribute("href", "/app/examples/platform");
expect(link).toHaveClass("ui-button", "ui-button--primary");
await user.click(link);
expect(screen.getByTestId("location")).toHaveTextContent(
/^\/examples\/platform$/,
);
});
it("keeps LinkButton `href` as a plain anchor", () => {
renderInRouter(<LinkButton href="https://example.com/docs">Docs</LinkButton>);
expect(screen.getByRole("link", { name: "Docs" })).toHaveAttribute(
"href",
"https://example.com/docs",
);
});
it("renders breadcrumb `to` items as router links", async () => {
const user = userEvent.setup();
renderInRouter(
<Breadcrumbs
items={[
{ label: "Home", to: "/" },
{ label: "Examples", to: "/examples" },
{ label: "States" },
]}
label="Location"
/>,
);
expect(screen.getByRole("link", { name: "Home" })).toHaveAttribute(
"href",
"/app",
);
await user.click(screen.getByRole("link", { name: "Examples" }));
expect(screen.getByTestId("location")).toHaveTextContent(/^\/examples$/);
expect(screen.getByText("States")).toHaveAttribute("aria-current", "page");
});
it("renders page link actions with `to` as router links", async () => {
const user = userEvent.setup();
renderInRouter(
<StandardPage
actions={[
{ kind: "link", label: "Open states", to: "/examples/platform" },
{ kind: "link", label: "External", href: "https://example.com" },
]}
heading={{ title: "Page" }}
/>,
);
expect(screen.getByRole("link", { name: "External" })).toHaveAttribute(
"href",
"https://example.com",
);
const link = screen.getByRole("link", { name: "Open states" });
expect(link).toHaveAttribute("href", "/app/examples/platform");
await user.click(link);
expect(screen.getByTestId("location")).toHaveTextContent(
/^\/examples\/platform$/,
);
});
it("keeps the other search parameters and the basename in pagination links", async () => {
const user = userEvent.setup();
const onChange = vi.fn();
renderInRouter(
<Pagination
label="Pages"
nextLabel="Next"
onChange={onChange}
page={1}
pageCount={3}
pageLabel={(page) => `Page ${page}`}
previousLabel="Previous"
/>,
"/app/items?q=term&sort=name&page=1",
);
expect(screen.getByRole("link", { name: "Page 2" })).toHaveAttribute(
"href",
"/app/items?q=term&sort=name&page=2",
);
await user.click(screen.getByRole("link", { name: "Page 3" }));
expect(onChange).toHaveBeenCalledWith(3);
// Page changes stay with the owner: the link itself does not navigate.
expect(screen.getByTestId("location")).toHaveTextContent(
"/items?q=term&sort=name&page=1",
);
});
});
describe("pagination outside a router", () => {
it("keeps the other search parameters of the document URL", () => {
window.history.pushState({}, "", "/list?q=term");
render(
<Pagination
label="Pages"
nextLabel="Next"
onChange={() => {}}
page={1}
pageCount={2}
pageLabel={(page) => `Page ${page}`}
previousLabel="Previous"
/>,
);
expect(screen.getByRole("link", { name: "Page 2" })).toHaveAttribute(
"href",
"?q=term&page=2",
);
});
});