dify/web/app/components/base/linked-apps-panel/index.spec.tsx
Saumya Talwani 98466e2d29
Some checks are pending
autofix.ci / autofix (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
test: add tests for some base components (#32265)
2026-02-13 14:29:04 +08:00

94 lines
3.0 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import * as React from 'react'
import { vi } from 'vitest'
import { AppModeEnum } from '@/types/app'
import LinkedAppsPanel from './index'
vi.mock('next/link', () => ({
default: ({ children, href, className }: { children: React.ReactNode, href: string, className: string }) => (
<a href={href} className={className} data-testid="link-item">
{children}
</a>
),
}))
describe('LinkedAppsPanel Component', () => {
const mockRelatedApps = [
{
id: 'app-1',
name: 'Chatbot App',
mode: AppModeEnum.CHAT,
icon_type: 'emoji' as const,
icon: '🤖',
icon_background: '#FFEAD5',
icon_url: '',
},
{
id: 'app-2',
name: 'Workflow App',
mode: AppModeEnum.WORKFLOW,
icon_type: 'image' as const,
icon: 'file-id',
icon_background: '#E4FBCC',
icon_url: 'https://example.com/icon.png',
},
{
id: 'app-3',
name: '',
mode: AppModeEnum.AGENT_CHAT,
icon_type: 'emoji' as const,
icon: '🕵️',
icon_background: '#D3F8DF',
icon_url: '',
},
]
describe('Render', () => {
it('renders correctly with multiple apps', () => {
render(<LinkedAppsPanel relatedApps={mockRelatedApps} isMobile={false} />)
const items = screen.getAllByTestId('link-item')
expect(items).toHaveLength(3)
expect(screen.getByText('Chatbot App')).toBeInTheDocument()
expect(screen.getByText('Workflow App')).toBeInTheDocument()
expect(screen.getByText('--')).toBeInTheDocument()
})
it('displays correct app mode labels', () => {
render(<LinkedAppsPanel relatedApps={mockRelatedApps} isMobile={false} />)
expect(screen.getByText('Chatbot')).toBeInTheDocument()
expect(screen.getByText('Workflow')).toBeInTheDocument()
expect(screen.getByText('Agent')).toBeInTheDocument()
})
it('hides app name and centers content in mobile mode', () => {
render(<LinkedAppsPanel relatedApps={mockRelatedApps} isMobile={true} />)
expect(screen.queryByText('Chatbot App')).not.toBeInTheDocument()
expect(screen.queryByText('Workflow App')).not.toBeInTheDocument()
const items = screen.getAllByTestId('link-item')
expect(items[0]).toHaveClass('justify-center')
})
it('handles empty relatedApps list gracefully', () => {
const { container } = render(<LinkedAppsPanel relatedApps={[]} isMobile={false} />)
const items = screen.queryAllByTestId('link-item')
expect(items).toHaveLength(0)
expect(container.firstChild).toBeInTheDocument()
})
})
describe('Interaction', () => {
it('renders correct links for each app', () => {
render(<LinkedAppsPanel relatedApps={mockRelatedApps} isMobile={false} />)
const items = screen.getAllByTestId('link-item')
expect(items[0]).toHaveAttribute('href', '/app/app-1/overview')
expect(items[1]).toHaveAttribute('href', '/app/app-2/overview')
})
})
})