import { render, screen } from '@testing-library/react' import * as React from 'react' import AppBasic from '../basic' vi.mock('@/app/components/base/icons/src/vender/workflow', () => ({ ApiAggregate: (props: React.SVGProps) => , WindowCursor: (props: React.SVGProps) => , })) vi.mock('@/app/components/base/tooltip', () => ({ default: ({ popupContent }: { popupContent: React.ReactNode }) => (
{popupContent}
), })) vi.mock('../../base/app-icon', () => ({ default: ({ icon, background, innerIcon, className }: { icon?: string background?: string innerIcon?: React.ReactNode className?: string }) => (
{innerIcon}
), })) describe('AppBasic', () => { describe('Icon rendering', () => { it('should render app icon when iconType is app with valid icon and background', () => { render() expect(screen.getByTestId('app-icon')).toBeInTheDocument() }) it('should not render app icon when icon is empty', () => { render() expect(screen.queryByTestId('app-icon')).not.toBeInTheDocument() }) it('should render api icon when iconType is api', () => { render() expect(screen.getByTestId('api-icon')).toBeInTheDocument() }) it('should render webapp icon when iconType is webapp', () => { render() expect(screen.getByTestId('webapp-icon')).toBeInTheDocument() }) it('should render dataset icon when iconType is dataset', () => { render() const icons = screen.getAllByTestId('app-icon') expect(icons.length).toBeGreaterThan(0) }) it('should render notion icon when iconType is notion', () => { render() const icons = screen.getAllByTestId('app-icon') expect(icons.length).toBeGreaterThan(0) }) }) describe('Expand mode', () => { it('should show name and type in expand mode', () => { render() expect(screen.getByText('My App')).toBeInTheDocument() expect(screen.getByText('Chatbot')).toBeInTheDocument() }) it('should hide name and type in collapse mode', () => { render() expect(screen.queryByText('My App')).not.toBeInTheDocument() }) it('should show hover tip when provided', () => { render() expect(screen.getByTestId('tooltip')).toBeInTheDocument() expect(screen.getByText('Some tip')).toBeInTheDocument() }) it('should not show hover tip when not provided', () => { render() expect(screen.queryByTestId('tooltip')).not.toBeInTheDocument() }) }) describe('Type display', () => { it('should hide type when hideType is true', () => { render() expect(screen.queryByText('Chatbot')).not.toBeInTheDocument() }) it('should show external tag when isExternal is true', () => { render() expect(screen.getByText('dataset.externalTag')).toBeInTheDocument() }) it('should show type inline when isExtraInLine is true and hideType is false', () => { render() expect(screen.getByText('Chatbot')).toBeInTheDocument() }) it('should apply custom text styles', () => { render() const nameContainer = screen.getByText('My App').parentElement expect(nameContainer).toHaveClass('text-red-500') }) }) })