feat(ai-character): 관리자 인증 셸 구현
This commit is contained in:
42
src/shared/ui/__tests__/resource-pagination.test.tsx
Normal file
42
src/shared/ui/__tests__/resource-pagination.test.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { expect, test, vi } from "vitest";
|
||||
|
||||
import type { PageData } from "@/shared/api/pagination";
|
||||
import { ResourcePagination } from "@/shared/ui/resource-pagination";
|
||||
|
||||
const pageData: PageData<string> = {
|
||||
totalCount: 42,
|
||||
page: 1,
|
||||
size: 20,
|
||||
hasNext: true,
|
||||
items: [],
|
||||
};
|
||||
|
||||
test("ResourcePagination uses PageData and real buttons for accessible page movement", () => {
|
||||
const onPageChange = vi.fn();
|
||||
const onSizeChange = vi.fn();
|
||||
|
||||
render(<ResourcePagination data={pageData} onPageChange={onPageChange} onSizeChange={onSizeChange} />);
|
||||
|
||||
const previous = screen.getByRole("button", { name: "이전 페이지" });
|
||||
const next = screen.getByRole("button", { name: "다음 페이지" });
|
||||
|
||||
expect(previous.tagName).toBe("BUTTON");
|
||||
expect(next).toBeEnabled();
|
||||
expect(screen.getByText("총 42개 · 2페이지")).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(previous);
|
||||
fireEvent.click(next);
|
||||
fireEvent.change(screen.getByLabelText("페이지 크기"), { target: { value: "50" } });
|
||||
|
||||
expect(onPageChange).toHaveBeenNthCalledWith(1, 0);
|
||||
expect(onPageChange).toHaveBeenNthCalledWith(2, 2);
|
||||
expect(onSizeChange).toHaveBeenCalledWith(50);
|
||||
});
|
||||
|
||||
test("ResourcePagination disables unavailable previous and next actions", () => {
|
||||
render(<ResourcePagination data={{ ...pageData, page: 0, hasNext: false }} onPageChange={vi.fn()} onSizeChange={vi.fn()} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "이전 페이지" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "다음 페이지" })).toBeDisabled();
|
||||
});
|
||||
Reference in New Issue
Block a user