mirror of
https://github.com/langgenius/dify.git
synced 2026-04-18 04:16:28 +08:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import { render } from '@testing-library/react'
|
|
import MenuDialog from '../menu-dialog'
|
|
|
|
type DialogProps = {
|
|
children: ReactNode
|
|
open?: boolean
|
|
onOpenChange?: (open: boolean) => void
|
|
}
|
|
|
|
let latestOnOpenChange: DialogProps['onOpenChange']
|
|
|
|
vi.mock('@/app/components/base/ui/dialog', () => ({
|
|
Dialog: ({ children, onOpenChange }: DialogProps) => {
|
|
latestOnOpenChange = onOpenChange
|
|
return <div data-testid="dialog">{children}</div>
|
|
},
|
|
DialogContent: ({ children, className }: { children: ReactNode, className?: string }) => (
|
|
<div className={className}>{children}</div>
|
|
),
|
|
}))
|
|
|
|
describe('MenuDialog dialog lifecycle', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
latestOnOpenChange = undefined
|
|
})
|
|
|
|
it('should only call onClose when the dialog requests closing', () => {
|
|
const onClose = vi.fn()
|
|
render(
|
|
<MenuDialog show={true} onClose={onClose}>
|
|
<div>Content</div>
|
|
</MenuDialog>,
|
|
)
|
|
|
|
latestOnOpenChange?.(true)
|
|
latestOnOpenChange?.(false)
|
|
|
|
expect(onClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|