test(ui): couvrir les pages Cartes, détail, édition et Jeu + page de création manquante (P4, F-05 à F-10)
This commit is contained in:
1 parent
61eef32c74
commit
9a62743e6f
5 files changed
+172
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import EditCardPage from './page'
|
||||
|
||||
vi.mock('@/lib/api-client', () => {
|
||||
class ApiClientErrorMock extends Error {
|
||||
status: number
|
||||
constructor(status: number, name: string, message: string) {
|
||||
super(message)
|
||||
this.name = name
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
return {
|
||||
ApiClientError: ApiClientErrorMock,
|
||||
cardsApi: { get: vi.fn() },
|
||||
}
|
||||
})
|
||||
|
||||
const notFoundMock = vi.fn()
|
||||
vi.mock('next/navigation', () => ({
|
||||
useRouter: () => ({ push: vi.fn(), refresh: vi.fn() }),
|
||||
notFound: () => notFoundMock(),
|
||||
}))
|
||||
|
||||
import { ApiClientError, cardsApi } from '@/lib/api-client'
|
||||
|
||||
const CARD = {
|
||||
id: '1',
|
||||
question: 'Cest quoi un commit ?',
|
||||
response: 'Un snapshot',
|
||||
theme: 'git',
|
||||
tags: [],
|
||||
createdAt: new Date('2026-01-01T08:00:00Z'),
|
||||
updatedAt: new Date('2026-01-01T08:00:00Z'),
|
||||
}
|
||||
|
||||
describe('EditCardPage', () => {
|
||||
it('pré-remplit le formulaire depuis la carte (F-06)', async () => {
|
||||
vi.mocked(cardsApi.get).mockResolvedValue(CARD)
|
||||
const element = await EditCardPage({ params: Promise.resolve({ id: '1' }) })
|
||||
render(element)
|
||||
expect(screen.getByLabelText('Question')).toHaveValue('Cest quoi un commit ?')
|
||||
expect(screen.getByLabelText('R\u00e9ponse')).toHaveValue('Un snapshot')
|
||||
expect(screen.getByRole('button', { name: 'Enregistrer' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('déclenche notFound si la carte est inconnue', async () => {
|
||||
notFoundMock.mockImplementation(() => {
|
||||
throw new Error('not-found')
|
||||
})
|
||||
vi.mocked(cardsApi.get).mockRejectedValue(
|
||||
new ApiClientError(404, 'NotFoundError', 'Carte introuvable'),
|
||||
)
|
||||
await expect(EditCardPage({ params: Promise.resolve({ id: 'x' }) })).rejects.toThrow(
|
||||
'not-found',
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user