mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 10:12:43 +08:00
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>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import * as React from 'react'
|
|
import { Dialog } from '@/app/components/base/ui/dialog'
|
|
import Header from '../header'
|
|
|
|
function renderHeader(onClose: () => void) {
|
|
return render(
|
|
<Dialog open>
|
|
<Header onClose={onClose} />
|
|
</Dialog>,
|
|
)
|
|
}
|
|
|
|
describe('Header', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('Rendering', () => {
|
|
it('should render title and description translations', () => {
|
|
const handleClose = vi.fn()
|
|
|
|
renderHeader(handleClose)
|
|
|
|
expect(screen.getByText('billing.plansCommon.title.plans')).toBeInTheDocument()
|
|
expect(screen.getByText('billing.plansCommon.title.description')).toBeInTheDocument()
|
|
expect(screen.getByRole('button')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('Props', () => {
|
|
it('should invoke onClose when close button is clicked', () => {
|
|
const handleClose = vi.fn()
|
|
renderHeader(handleClose)
|
|
|
|
fireEvent.click(screen.getByRole('button'))
|
|
|
|
expect(handleClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should render structural elements with translation keys', () => {
|
|
const { container } = renderHeader(vi.fn())
|
|
|
|
expect(container.querySelector('span')).toBeInTheDocument()
|
|
expect(container.querySelector('p')).toBeInTheDocument()
|
|
expect(screen.getByRole('button')).toBeInTheDocument()
|
|
})
|
|
})
|
|
})
|