dify/web/app/components/header/account-setting/__tests__/menu-dialog.spec.tsx
yyh bbe975c6bc
feat: enhance model plugin workflow checks and model provider management UX (#33289)
Signed-off-by: yyh <yuanyouhuilyz@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Coding On Star <447357187@qq.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: statxc <tyleradams93226@gmail.com>
2026-03-18 10:16:15 +08:00

94 lines
2.4 KiB
TypeScript

import { fireEvent, render, screen } from '@testing-library/react'
import MenuDialog from '../menu-dialog'
describe('MenuDialog', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('Rendering', () => {
it('should render children when show is true', () => {
// Act
render(
<MenuDialog show={true} onClose={vi.fn()}>
<div data-testid="dialog-content">Content</div>
</MenuDialog>,
)
// Assert
expect(screen.getByTestId('dialog-content')).toBeInTheDocument()
})
it('should not render children when show is false', () => {
// Act
render(
<MenuDialog show={false} onClose={vi.fn()}>
<div data-testid="dialog-content">Content</div>
</MenuDialog>,
)
// Assert
expect(screen.queryByTestId('dialog-content')).not.toBeInTheDocument()
})
it('should apply custom className', () => {
// Act
render(
<MenuDialog show={true} onClose={vi.fn()} className="custom-class">
<div data-testid="dialog-content">Content</div>
</MenuDialog>,
)
// Assert
expect(screen.getByRole('dialog')).toHaveClass('custom-class')
})
})
describe('Interactions', () => {
it('should call onClose when Escape key is pressed', () => {
// Arrange
const onClose = vi.fn()
render(
<MenuDialog show={true} onClose={onClose}>
<div>Content</div>
</MenuDialog>,
)
// Act
fireEvent.keyDown(document, { key: 'Escape' })
// Assert
expect(onClose).toHaveBeenCalled()
})
it('should not call onClose when a key other than Escape is pressed', () => {
// Arrange
const onClose = vi.fn()
render(
<MenuDialog show={true} onClose={onClose}>
<div>Content</div>
</MenuDialog>,
)
// Act
fireEvent.keyDown(document, { key: 'Enter' })
// Assert
expect(onClose).not.toHaveBeenCalled()
})
it('should not crash when Escape is pressed and onClose is not provided', () => {
// Arrange
render(
<MenuDialog show={true}>
<div data-testid="dialog-content">Content</div>
</MenuDialog>,
)
// Act & Assert
fireEvent.keyDown(document, { key: 'Escape' })
expect(screen.getByTestId('dialog-content')).toBeInTheDocument()
})
})
})