36 lines
943 B
TypeScript
36 lines
943 B
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import Dialog from '@/components/ui/Dialog'
|
|
|
|
describe('Dialog', () => {
|
|
it('renders nothing when open=false', () => {
|
|
render(
|
|
<Dialog open={false} onClose={() => {}} title="X">
|
|
body
|
|
</Dialog>,
|
|
)
|
|
expect(screen.queryByText('body')).toBeNull()
|
|
})
|
|
|
|
it('renders content when open=true', () => {
|
|
render(
|
|
<Dialog open={true} onClose={() => {}} title="X">
|
|
body
|
|
</Dialog>,
|
|
)
|
|
expect(screen.getByText('body')).toBeInTheDocument()
|
|
})
|
|
|
|
it('calls onClose on backdrop click', async () => {
|
|
const onClose = vi.fn()
|
|
render(
|
|
<Dialog open onClose={onClose} title="X">
|
|
body
|
|
</Dialog>,
|
|
)
|
|
await userEvent.click(screen.getByTestId('dialog-backdrop'))
|
|
expect(onClose).toHaveBeenCalled()
|
|
})
|
|
})
|