blob: c36eb68f402749bdff0324ce626fe590db94529b [file] [log] [blame]
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +08001// test/upload.test.tsx
2import React from 'react'
3import { render, screen, fireEvent } from '@testing-library/react'
4import UploadComponent from '@/components/upload/upload'
5import '@testing-library/jest-dom'
6
7describe('UploadComponent', () => {
8 it('should render upload component correctly', () => {
9 render(<UploadComponent />)
10
11 const input = screen.getByTestId('upload-input')
12 const uploadButton = screen.getByTestId('upload-button')
13
14 expect(input).toBeInTheDocument()
15 expect(uploadButton).toBeInTheDocument()
16 })
17
18 it('should update selected file on file change', () => {
19 render(<UploadComponent />)
20
21 const input = screen.getByTestId('upload-input') as HTMLInputElement
22 const file = new File(['hello'], 'hello.png', { type: 'image/png' })
23
24 fireEvent.change(input, { target: { files: [file] } })
25 expect(input.files?.[0]).toEqual(file)
26 })
27})