gongxiangp2/components/upload/ProductPackageUploader.test.tsx
chenpei 4712175cb0 feat(素材链路): 发布白底图双轨与AI生图回传能力
- 完成白底图 WebP 双轨接口、上传链路与预览缓存改造
- 新增 AI 生图平台成品回传接口、任务状态与表单规则
- 补齐 AI 生成标签、任务详情补全、相关测试与对接文档
2026-03-25 10:28:02 +08:00

82 lines
2.5 KiB
TypeScript
Raw 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.

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import ProductPackageUploader from '@/components/upload/ProductPackageUploader'
jest.mock('@/components/upload/DetailImageSorter', () => ({
__esModule: true,
default: () => <div data-testid="detail-image-sorter" />,
}))
jest.mock('@/components/upload/UploadForm', () => ({
__esModule: true,
default: () => <div data-testid="upload-form" />,
}))
jest.mock('@/components/upload/category-handlers', () => ({
addCategory: jest.fn(),
addScene: jest.fn(),
}))
const defaultProps = {
onSuccess: jest.fn(),
onCancel: jest.fn(),
categories: [],
scenes: [],
platforms: [],
productCategories: [],
onRefreshCategories: jest.fn().mockResolvedValue(undefined),
onRefreshScenes: jest.fn().mockResolvedValue(undefined),
}
describe('ProductPackageUploader', () => {
beforeEach(() => {
jest.clearAllMocks()
Object.defineProperty(URL, 'createObjectURL', {
configurable: true,
writable: true,
value: jest.fn(() => 'blob:mock'),
})
Object.defineProperty(URL, 'revokeObjectURL', {
configurable: true,
writable: true,
value: jest.fn(),
})
})
test('任务-详情源文件选择框支持 psb/tif/tiff', async () => {
const user = userEvent.setup()
render(<ProductPackageUploader {...defaultProps} />)
const input = screen.getByLabelText(/PSD源文件/) as HTMLInputElement
expect(input.accept).toBe('.psd,.psb,.tif,.tiff,.zip,.rar,.7z')
const files = [
new File(['a'], 'sample.psb', { type: 'application/octet-stream' }),
new File(['b'], 'sample.tif', { type: 'image/tiff' }),
new File(['c'], 'sample.tiff', { type: 'image/tiff' }),
]
await user.upload(input, files)
expect(screen.getByText('sample.psb')).toBeInTheDocument()
expect(screen.getByText('sample.tif')).toBeInTheDocument()
expect(screen.getByText('sample.tiff')).toBeInTheDocument()
})
test('空的任务-详情源文件会被直接拦截并提示', async () => {
const user = userEvent.setup()
render(<ProductPackageUploader {...defaultProps} />)
const input = screen.getByLabelText(/PSD源文件/) as HTMLInputElement
const emptyFile = new File([], 'empty.psd', { type: 'application/octet-stream' })
await user.upload(input, emptyFile)
expect(screen.getByText('以下文件为空,无法上传:empty.psd')).toBeInTheDocument()
expect(screen.queryByText('empty.psd')).not.toBeInTheDocument()
})
})