test: strengthen TechLog shell contracts

This commit is contained in:
DongHyeonka
2026-08-15 21:42:49 +09:00
parent 627df884dd
commit 3bc74e0195
2 changed files with 96 additions and 9 deletions
+56 -9
View File
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
import { fireEvent, render, screen, within } from "@testing-library/react";
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createMemoryRouter, RouterProvider } from "react-router-dom";
@@ -94,20 +94,26 @@ describe("TechLog Public shell", () => {
expect(
screen.getByRole("navigation", { name: "모바일 주요 탐색" }),
).toBeInTheDocument();
const expectedNavigation = [
["탐색", "/explore"],
["프로젝트", "/projects"],
["변경 기록", "/releases"],
["프로필", "/profile"],
];
expect(
Array.from(
view.container.querySelectorAll<HTMLAnchorElement>(".desktop-nav a"),
(link) => link.textContent,
(link) => [link.textContent, link.getAttribute("href")],
),
).toEqual(["탐색", "프로젝트", "변경 기록", "프로필"]);
).toEqual(expectedNavigation);
expect(
Array.from(
view.container.querySelectorAll<HTMLAnchorElement>(
".mobile-nav nav a",
),
(link) => link.textContent,
(link) => [link.textContent, link.getAttribute("href")],
),
).toEqual(["탐색", "프로젝트", "변경 기록", "프로필"]);
).toEqual(expectedNavigation);
for (const link of screen.getAllByRole("link", { name: "프로젝트" })) {
expect(link).toHaveAttribute("aria-current", "page");
}
@@ -182,7 +188,26 @@ describe("TechLog Public shell", () => {
expect(router.state.location.pathname).toBe("/projects/auth-lab");
});
it("closes mobile navigation on Escape and before opening the one search dialog", async () => {
it("navigates the full-search action with its canonical query intact", async () => {
const user = userEvent.setup();
const { router } = renderShell();
await user.click(
screen.getByRole("button", { name: "TechLog 검색 열기" }),
);
await user.type(
screen.getByRole("searchbox", { name: "검색어" }),
"Keycloak",
);
await user.click(
screen.getByRole("link", { name: /전체 검색 결과 보기/ }),
);
expect(router.state.location.pathname).toBe("/search");
expect(router.state.location.search).toBe("?q=Keycloak");
});
it("uses native mobile disclosure activation and closes it after selection", async () => {
const user = userEvent.setup();
const view = renderShell();
const details = view.container.querySelector<HTMLDetailsElement>(
@@ -192,12 +217,34 @@ describe("TechLog Public shell", () => {
expect(details).not.toBeNull();
expect(summary).not.toBeNull();
details!.open = true;
fireEvent.keyDown(details!, { key: "Escape" });
await user.click(summary!);
expect(details).toHaveAttribute("open");
await user.click(
within(details!).getByRole("link", { name: "탐색" }),
);
expect(details).not.toHaveAttribute("open");
await user.click(summary!);
expect(details).toHaveAttribute("open");
summary!.focus();
await user.keyboard("{Escape}");
expect(details).not.toHaveAttribute("open");
expect(summary).toHaveFocus();
});
details!.open = true;
it("closes a natively opened mobile disclosure before opening one search dialog", async () => {
const user = userEvent.setup();
const view = renderShell();
const details = view.container.querySelector<HTMLDetailsElement>(
"details.mobile-nav",
);
const summary = details?.querySelector<HTMLElement>("summary");
expect(details).not.toBeNull();
expect(summary).not.toBeNull();
await user.click(summary!);
expect(details).toHaveAttribute("open");
await user.click(
screen.getByRole("button", { name: "TechLog 검색 열기" }),
);