Files
tolaria/src/components/ConfirmDeleteDialog.test.tsx
Test 9a7369c799 feat: trash management — bulk restore, delete permanently, empty trash
- Add ConfirmDeleteDialog for permanent deletion confirmation
- Update BulkActionBar to show contextual actions (Restore/Delete permanently
  in trash view, Archive/Trash elsewhere)
- Add Empty Trash button in note list header when viewing trash
- Add Empty Trash command to Cmd+K palette
- Add bulk restore, bulk delete permanently, and empty trash handlers
- All permanent deletions require confirmation dialog
- Update mock handlers for batch_delete_notes and empty_trash

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 00:33:44 +01:00

82 lines
2.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { ConfirmDeleteDialog } from './ConfirmDeleteDialog'
describe('ConfirmDeleteDialog', () => {
const onConfirm = vi.fn()
const onCancel = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
})
it('renders with title and message', () => {
render(
<ConfirmDeleteDialog
open={true}
title="Delete permanently?"
message="This cannot be undone."
onConfirm={onConfirm}
onCancel={onCancel}
/>,
)
expect(screen.getByText('Delete permanently?')).toBeInTheDocument()
expect(screen.getByText('This cannot be undone.')).toBeInTheDocument()
})
it('calls onConfirm when delete button clicked', () => {
render(
<ConfirmDeleteDialog
open={true}
title="Delete permanently?"
message="This cannot be undone."
onConfirm={onConfirm}
onCancel={onCancel}
/>,
)
fireEvent.click(screen.getByTestId('confirm-delete-btn'))
expect(onConfirm).toHaveBeenCalledTimes(1)
})
it('calls onCancel when cancel button clicked', () => {
render(
<ConfirmDeleteDialog
open={true}
title="Delete permanently?"
message="This cannot be undone."
onConfirm={onConfirm}
onCancel={onCancel}
/>,
)
fireEvent.click(screen.getByText('Cancel'))
expect(onCancel).toHaveBeenCalledTimes(1)
})
it('does not render when open is false', () => {
render(
<ConfirmDeleteDialog
open={false}
title="Delete permanently?"
message="This cannot be undone."
onConfirm={onConfirm}
onCancel={onCancel}
/>,
)
expect(screen.queryByText('Delete permanently?')).not.toBeInTheDocument()
})
it('uses custom confirm label when provided', () => {
render(
<ConfirmDeleteDialog
open={true}
title="Empty Trash?"
message="Delete all notes?"
confirmLabel="Empty Trash"
onConfirm={onConfirm}
onCancel={onCancel}
/>,
)
expect(screen.getByText('Empty Trash')).toBeInTheDocument()
})
})