dify/web/app/components/base/logo/__tests__/dify-logo.spec.tsx
Jingyi 9b74df21d0
feat(web): refine onboarding UI (#37433)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
Co-authored-by: gigglewang <gigglewang@dify.ai>
Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
Co-authored-by: chariri <w@chariri.moe>
Co-authored-by: Evan <2869018789@qq.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-06-15 08:47:15 +00:00

101 lines
3.3 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import useTheme from '@/hooks/use-theme'
import { Theme } from '@/types/app'
import DifyLogo from '../dify-logo'
vi.mock('@/hooks/use-theme', () => ({
default: vi.fn(),
}))
vi.mock('@/utils/var', () => ({
basePath: '/test-base-path',
}))
describe('DifyLogo', () => {
const mockUseTheme = {
theme: Theme.light,
themes: ['light', 'dark'],
setTheme: vi.fn(),
resolvedTheme: Theme.light,
systemTheme: Theme.light,
forcedTheme: undefined,
}
beforeEach(() => {
vi.mocked(useTheme).mockReturnValue(mockUseTheme as ReturnType<typeof useTheme>)
})
describe('Render', () => {
it('renders correctly with default props', () => {
render(<DifyLogo />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toBeInTheDocument()
expect(img).toHaveAttribute('src', '/test-base-path/logo/logo.svg')
})
})
describe('Props', () => {
it('applies custom size correctly', () => {
const { rerender } = render(<DifyLogo size="large" />)
let img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveClass('w-16')
expect(img).toHaveClass('h-7')
rerender(<DifyLogo size="small" />)
img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveClass('w-9')
expect(img).toHaveClass('h-4')
})
it('applies custom style correctly', () => {
render(<DifyLogo style="monochromeWhite" />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveAttribute('src', '/test-base-path/logo/logo-monochrome-white.svg')
})
it('applies custom className', () => {
render(<DifyLogo className="custom-test-class" />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveClass('custom-test-class')
})
it('applies custom alt text', () => {
const { container } = render(<DifyLogo alt="" />)
const img = container.querySelector('img')
expect(img).toHaveAttribute('alt', '')
})
})
describe('Theme behavior', () => {
it('uses monochromeWhite logo in dark theme when style is default', () => {
vi.mocked(useTheme).mockReturnValue({
...mockUseTheme,
theme: Theme.dark,
} as ReturnType<typeof useTheme>)
render(<DifyLogo style="default" />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveAttribute('src', '/test-base-path/logo/logo-monochrome-white.svg')
})
it('uses monochromeWhite logo in dark theme when style is monochromeWhite', () => {
vi.mocked(useTheme).mockReturnValue({
...mockUseTheme,
theme: Theme.dark,
} as ReturnType<typeof useTheme>)
render(<DifyLogo style="monochromeWhite" />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveAttribute('src', '/test-base-path/logo/logo-monochrome-white.svg')
})
it('uses default logo in light theme when style is default', () => {
vi.mocked(useTheme).mockReturnValue({
...mockUseTheme,
theme: Theme.light,
} as ReturnType<typeof useTheme>)
render(<DifyLogo style="default" />)
const img = screen.getByRole('img', { name: 'Dify' })
expect(img).toHaveAttribute('src', '/test-base-path/logo/logo.svg')
})
})
})