feat(notes): add note deletion with confirmation

This commit is contained in:
devcodetools committed 2026-09-13 15:32:33 +02:00
1 parent 0976c51cc1
commit 0af0cdc405
4 files changed
+142 -4

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { fireEvent, render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import DeleteModal from './DeleteModal'
describe('DeleteModal', () => {
it('renders nothing when closed', () => {
render(<DeleteModal open={false} title="Courses" onConfirm={vi.fn()} onCancel={vi.fn()} />)
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
})
it('renders the dialog with the note title when open', () => {
render(<DeleteModal open title="Courses" onConfirm={vi.fn()} onCancel={vi.fn()} />)
expect(screen.getByRole('dialog', { name: 'Supprimer la note ?' })).toBeInTheDocument()
expect(screen.getByText(/Courses/)).toBeInTheDocument()
})
it('shows a placeholder when the note has no title', () => {
render(<DeleteModal open title="" onConfirm={vi.fn()} onCancel={vi.fn()} />)
expect(screen.getByText(/Sans titre/)).toBeInTheDocument()
})
it('calls onConfirm when the confirm button is clicked', () => {
const onConfirm = vi.fn()
render(<DeleteModal open title="Courses" onConfirm={onConfirm} onCancel={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: 'Supprimer' }))
expect(onConfirm).toHaveBeenCalled()
})
it('calls onCancel when the cancel button is clicked', () => {
const onCancel = vi.fn()
render(<DeleteModal open title="Courses" onConfirm={vi.fn()} onCancel={onCancel} />)
fireEvent.click(screen.getByRole('button', { name: 'Annuler' }))
expect(onCancel).toHaveBeenCalled()
})
})