fix: 주제 탭을 칩 크기로 줄이고 개수 상한을 없앤다
탭을 구역 제목 급(30px/650)으로 세웠다. 주제가 둘일 때는 그럴듯했지만 열 개, 스무 개가 되면 이름만으로 화면이 덮인다 — 여기서 하려는 말은 「이것이 이 구역의 제목이다」가 아니라 「고를 것이 이만큼 있다」이므로 급도 그쪽이어야 한다. 지금 무엇을 읽는지는 목록 바로 위의 축 이름과 「전체 보기」 줄이 말한다. 고른 탭의 파란 밑줄도 없앤다. 주제가 스무 개면 밑줄이 설 자리 스무 개가 함께 늘어선다. 고르지 않은 것은 색만 죽인다. 개수 상한도 없앤다. 상한은 주제마다 상세를 미리 받느라 둔 것이었는데, 그러면 상한 밖의 주제는 다시 「다른 주제 N개 보기」로 밀린다 — 이 구역이 없애려던 문제로 되돌아간다. 탭은 목록이 주는 전부이고, 상세는 고른 것만 그때 받는다. 요청은 목록 하나 + 처음 열린 주제 하나로 고정되고, 주제가 늘어도 그대로다. 받지 못한 주제는 그 자리에 남긴다. 홈이 두 읽기를 `Promise.all` 로 묶었을 때는 하나가 실패하면 나머지까지 통째로 사라져 흔적이 없었다.
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
|
||||
import type { PublicTopicDetail } from "../../../src/features/tech-log/application/ports/public-content-queries.ts";
|
||||
import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
|
||||
import type {
|
||||
PublicTopic,
|
||||
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";
|
||||
import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx";
|
||||
import { createTestApplication } from "../../helpers/create-test-application.ts";
|
||||
import { renderWithQueryProviders } from "../../helpers/query-providers.tsx";
|
||||
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
|
||||
|
||||
/**
|
||||
* 홈이 주제 하나만 펴 두던 동안, 나머지로 가는 길은 비교 목록 밑의 작은 글씨 한 줄뿐이었다 —
|
||||
@@ -50,17 +58,52 @@ const JPA = topic("jpa-feed-query-performance", "JPA 피드 조회 성능", "조
|
||||
["derived-query", "Derived Query", "쿼리가 나뉜다"],
|
||||
]);
|
||||
|
||||
function renderTabs(topics: ReadonlyArray<PublicTopicDetail>) {
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<HomeTopicTabs topics={topics} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
/** 목록이 주는 만큼. 탭은 상세 없이 이것만으로 그려져야 한다. */
|
||||
function listItem(detail: PublicTopicDetail, recordCount: number): PublicTopic {
|
||||
return {
|
||||
name: detail.name,
|
||||
slug: detail.slug,
|
||||
thesis: "",
|
||||
description: "",
|
||||
variantLabel: detail.variantLabel,
|
||||
variantCount: detail.variants.length,
|
||||
recordCount,
|
||||
};
|
||||
}
|
||||
|
||||
function renderTabs(
|
||||
topics: ReadonlyArray<PublicTopic>,
|
||||
firstDetail: PublicTopicDetail,
|
||||
getTopicDetail = vi.fn(async (slug: string) =>
|
||||
[AUTH, JPA].find((detail) => detail.slug === slug),
|
||||
),
|
||||
) {
|
||||
const techLog = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input;
|
||||
const application = createTestApplication({
|
||||
featureInputs: {
|
||||
"tech-log": {
|
||||
...techLog,
|
||||
publicContent: { ...techLog.publicContent, getTopicDetail },
|
||||
},
|
||||
},
|
||||
});
|
||||
render(
|
||||
renderWithQueryProviders(
|
||||
<ApplicationProvider application={application}>
|
||||
<MemoryRouter>
|
||||
<HomeTopicTabs topics={topics} firstDetail={firstDetail} />
|
||||
</MemoryRouter>
|
||||
</ApplicationProvider>,
|
||||
),
|
||||
);
|
||||
return { getTopicDetail };
|
||||
}
|
||||
|
||||
const TABS = [listItem(AUTH, 18), listItem(JPA, 3)];
|
||||
|
||||
describe("홈의 주제 탭", () => {
|
||||
it("주제 이름이 목록보다 먼저 전부 보인다", () => {
|
||||
renderTabs([AUTH, JPA]);
|
||||
renderTabs(TABS, AUTH);
|
||||
|
||||
expect(screen.getAllByRole("tab").map((tab) => tab.textContent)).toEqual([
|
||||
"OAuth/OIDC 인증 경계",
|
||||
@@ -68,8 +111,10 @@ describe("홈의 주제 탭", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("첫 주제의 축이 열려 있고 나머지 주제의 축은 감춰져 있다", () => {
|
||||
renderTabs([AUTH, JPA]);
|
||||
it("첫 주제의 축은 미리 받아 둔 것으로 곧바로 열린다", () => {
|
||||
const { getTopicDetail } = renderTabs(TABS, AUTH);
|
||||
|
||||
expect(getTopicDetail).not.toHaveBeenCalled();
|
||||
|
||||
const open = screen.getByRole("tabpanel");
|
||||
expect(within(open).getAllByRole("link").map((link) => link.textContent)).toEqual([
|
||||
@@ -82,28 +127,59 @@ describe("홈의 주제 탭", () => {
|
||||
expect(within(open).getByText("구조")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("탭을 고르면 그 주제의 축으로 바뀐다", async () => {
|
||||
it("고른 주제의 상세만 그때 받는다", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderTabs([AUTH, JPA]);
|
||||
const { getTopicDetail } = renderTabs(TABS, AUTH);
|
||||
|
||||
await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" }));
|
||||
|
||||
expect(getTopicDetail).toHaveBeenCalledExactlyOnceWith("jpa-feed-query-performance");
|
||||
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",
|
||||
]);
|
||||
await waitFor(() =>
|
||||
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();
|
||||
const { getTopicDetail } = renderTabs(TABS, AUTH);
|
||||
|
||||
await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" }));
|
||||
await screen.findByText("조회 전략");
|
||||
await user.click(screen.getByRole("tab", { name: "OAuth/OIDC 인증 경계" }));
|
||||
await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" }));
|
||||
|
||||
expect(getTopicDetail).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("받지 못하면 그 자리에 남긴다 — 목록만 사라지지 않는다", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderTabs(
|
||||
TABS,
|
||||
AUTH,
|
||||
vi.fn(async () => {
|
||||
throw new Error("불통");
|
||||
}),
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" }));
|
||||
|
||||
expect(await screen.findByText("이 주제를 지금 불러오지 못했습니다.")).toBeTruthy();
|
||||
expect(screen.getAllByRole("tab")).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("방향키로 탭을 옮긴다", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderTabs([AUTH, JPA]);
|
||||
renderTabs(TABS, AUTH);
|
||||
|
||||
await user.tab();
|
||||
await user.keyboard("{ArrowRight}");
|
||||
@@ -114,7 +190,7 @@ describe("홈의 주제 탭", () => {
|
||||
});
|
||||
|
||||
it("주제가 하나면 고를 것이 없지만 목록은 그대로 나온다", () => {
|
||||
renderTabs([AUTH]);
|
||||
renderTabs([listItem(AUTH, 18)], AUTH);
|
||||
|
||||
expect(screen.queryAllByRole("tab")).toHaveLength(0);
|
||||
expect(screen.getByRole("button").textContent).toBe("OAuth/OIDC 인증 경계");
|
||||
|
||||
@@ -17,18 +17,11 @@ const RAW = readFileSync("src/features/tech-log/presentation/styles/globals.css"
|
||||
*/
|
||||
const CSS = RAW.replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/gu, "");
|
||||
|
||||
/**
|
||||
* 나란히 서는 구역 제목들. 정본이 맨 앞이다.
|
||||
*
|
||||
* <p>홈의 주제 탭은 h2 가 아니지만 구역 제목이 서 있던 자리를 그대로 물려받았다. 태그가 다르다는
|
||||
* 이유로 급을 따로 정하면 같은 자리에 있는 글자가 화면마다 다른 크기로 나온다 — 이 검사가 처음
|
||||
* 잡은 것이 바로 그 일이다.
|
||||
*/
|
||||
/** 나란히 서는 구역 제목들. 정본이 맨 앞이다. */
|
||||
const SECTION_HEADINGS = [
|
||||
".section-heading-row h2",
|
||||
".document-relations h2",
|
||||
".topic-variants h2",
|
||||
".home-topic-tabs button",
|
||||
] as const;
|
||||
|
||||
/** 마지막으로 선언된 값을 읽는다 — 뒤에 오는 규칙이 이긴다. */
|
||||
|
||||
Reference in New Issue
Block a user