mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import ConfigModel from './config-model'
|
|
|
|
// Mock icons
|
|
vi.mock('@remixicon/react', () => ({
|
|
RiEqualizer2Line: () => <div data-testid="config-icon" />,
|
|
RiScales3Line: () => <div data-testid="scales-icon" />,
|
|
}))
|
|
|
|
// Mock Indicator
|
|
vi.mock('@/app/components/header/indicator', () => ({
|
|
default: ({ color }: { color: string }) => <div data-testid={`indicator-${color}`} />,
|
|
}))
|
|
|
|
describe('ConfigModel', () => {
|
|
it('should render authorization error when loadBalancingInvalid is true', () => {
|
|
const onClick = vi.fn()
|
|
render(<ConfigModel loadBalancingInvalid onClick={onClick} />)
|
|
|
|
expect(screen.getByText(/modelProvider.auth.authorizationError/)).toBeInTheDocument()
|
|
expect(screen.getByTestId('scales-icon')).toBeInTheDocument()
|
|
expect(screen.getByTestId('indicator-orange')).toBeInTheDocument()
|
|
|
|
fireEvent.click(screen.getByText(/modelProvider.auth.authorizationError/))
|
|
expect(onClick).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should render credential removed message when credentialRemoved is true', () => {
|
|
render(<ConfigModel credentialRemoved />)
|
|
|
|
expect(screen.getByText(/modelProvider.auth.credentialRemoved/)).toBeInTheDocument()
|
|
expect(screen.getByTestId('indicator-red')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render standard config message when no flags enabled', () => {
|
|
render(<ConfigModel />)
|
|
|
|
expect(screen.getByText(/operation.config/)).toBeInTheDocument()
|
|
expect(screen.getByTestId('config-icon')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render config load balancing when loadBalancingEnabled is true', () => {
|
|
render(<ConfigModel loadBalancingEnabled />)
|
|
|
|
expect(screen.getByText(/modelProvider.auth.configLoadBalancing/)).toBeInTheDocument()
|
|
expect(screen.getByTestId('scales-icon')).toBeInTheDocument()
|
|
})
|
|
})
|