import { fireEvent, render, screen } from '@testing-library/react' import AnnotationFullModal from './modal' jest.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, }), })) let mockUsageProps: { className?: string } | null = null jest.mock('./usage', () => ({ __esModule: true, default: (props: { className?: string }) => { mockUsageProps = props return (
usage
) }, })) let mockUpgradeBtnProps: { loc?: string } | null = null jest.mock('../upgrade-btn', () => ({ __esModule: true, default: (props: { loc?: string }) => { mockUpgradeBtnProps = props return ( ) }, })) type ModalSnapshot = { isShow: boolean closable?: boolean className?: string } let mockModalProps: ModalSnapshot | null = null jest.mock('../../base/modal', () => ({ __esModule: true, default: ({ isShow, children, onClose, closable, className }: { isShow: boolean; children: React.ReactNode; onClose: () => void; closable?: boolean; className?: string }) => { mockModalProps = { isShow, closable, className, } if (!isShow) return null return (
{closable && ( )} {children}
) }, })) describe('AnnotationFullModal', () => { beforeEach(() => { jest.clearAllMocks() mockUsageProps = null mockUpgradeBtnProps = null mockModalProps = null }) // Rendering marketing copy inside modal describe('Rendering', () => { it('should display main info when visible', () => { // Act render() // Assert expect(screen.getByText('billing.annotatedResponse.fullTipLine1')).toBeInTheDocument() expect(screen.getByText('billing.annotatedResponse.fullTipLine2')).toBeInTheDocument() expect(screen.getByTestId('usage-component')).toHaveAttribute('data-classname', 'mt-4') expect(screen.getByTestId('upgrade-btn')).toHaveTextContent('annotation-create') expect(mockUpgradeBtnProps?.loc).toBe('annotation-create') expect(mockModalProps).toEqual(expect.objectContaining({ isShow: true, closable: true, className: '!p-0', })) }) }) // Controlling modal visibility describe('Visibility', () => { it('should not render content when hidden', () => { // Act const { container } = render() // Assert expect(container).toBeEmptyDOMElement() expect(mockModalProps).toEqual(expect.objectContaining({ isShow: false })) }) }) // Handling close interactions describe('Close handling', () => { it('should trigger onHide when close control is clicked', () => { // Arrange const onHide = jest.fn() // Act render() fireEvent.click(screen.getByTestId('mock-modal-close')) // Assert expect(onHide).toHaveBeenCalledTimes(1) }) }) })