阳菜,放晴! | 7e1e3a5 | 2025-06-05 23:00:51 +0800 | [diff] [blame] | 1 | // test/upload.test.tsx |
| 2 | import React from 'react' |
| 3 | import { render, screen, fireEvent } from '@testing-library/react' |
| 4 | import UploadComponent from '@/components/upload/upload' |
| 5 | import '@testing-library/jest-dom' |
| 6 | |
| 7 | describe('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 | }) |