import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import DeepThinking from './DeepThinking'; describe('DeepThinking', () => { const defaultProps = { toggleContent: 'Show thinking' }; it('should render with required props only', () => { render(); expect(screen.getByText('Show thinking')).toBeTruthy(); }); it('should render subheading when provided', () => { const subheading = 'Thought for 3 seconds'; render(); expect(screen.getByText(subheading)).toBeTruthy(); }); it('should render body content when provided', () => { const body = "Here's why I think that"; render(); expect(screen.getByText(body)).toBeTruthy(); }); it('should render with complex content including React elements', () => { const body = (

Complex body content

  • Item 1
  • Item 2
); render(); expect(screen.getByText('Complex body content')).toBeTruthy(); expect(screen.getByText('Item 1')).toBeTruthy(); expect(screen.getByText('Item 2')).toBeTruthy(); }); it('should apply custom className from cardProps', () => { const { container } = render( ); expect(container.querySelector('.custom-tool-response-class')).toBeTruthy(); }); it('should pass through expandableSectionProps', () => { render(); expect(document.querySelector('.custom-expandable-class')).toBeTruthy(); }); it('should not render subheading span when subheading is not provided', () => { const { container } = render(); const subheadingContainer = container.querySelector('.pf-chatbot__tool-response-subheading'); expect(subheadingContainer).toBeFalsy(); }); it('should pass through cardBodyProps', () => { render( ); const cardBody = screen.getByText('Thinking content').closest('.pf-v6-c-card__body'); expect(cardBody).toHaveClass('custom-card-body-class'); }); it('Renders expanded by default', () => { render(); expect(screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'true'); expect(screen.getByText('Thinking content')).toBeVisible(); }); it('Renders collapsed when isDefaultExpanded is false', () => { render(); expect(screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'false'); expect(screen.getByText('Thinking content')).not.toBeVisible(); }); it('expandableSectionProps.isExpanded overrides isDefaultExpanded', () => { render( ); expect(screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'true'); expect(screen.getByText('Thinking content')).toBeVisible(); }); it('expandableSectionProps.onToggle overrides internal onToggle behavior', async () => { const user = userEvent.setup(); const customOnToggle = jest.fn(); render( ); const toggleButton = screen.getByRole('button', { name: defaultProps.toggleContent }); expect(toggleButton).toHaveAttribute('aria-expanded', 'false'); await user.click(toggleButton); expect(customOnToggle).toHaveBeenCalled(); expect(toggleButton).toHaveAttribute('aria-expanded', 'false'); expect(screen.getByText('Thinking content')).not.toBeVisible(); }); it('should render toggleContent as markdown when isToggleContentMarkdown is true', () => { const toggleContent = '**Bold thinking**'; const { container } = render(); expect(container.querySelector('strong')).toBeTruthy(); expect(screen.getByText('Bold thinking')).toBeTruthy(); }); it('should not render toggleContent as markdown when isToggleContentMarkdown is false', () => { const toggleContent = '**Bold thinking**'; const { container } = render(); expect(container.querySelector('strong')).toBeFalsy(); expect(screen.getByText('**Bold thinking**')).toBeTruthy(); }); it('should render subheading as markdown when isSubheadingMarkdown is true', () => { const subheading = '**Bold subheading**'; const { container } = render(); expect(container.querySelector('strong')).toBeTruthy(); expect(screen.getByText('Bold subheading')).toBeTruthy(); }); it('should not render subheading as markdown when isSubheadingMarkdown is false', () => { const subheading = '**Bold subheading**'; render(); expect(screen.getByText('**Bold subheading**')).toBeTruthy(); }); it('should render body as markdown when isBodyMarkdown is true', () => { const body = '**Bold body**'; const { container } = render(); expect(container.querySelector('strong')).toBeTruthy(); expect(screen.getByText('Bold body')).toBeTruthy(); }); it('should not render body as markdown when isBodyMarkdown is false', () => { const body = '**Bold body**'; render(); expect(screen.getByText('**Bold body**')).toBeTruthy(); }); it('should pass markdownContentProps to MarkdownContent component', () => { const body = '**Bold body**'; const { container } = render( ); expect(container.querySelector('.pf-m-primary')).toBeTruthy(); }); });