31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
import { Modal } from '@/components/ui/modal'
|
|
|
|
describe('Modal', () => {
|
|
it('renders nothing when closed', () => {
|
|
const { container } = render(<Modal open={false} onClose={() => {}} title="T">body</Modal>)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders a 12px card dialog with the floating shadow and a 1px header rule', () => {
|
|
render(<Modal open onClose={() => {}} title="Confirm" footer={<span>actions</span>}>body text</Modal>)
|
|
const dialog = screen.getByRole('dialog')
|
|
expect(screen.getByText('Confirm')).toBeTruthy()
|
|
expect(screen.getByText('body text')).toBeTruthy()
|
|
expect(screen.getByText('actions')).toBeTruthy()
|
|
expect(dialog.innerHTML).toContain('rounded-xl')
|
|
expect(dialog.innerHTML).toContain('shadow-float')
|
|
expect(dialog.innerHTML).toContain('border-b border-rule')
|
|
expect(dialog.innerHTML).not.toContain('border-b-2')
|
|
})
|
|
|
|
it('closes from the X button and on Escape', () => {
|
|
const onClose = vi.fn()
|
|
render(<Modal open onClose={onClose} title="T">x</Modal>)
|
|
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
|
|
fireEvent.keyDown(document, { key: 'Escape' })
|
|
expect(onClose).toHaveBeenCalledTimes(2)
|
|
})
|
|
})
|