75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { render, screen, waitFor } from '@testing-library/react'
|
||
import userEvent from '@testing-library/user-event'
|
||
|
||
import UploadModal from '@/components/UploadModal'
|
||
|
||
jest.mock('next/image', () => ({
|
||
__esModule: true,
|
||
default: (props: any) => {
|
||
const { priority, fill, unoptimized, sizes, ...rest } = props
|
||
return <img {...rest} />
|
||
},
|
||
}))
|
||
|
||
jest.mock('@/hooks/useCategoryData', () => ({
|
||
useCategoryData: () => ({
|
||
data: {
|
||
categories: [],
|
||
scenes: [],
|
||
platforms: [],
|
||
productCategories: [],
|
||
},
|
||
refreshCategories: jest.fn(),
|
||
refreshScenes: jest.fn(),
|
||
}),
|
||
}))
|
||
|
||
jest.mock('@/components/upload/ProductPackageUploader', () => ({
|
||
__esModule: true,
|
||
default: () => <div data-testid="product-package-uploader" />,
|
||
}))
|
||
|
||
jest.mock('@/components/upload/VideoScreenshotUploader', () => ({
|
||
__esModule: true,
|
||
default: () => <div data-testid="video-screenshot-uploader" />,
|
||
}))
|
||
|
||
jest.mock('@/components/upload/TaskPageUploader', () => ({
|
||
__esModule: true,
|
||
default: () => <div data-testid="task-page-uploader" />,
|
||
}))
|
||
|
||
describe('UploadModal - 任务-其他', () => {
|
||
beforeEach(() => {
|
||
jest.clearAllMocks()
|
||
|
||
global.fetch = jest.fn().mockResolvedValue({
|
||
ok: true,
|
||
json: async () => ({
|
||
materialTypes: ['3D场景', '任务-其他'],
|
||
}),
|
||
}) as any
|
||
})
|
||
|
||
test('任务-其他应使用公共上传面板形式,只保留任务号 + 预览图片 + 素材文件', async () => {
|
||
const user = userEvent.setup()
|
||
|
||
render(<UploadModal onClose={jest.fn()} onSuccess={jest.fn()} />)
|
||
|
||
const materialTypeSelect = (await screen.findAllByRole('combobox'))[0]
|
||
await user.selectOptions(materialTypeSelect, '任务-其他')
|
||
|
||
await waitFor(() => {
|
||
expect(screen.getByLabelText('任务号 *')).toBeInTheDocument()
|
||
})
|
||
|
||
expect(screen.getByText('预览图片 *')).toBeInTheDocument()
|
||
expect(screen.getByText('素材文件 *')).toBeInTheDocument()
|
||
expect(screen.getByText('支持格式:压缩包(.zip / .rar / .7z)')).toBeInTheDocument()
|
||
|
||
expect(screen.queryByLabelText('SPU型号 *')).not.toBeInTheDocument()
|
||
expect(screen.queryByText('压缩包源文件 *')).not.toBeInTheDocument()
|
||
expect(screen.queryByText('预览图 *')).not.toBeInTheDocument()
|
||
})
|
||
})
|