91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import React from "react"
|
|
import { describe, expect, it, vi } from "vitest"
|
|
import { render } from "@testing-library/react"
|
|
import { MemoryRouter } from "react-router-dom"
|
|
|
|
vi.mock("@/components/layout/PageHead", () => ({
|
|
default: ({ title }: { title: string }) => <div data-testid="page-head">{title}</div>,
|
|
}))
|
|
|
|
vi.mock("@tanstack/react-query", () => ({
|
|
useQuery: () => ({ data: [], isLoading: false, isError: false, refetch: vi.fn() }),
|
|
useMutation: () => ({ mutate: vi.fn(), mutateAsync: vi.fn(), isLoading: false }),
|
|
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
|
}))
|
|
|
|
vi.mock("@/components/ui", () => ({
|
|
Button: ({ children, onClick }: any) => <button onClick={onClick}>{children}</button>,
|
|
Input: ({ placeholder }: any) => <input placeholder={placeholder} />,
|
|
Select: ({ options }: any) => (
|
|
<select>
|
|
{options?.map((o: any) => (
|
|
<option key={o.value}>{o.label}</option>
|
|
))}
|
|
</select>
|
|
),
|
|
Modal: ({ open, children }: any) => (open ? <div role="dialog">{children}</div> : null),
|
|
Empty: () => <div>Empty</div>,
|
|
Card: ({ children }: any) => <div>{children}</div>,
|
|
Tag: ({ children }: any) => <span>{children}</span>,
|
|
Tooltip: ({ children }: any) => <span>{children}</span>,
|
|
}))
|
|
|
|
vi.mock("antd", () => ({
|
|
Modal: ({ open, children }: any) => (open ? <div role="dialog">{children}</div> : null),
|
|
message: { success: vi.fn(), error: vi.fn(), warning: vi.fn() },
|
|
Popconfirm: ({ children }: any) => <span>{children}</span>,
|
|
Form: ({ children }: any) => <form>{children}</form>,
|
|
Input: ({ placeholder }: any) => <input placeholder={placeholder} />,
|
|
InputNumber: () => <input type="number" />,
|
|
}))
|
|
|
|
vi.mock("@ant-design/icons", () => ({
|
|
PlusOutlined: () => <span />,
|
|
EditOutlined: () => <span />,
|
|
DeleteOutlined: () => <span />,
|
|
SearchOutlined: () => <span />,
|
|
FileTextOutlined: () => <span />,
|
|
CopyOutlined: () => <span />,
|
|
RobotOutlined: () => <span />,
|
|
CheckOutlined: () => <span />,
|
|
StarOutlined: () => <span />,
|
|
}))
|
|
|
|
vi.mock("@/api/titles", () => ({
|
|
getTitles: vi.fn().mockResolvedValue([]),
|
|
createTitle: vi.fn().mockResolvedValue({ success: true }),
|
|
updateTitle: vi.fn().mockResolvedValue({ success: true }),
|
|
deleteTitle: vi.fn().mockResolvedValue({ success: true }),
|
|
}))
|
|
|
|
vi.mock("@/store/authStore", () => ({
|
|
useAuthStore: (sel: any) => sel({ user: { id: "1", vip_level: 0 }, isAuthenticated: true }),
|
|
}))
|
|
|
|
vi.mock("@/pages/titles/titles.css", () => ({}))
|
|
|
|
import TitleLibrary from "@/pages/titles/TitleLibrary"
|
|
import "@/pages/titles/types/titleLibrary"
|
|
import "@/pages/titles/constants/titleLibrary"
|
|
import "@/pages/titles/utils/titleLibrary"
|
|
import "@/pages/titles/hooks/useTitleLibrary"
|
|
import "@/pages/titles/hooks/useTitleEdit"
|
|
import "@/pages/titles/hooks/useTitleAI"
|
|
import "@/pages/titles/components/title-library/TitleCard"
|
|
import "@/pages/titles/components/title-library/CategorySidebar"
|
|
import "@/pages/titles/components/title-library/FilterBar"
|
|
import "@/pages/titles/components/title-library/TitleGrid"
|
|
import "@/pages/titles/components/title-library/CreateTitleModal"
|
|
import "@/pages/titles/components/title-library/AIGenerateModal"
|
|
|
|
describe("TitleLibrary Page", () => {
|
|
it("should render without crashing", () => {
|
|
const { container } = render(
|
|
<MemoryRouter>
|
|
<TitleLibrary />
|
|
</MemoryRouter>,
|
|
)
|
|
expect(container.firstChild).toBeTruthy()
|
|
})
|
|
})
|