import {describe, expect, it, vi} from 'vitest'
import {render, screen, userEvent} from '../../test-utils'
import {AlertDialogAtom} from './alert-dialog'
describe('AlertDialogAtom', () => {
const defaultProps = {
title: 'Confirm Action',
description: 'Are you sure you want to proceed?',
cancelButtonText: 'Cancel',
confirmationButtonText: 'Confirm',
open: false,
onOpenChange: vi.fn(),
onConfirmationAction: vi.fn(),
}
it('renders trigger element', () => {
render(
)
expect(
screen.getByRole('button', {name: /open dialog/i})
).toBeInTheDocument()
})
it('shows dialog content when open', () => {
render(
)
expect(screen.getByText(defaultProps.title)).toBeInTheDocument()
expect(screen.getByText(defaultProps.description)).toBeInTheDocument()
expect(
screen.getByRole('button', {name: defaultProps.cancelButtonText})
).toBeInTheDocument()
expect(
screen.getByRole('button', {name: defaultProps.confirmationButtonText})
).toBeInTheDocument()
})
it('calls onConfirmationAction when confirm button is clicked', async () => {
const user = userEvent.setup()
const onConfirmationAction = vi.fn()
render(
)
await user.click(
screen.getByRole('button', {name: defaultProps.confirmationButtonText})
)
expect(onConfirmationAction).toHaveBeenCalledTimes(1)
})
})