import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { Modal } from '@/components/ui/modal'
describe('Modal (Modernist dialog)', () => {
it('renders nothing when closed', () => {
const { container } = render(
{}} title="T">
body
,
)
expect(container.firstChild).toBeNull()
})
it('renders a dialog with title, body and footer on the surface fill', () => {
render(
{}} title="Confirm" footer={actions}>
body text
,
)
const dialog = screen.getByRole('dialog')
expect(dialog).toBeTruthy()
expect(screen.getByText('Confirm')).toBeTruthy()
expect(screen.getByText('body text')).toBeTruthy()
expect(screen.getByText('actions')).toBeTruthy()
expect(dialog.innerHTML).toContain('bg-surface')
expect(dialog.innerHTML).toContain('shadow-lg')
})
it('has no rounded corners and uses a 2px title rule', () => {
render(
{}} title="T">
x
,
)
const html = screen.getByRole('dialog').innerHTML
expect(html).not.toMatch(/rounded/)
expect(html).toContain('border-b')
})
it('closes from the X button and on Escape', () => {
const onClose = vi.fn()
render(
x
,
)
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
fireEvent.keyDown(document, { key: 'Escape' })
expect(onClose).toHaveBeenCalledTimes(2)
})
})