feat(notes): add note deletion with confirmation
This commit is contained in:
1 parent
0976c51cc1
commit
0af0cdc405
4 files changed
+142
-4
No files matched your search
@@ -7,8 +7,9 @@ const note: Note = { id: 42, title: 'Courses', content: 'Lait\nOeufs' }
|
||||
|
||||
const renderEditor = (overrides: Partial<Note> = {}) => {
|
||||
const onUpdate = vi.fn()
|
||||
render(<NoteEditor note={{ ...note, ...overrides }} onUpdate={onUpdate} />)
|
||||
return { onUpdate }
|
||||
const onDelete = vi.fn()
|
||||
render(<NoteEditor note={{ ...note, ...overrides }} onUpdate={onUpdate} onDelete={onDelete} />)
|
||||
return { onUpdate, onDelete }
|
||||
}
|
||||
|
||||
describe('NoteEditor', () => {
|
||||
@@ -70,4 +71,33 @@ describe('NoteEditor', () => {
|
||||
expect(onUpdate).not.toHaveBeenCalled()
|
||||
expect(screen.getByText('Courses')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens the delete confirmation when the × button is clicked', () => {
|
||||
renderEditor()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Supprimer la note' }))
|
||||
|
||||
expect(screen.getByRole('dialog', { name: 'Supprimer la note ?' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('deletes the note after confirmation', () => {
|
||||
const { onDelete } = renderEditor()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Supprimer la note' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||
|
||||
expect(onDelete).toHaveBeenCalledWith(42)
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not delete when the confirmation is cancelled', () => {
|
||||
const { onDelete } = renderEditor()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Supprimer la note' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Annuler' }))
|
||||
|
||||
expect(onDelete).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user