mirror of
https://github.com/langgenius/dify.git
synced 2026-04-12 22:17:09 +08:00
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import * as React from 'react'
|
|
import { Dialog, DialogContent } from '@/app/components/base/ui/dialog'
|
|
import Header from '../header'
|
|
|
|
function renderHeader(onClose: () => void) {
|
|
return render(
|
|
<Dialog open>
|
|
<DialogContent>
|
|
<Header onClose={onClose} />
|
|
</DialogContent>
|
|
</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', { name: 'common.operation.close' })).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('Props', () => {
|
|
it('should invoke onClose when close button is clicked', () => {
|
|
const handleClose = vi.fn()
|
|
renderHeader(handleClose)
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'common.operation.close' }))
|
|
|
|
expect(handleClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should render structural elements with translation keys', () => {
|
|
renderHeader(vi.fn())
|
|
|
|
expect(screen.getByText('billing.plansCommon.title.plans')).toBeInTheDocument()
|
|
expect(screen.getByText('billing.plansCommon.title.description')).toBeInTheDocument()
|
|
expect(screen.getByRole('button', { name: 'common.operation.close' })).toBeInTheDocument()
|
|
})
|
|
})
|
|
})
|