53 lines
1.6 KiB
TypeScript
53 lines
1.6 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 (Modernist dialog)', () => {
|
|
it('renders nothing when closed', () => {
|
|
const { container } = render(
|
|
<Modal open={false} onClose={() => {}} title="T">
|
|
body
|
|
</Modal>,
|
|
)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders a dialog with title, body and footer on the surface fill', () => {
|
|
render(
|
|
<Modal open onClose={() => {}} title="Confirm" footer={<span>actions</span>}>
|
|
body text
|
|
</Modal>,
|
|
)
|
|
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(
|
|
<Modal open onClose={() => {}} title="T">
|
|
x
|
|
</Modal>,
|
|
)
|
|
const html = screen.getByRole('dialog').innerHTML
|
|
expect(html).not.toMatch(/rounded/)
|
|
expect(html).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)
|
|
})
|
|
})
|