mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
- Introduced new test files for CheckboxWithLabel, CrawledResultItem, ErrorMessage, and various components related to website crawling and document preview. - Enhanced test coverage by validating rendering, user interactions, and edge cases for each component. - Ensured proper functionality of user interactions such as checkbox selections, button clicks, and rendering of dynamic content. These additions improve the reliability and maintainability of the website crawl and document preview features.
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import Header from './header'
|
|
|
|
vi.mock('react-i18next', () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, opts?: { pluginName?: string }) => opts?.pluginName ? `${key}-${opts.pluginName}` : key,
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@remixicon/react', () => ({
|
|
RiBookOpenLine: () => <span data-testid="book-icon" />,
|
|
RiEqualizer2Line: ({ onClick }: { onClick?: () => void }) => <span data-testid="config-icon" onClick={onClick} />,
|
|
}))
|
|
|
|
vi.mock('@/app/components/base/button', () => ({
|
|
default: ({ children }: { children: React.ReactNode }) => <button>{children}</button>,
|
|
}))
|
|
|
|
vi.mock('@/app/components/base/divider', () => ({
|
|
default: () => <span data-testid="divider" />,
|
|
}))
|
|
|
|
vi.mock('@/app/components/base/tooltip', () => ({
|
|
default: ({ children }: { children: React.ReactNode }) => <div data-testid="tooltip">{children}</div>,
|
|
}))
|
|
|
|
vi.mock('./credential-selector', () => ({
|
|
default: () => <div data-testid="credential-selector" />,
|
|
}))
|
|
|
|
describe('Header', () => {
|
|
const defaultProps = {
|
|
docTitle: 'Documentation',
|
|
docLink: 'https://docs.example.com',
|
|
onClickConfiguration: vi.fn(),
|
|
pluginName: 'TestPlugin',
|
|
credentials: [],
|
|
currentCredentialId: '',
|
|
onCredentialChange: vi.fn(),
|
|
}
|
|
|
|
it('should render doc link with title', () => {
|
|
render(<Header {...defaultProps} />)
|
|
expect(screen.getByText('Documentation')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render credential selector', () => {
|
|
render(<Header {...defaultProps} />)
|
|
expect(screen.getByTestId('credential-selector')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render configuration button', () => {
|
|
render(<Header {...defaultProps} />)
|
|
expect(screen.getByTestId('config-icon')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should link to external doc', () => {
|
|
render(<Header {...defaultProps} />)
|
|
const link = screen.getByText('Documentation').closest('a')
|
|
expect(link).toHaveAttribute('href', 'https://docs.example.com')
|
|
expect(link).toHaveAttribute('target', '_blank')
|
|
})
|
|
})
|