dify/web/app/components/datasets/__tests__/no-linked-apps-panel.spec.tsx
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

58 lines
1.7 KiB
TypeScript

import { cleanup, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import NoLinkedAppsPanel from '../no-linked-apps-panel'
vi.mock('@/context/i18n', () => ({
useDocLink: () => (path: string) => `https://docs.example.com${path}`,
}))
// Mock useDocLink
afterEach(() => {
cleanup()
})
describe('NoLinkedAppsPanel', () => {
it('should render without crashing', () => {
render(<NoLinkedAppsPanel />)
expect(screen.getByText('common.datasetMenus.emptyTip')).toBeInTheDocument()
})
it('should render the empty tip text', () => {
render(<NoLinkedAppsPanel />)
expect(screen.getByText('common.datasetMenus.emptyTip')).toBeInTheDocument()
})
it('should render the view doc link', () => {
render(<NoLinkedAppsPanel />)
expect(screen.getByText('common.datasetMenus.viewDoc')).toBeInTheDocument()
})
it('should render link with correct href', () => {
render(<NoLinkedAppsPanel />)
const link = screen.getByRole('link')
expect(link).toHaveAttribute(
'href',
'https://docs.example.com/use-dify/knowledge/integrate-knowledge-within-application',
)
})
it('should render link with target="_blank"', () => {
render(<NoLinkedAppsPanel />)
const link = screen.getByRole('link')
expect(link).toHaveAttribute('target', '_blank')
})
it('should render link with rel="noopener noreferrer"', () => {
render(<NoLinkedAppsPanel />)
const link = screen.getByRole('link')
expect(link).toHaveAttribute('rel', 'noopener noreferrer')
})
it('should be wrapped with React.memo', () => {
expect((NoLinkedAppsPanel as unknown as { $$typeof: symbol }).$$typeof).toBe(
Symbol.for('react.memo'),
)
})
})