280db0b862
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m19s
CI/CD Pipeline / Frontend Lint (push) Successful in 4m24s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 4m48s
CI/CD Pipeline / Unit Tests (push) Successful in 5m28s
CI/CD Pipeline / Integration Tests (push) Successful in 1m34s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 53s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 6m43s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 1m48s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 8m36s
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 1m14s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m3s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
129 lines
5.0 KiB
TypeScript
129 lines
5.0 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(), setQueryData: vi.fn() }),
|
|
useInfiniteQuery: () => ({
|
|
data: { pages: [] },
|
|
isLoading: false,
|
|
fetchNextPage: vi.fn(),
|
|
hasNextPage: false,
|
|
}),
|
|
}))
|
|
|
|
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>,
|
|
Upload: ({ children }: any) => <div>{children}</div>,
|
|
Progress: () => <div />,
|
|
}))
|
|
|
|
vi.mock("antd", () => ({
|
|
Table: () => <div />,
|
|
Pagination: () => <div />,
|
|
Tabs: () => <div />,
|
|
Modal: ({ open, children }: any) => (open ? <div role="dialog">{children}</div> : null),
|
|
message: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() },
|
|
Popconfirm: ({ children }: any) => <span>{children}</span>,
|
|
Form: ({ children }: any) => <form>{children}</form>,
|
|
Input: ({ placeholder }: any) => <input placeholder={placeholder} />,
|
|
InputNumber: () => <input type="number" />,
|
|
Select: () => <select />,
|
|
Empty: () => <div>Empty</div>,
|
|
Space: ({ children }: any) => <div>{children}</div>,
|
|
Tag: ({ children }: any) => <span>{children}</span>,
|
|
Badge: ({ children }: any) => <span>{children}</span>,
|
|
Tooltip: ({ children }: any) => <span>{children}</span>,
|
|
Upload: ({ children }: any) => <div>{children}</div>,
|
|
Progress: () => <div />,
|
|
Switch: () => <input type="checkbox" />,
|
|
Radio: ({ children }: any) => <span>{children}</span>,
|
|
RadioGroup: ({ children }: any) => <div>{children}</div>,
|
|
Checkbox: ({ children }: any) => (
|
|
<label>
|
|
<input type="checkbox" />
|
|
{children}
|
|
</label>
|
|
),
|
|
DatePicker: () => <input type="date" />,
|
|
Col: ({ children }: any) => <div>{children}</div>,
|
|
Row: ({ children }: any) => <div>{children}</div>,
|
|
Card: ({ children }: any) => <div>{children}</div>,
|
|
List: () => <ul />,
|
|
Grid: { useBreakpoint: () => ({ xs: true, sm: true, md: true, lg: true }) },
|
|
Descriptions: ({ children }: any) => <div>{children}</div>,
|
|
Divider: () => <hr />,
|
|
Avatar: () => <span />,
|
|
Dropdown: ({ children }: any) => <span>{children}</span>,
|
|
Menu: ({ children }: any) => <ul>{children}</ul>,
|
|
Drawer: ({ open, children }: any) => (open ? <div>{children}</div> : null),
|
|
Typography: {
|
|
Title: ({ children }: any) => <h2>{children}</h2>,
|
|
Text: ({ children }: any) => <span>{children}</span>,
|
|
Paragraph: ({ children }: any) => <p>{children}</p>,
|
|
},
|
|
Spin: ({ spinning }: any) => (spinning ? <div>Loading...</div> : <></>),
|
|
Slider: () => <input type="range" />,
|
|
Rate: () => <div />,
|
|
Collapse: ({ children }: any) => <div>{children}</div>,
|
|
Steps: ({ children }: any) => <div>{children}</div>,
|
|
Button: ({ children }: any) => <button>{children}</button>,
|
|
}))
|
|
|
|
vi.mock("@ant-design/icons", () => ({
|
|
CopyOutlined: () => <span />,
|
|
ExclamationCircleOutlined: () => <span />,
|
|
InboxOutlined: () => <span />,
|
|
LoadingOutlined: () => <span />,
|
|
SearchOutlined: () => <span />,
|
|
ThunderboltOutlined: () => <span />,
|
|
}))
|
|
|
|
vi.mock("@/store/authStore", () => ({
|
|
useAuthStore: (sel: any) => sel({ user: { id: "1", vip_level: 0 }, isAuthenticated: true }),
|
|
}))
|
|
|
|
vi.mock("@/api/templates", () => ({
|
|
getTemplates: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
getTemplatesList: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
getTemplate: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
toggleFavoriteTemplate: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
copyTemplate: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
generateFromTemplate: vi.fn().mockResolvedValue({ items: [], total: 0, success: true }),
|
|
}))
|
|
|
|
vi.mock("@/pages/templates/TemplateLibrary.css", () => ({}))
|
|
|
|
import TemplateLibrary from "@/pages/templates/TemplateLibrary"
|
|
|
|
describe("TemplateLibrary Page", () => {
|
|
it("should render without crashing", () => {
|
|
const { container } = render(
|
|
<MemoryRouter>
|
|
<TemplateLibrary />
|
|
</MemoryRouter>,
|
|
)
|
|
expect(container.firstChild).toBeTruthy()
|
|
})
|
|
})
|