07d9b56fe7
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
120 lines
4.4 KiB
TypeScript
Executable File
120 lines
4.4 KiB
TypeScript
Executable File
// 重构:DuplicationUpload 页面已拆分为子组件(UploadZone/InfoSidebar/UploadProgress等)
|
|
import { describe, expect, it, vi, beforeEach } from "vitest"
|
|
import {
|
|
uploadForDuplication,
|
|
getDuplicationRecords,
|
|
getDuplicationDetail,
|
|
deleteDuplicationRecord,
|
|
retryDuplication,
|
|
} from "@/api/duplication"
|
|
|
|
const mockGet = vi.fn()
|
|
const mockPost = vi.fn()
|
|
const mockPut = vi.fn()
|
|
const mockDelete = vi.fn()
|
|
const mockPatch = vi.fn()
|
|
|
|
vi.mock("@/api/client", () => ({
|
|
default: {
|
|
get: (...args: unknown[]) => mockGet(...args),
|
|
post: (...args: unknown[]) => mockPost(...args),
|
|
put: (...args: unknown[]) => mockPut(...args),
|
|
delete: (...args: unknown[]) => mockDelete(...args),
|
|
patch: (...args: unknown[]) => mockPatch(...args),
|
|
},
|
|
}))
|
|
|
|
vi.mock("antd", () => ({ message: { error: vi.fn(), success: vi.fn() } }))
|
|
vi.mock("@/store/authStore", () => ({ useAuthStore: { getState: vi.fn(() => ({})) } }))
|
|
|
|
describe("duplication API", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockGet.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPost.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPut.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockDelete.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPatch.mockResolvedValue({ data: { success: true, items: [] } })
|
|
})
|
|
|
|
describe("uploadForDuplication", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(uploadForDuplication(new File(["test"], "test.txt"))).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(uploadForDuplication(new File(["test"], "test.txt"))).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("getDuplicationRecords", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getDuplicationRecords()).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(getDuplicationRecords()).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("getDuplicationDetail", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getDuplicationDetail("test-recordId")).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(getDuplicationDetail("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("deleteDuplicationRecord", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(deleteDuplicationRecord("test-recordId")).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(deleteDuplicationRecord("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("retryDuplication", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(retryDuplication("test-recordId")).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(retryDuplication("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
})
|