feat(ui): Dialog with backdrop + escape + motion fade
This commit is contained in:
1 parent
a1453ec32e
commit
afd58b386b
2 files changed
+101
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user