Files
tech-log-frontend/tests/features/tech-log/home-topic-tabs.test.tsx
T
DongHyeonka de4cb8b30b feat: 홈이 주제를 탭으로 나란히 세운다
홈은 주제 하나만 펴 두고 나머지는 비교 목록 밑 「다른 주제 N개 보기」 한 줄로 보냈다.
그 줄은 목록을 다 읽고 나서야 만나는 자리라 대개 지나쳤고, 그래서 JPA 주제는 홈에
있으면서도 없는 것과 같았다.

구역 제목이 서 있던 자리(「구조별로 알게 된 것」)를 주제 이름 탭이 대신한다. 무엇이 더
있는지가 목록을 읽기 전에 먼저 보이고, 탭을 고르면 그 주제의 축이 그대로 열린다 —
인증 경계면 SPA·Mediator·BFF·Forward-Auth, JPA면 그 주제의 조회 전략들이다.

- 축의 이름은 목록 바로 위로 내렸다. 제목 자리를 탭이 가져갔으니 「이 넷은 구조다」는
  목록에 붙어 있어야 짝이 보인다.
- 패널은 전부 그려 두고 감춘다. 상세는 이미 받아 온 것이라 탭을 눌러도 요청이 나가지
  않고, 페이지 내 검색이 감춘 주제까지 찾는다.
- 탭이 되는 주제 수에 상한을 둔다. 주제마다 상세 요청이 하나씩 나가므로, 주제가 늘어도
  홈의 요청 수는 정해져 있다.
- 「다른 주제」 줄은 축이 없어 탭이 되지 못한 주제만 받는다.

탭은 h2 가 아니지만 구역 제목의 자리를 물려받았으므로 `section-heading-rank` 가 그 급을
정본과 함께 묶는다.
2026-09-02 10:59:14 +09:00

132 lines
4.4 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { MemoryRouter } from "react-router-dom";
import type { PublicTopicDetail } from "../../../src/features/tech-log/application/ports/public-content-queries.ts";
import { HomeTopicTabs } from "../../../src/features/tech-log/presentation/public/components/home-topic-tabs.tsx";
/**
* 홈이 주제 하나만 펴 두던 동안, 나머지로 가는 길은 비교 목록 밑의 작은 글씨 한 줄뿐이었다 —
* 다 읽고 나서야 만나는 자리라 대개 지나쳤다. 탭이 하는 일은 「무엇이 더 있는지」를 목록보다
* 먼저 보이게 하는 것이므로, 검사도 그것을 본다.
*/
function topic(
slug: string,
name: string,
variantLabel: string,
variants: ReadonlyArray<[string, string, string]>,
): PublicTopicDetail {
return {
name,
slug,
description: "",
thesis: "",
variantLabel,
variants: variants.map(([variantSlug, title, conclusion]) => ({
slug: variantSlug,
title,
path: `/topics/${slug}/${variantSlug}`,
summary: `${title} 요약`,
conclusion,
recordCount: 2,
})),
featuredCases: [],
activeQuestions: [],
relatedProjects: [],
};
}
const AUTH = topic("oauth-oidc-auth-boundary", "OAuth/OIDC 인증 경계", "구조", [
["spa", "SPA", "브라우저가 token 을 들고 있다"],
["mediator", "Mediator", "교환만 서버가 맡는다"],
["bff", "BFF", "서버가 세션을 갖는다"],
["forward-auth", "Forward-Auth", "게이트웨이가 신원을 붙인다"],
]);
const JPA = topic("jpa-feed-query-performance", "JPA 피드 조회 성능", "조회 전략", [
["fetch-join", "Fetch Join", "행이 곱해진다"],
["derived-query", "Derived Query", "쿼리가 나뉜다"],
]);
function renderTabs(topics: ReadonlyArray<PublicTopicDetail>) {
return render(
<MemoryRouter>
<HomeTopicTabs topics={topics} />
</MemoryRouter>,
);
}
describe("홈의 주제 탭", () => {
it("주제 이름이 목록보다 먼저 전부 보인다", () => {
renderTabs([AUTH, JPA]);
expect(screen.getAllByRole("tab").map((tab) => tab.textContent)).toEqual([
"OAuth/OIDC 인증 경계",
"JPA 피드 조회 성능",
]);
});
it("첫 주제의 축이 열려 있고 나머지 주제의 축은 감춰져 있다", () => {
renderTabs([AUTH, JPA]);
const open = screen.getByRole("tabpanel");
expect(within(open).getAllByRole("link").map((link) => link.textContent)).toEqual([
"OAuth/OIDC 인증 경계 전체 보기",
"SPA브라우저가 token 을 들고 있다",
"Mediator교환만 서버가 맡는다",
"BFF서버가 세션을 갖는다",
"Forward-Auth게이트웨이가 신원을 붙인다",
]);
expect(within(open).getByText("구조")).toBeTruthy();
});
it("탭을 고르면 그 주제의 축으로 바뀐다", async () => {
const user = userEvent.setup();
renderTabs([AUTH, JPA]);
await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" }));
const open = screen.getByRole("tabpanel");
expect(within(open).getByText("조회 전략")).toBeTruthy();
expect(
within(open)
.getAllByRole("link")
.map((link) => link.getAttribute("href")),
).toEqual([
"/topics/jpa-feed-query-performance",
"/topics/jpa-feed-query-performance/fetch-join",
"/topics/jpa-feed-query-performance/derived-query",
]);
});
it("방향키로 탭을 옮긴다", async () => {
const user = userEvent.setup();
renderTabs([AUTH, JPA]);
await user.tab();
await user.keyboard("{ArrowRight}");
expect(screen.getByRole("tab", { selected: true }).textContent).toBe(
"JPA 피드 조회 성능",
);
});
it("주제가 하나면 고를 것이 없지만 목록은 그대로 나온다", () => {
renderTabs([AUTH]);
expect(screen.queryAllByRole("tab")).toHaveLength(0);
expect(screen.getByRole("button").textContent).toBe("OAuth/OIDC 인증 경계");
expect(
screen.getAllByRole("link").map((link) => link.getAttribute("href")),
).toEqual([
"/topics/oauth-oidc-auth-boundary",
"/topics/oauth-oidc-auth-boundary/spa",
"/topics/oauth-oidc-auth-boundary/mediator",
"/topics/oauth-oidc-auth-boundary/bff",
"/topics/oauth-oidc-auth-boundary/forward-auth",
]);
});
});