Files
ims/tests/components/capa/submit-verification-form.test.tsx
T
2026-10-14 11:12:22 +08:00

28 lines
1.1 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { SubmitVerificationForm } from '@/components/capa/submit-verification-form'
vi.mock('next/navigation', () => ({
useRouter: () => ({ refresh: vi.fn() }),
}))
function button() {
return screen.getByRole('button', { name: 'Submit for Verification' }) as HTMLButtonElement
}
describe('SubmitVerificationForm', () => {
it('is disabled until a note and a photo are provided', () => {
const { container } = render(<SubmitVerificationForm capaId="abc" />)
expect(button().disabled).toBe(true)
fireEvent.change(screen.getByLabelText('Completion note'), { target: { value: 'Rack fixed' } })
expect(button().disabled).toBe(true)
const input = container.querySelector('input[type="file"]') as HTMLInputElement
const file = new File(['x'], 'proof.jpg', { type: 'image/jpeg' })
fireEvent.change(input, { target: { files: [file] } })
expect(button().disabled).toBe(false)
expect(screen.getByText('proof.jpg')).toBeTruthy()
})
})