Files
memento-frontend/tests/component/memento-design-system.test.tsx

94 lines
2.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import { fireEvent, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it, vi } from "vitest";
import {
MementoBadge,
MementoButton,
MementoChip,
MementoIconButton,
} from "../../src/presentation/design-system/index.ts";
import { LibraryMediaGrid } from "../../src/features/memento-web/presentation/components/media-components.tsx";
import { MemoryItem } from "../../src/features/memento-web/presentation/components/memory-components.tsx";
describe("Memento design-system product variants", () => {
it("keeps the Memento visual classes while reusing template primitives", () => {
render(
<>
<MementoButton visual="primary">저장</MementoButton>
<MementoChip active>공유 중</MementoChip>
<MementoBadge accent>진행 중</MementoBadge>
<MementoIconButton accessibleName="닫기">
<span aria-hidden="true">×</span>
</MementoIconButton>
</>,
);
expect(screen.getByRole("button", { name: "저장" })).toHaveClass(
"btn",
"primary",
);
expect(screen.getByRole("button", { name: "공유 중" })).toHaveClass(
"chip",
"active",
);
expect(screen.getByText("진행 중")).toHaveClass("badge", "accent");
expect(screen.getByRole("button", { name: "닫기" })).toHaveClass(
"icon-btn",
);
expect(screen.getByRole("button", { name: "저장" })).not.toHaveClass(
"ui-button",
);
});
it("renders product memory/album card semantics behind router navigation", () => {
const { container } = render(
<MemoryRouter>
<div className="memento-app">
<MemoryItem
id="album-family"
title="가족 사진"
meta="124개 · 최근 수정 9월 14일"
photo={6}
count={124}
type="Album"
album
shared
/>
</div>
</MemoryRouter>,
);
expect(screen.getByText("가족 사진")).toBeVisible();
expect(screen.getByText("공유 Album")).toBeVisible();
expect(container.querySelector(".memory-item.album-list-item")).not.toBeNull();
});
it("keeps media selection controlled by React state callbacks", () => {
const onToggle = vi.fn();
const selected = new Set<string>(["0-0"]);
const { container } = render(
<div className="memento-app">
<LibraryMediaGrid
group={0}
offset={0}
hiddenMode="none"
selected={selected}
onToggle={onToggle}
/>
</div>,
);
const first = container.querySelector<HTMLElement>(
'.media-tile[data-key="0-0"]',
);
expect(first).not.toBeNull();
expect(first).toHaveClass("selected");
fireEvent.click(first!);
expect(onToggle).toHaveBeenCalledWith("0-0");
});
});