Files
faunosteo/apps/app/tests/unit/routes.NewReportRoute.test.tsx
T

41 lines
1.2 KiB
TypeScript

/** The new-report form on the bundled sheet: species select, submit gate. */
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { cleanup, render, screen, waitFor } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import NewReportRoute from '@/app/routes/NewReportRoute'
import { useLocaleStore } from '@/state/localeStore'
import { fr } from '@/i18n/fr'
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
localStorage.clear()
})
afterEach(cleanup)
function mount() {
return render(
<MemoryRouter initialEntries={['/new']}>
<NewReportRoute />
</MemoryRouter>,
)
}
describe('NewReportRoute', () => {
it('selects equine and names it once the sheet is loaded', async () => {
mount()
const select = screen.getByLabelText(
fr['form.animal.species'],
) as HTMLSelectElement
await waitFor(() => {
expect(select.value).toBe('equine')
expect(select.selectedOptions[0]?.textContent).toBe('Cheval')
})
})
it('disables submit while the names are empty', async () => {
mount()
const button = screen.getByRole('button', { name: fr['new_report.submit'] })
await waitFor(() => expect(button).toBeDisabled())
})
})