var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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(_jsx(DeepThinking, Object.assign({}, defaultProps)));
        expect(screen.getByText('Show thinking')).toBeTruthy();
    });
    it('should render subheading when provided', () => {
        const subheading = 'Thought for 3 seconds';
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { subheading: subheading })));
        expect(screen.getByText(subheading)).toBeTruthy();
    });
    it('should render body content when provided', () => {
        const body = "Here's why I think that";
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: body })));
        expect(screen.getByText(body)).toBeTruthy();
    });
    it('should render with complex content including React elements', () => {
        const body = (_jsxs("div", { children: [_jsx("p", { children: "Complex body content" }), _jsxs("ul", { children: [_jsx("li", { children: "Item 1" }), _jsx("li", { children: "Item 2" })] })] }));
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: body })));
        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(_jsx(DeepThinking, Object.assign({}, defaultProps, { cardProps: { className: 'custom-tool-response-class' } })));
        expect(container.querySelector('.custom-tool-response-class')).toBeTruthy();
    });
    it('should pass through expandableSectionProps', () => {
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { expandableSectionProps: { className: 'custom-expandable-class' } })));
        expect(document.querySelector('.custom-expandable-class')).toBeTruthy();
    });
    it('should not render subheading span when subheading is not provided', () => {
        const { container } = render(_jsx(DeepThinking, Object.assign({}, defaultProps)));
        const subheadingContainer = container.querySelector('.pf-chatbot__tool-response-subheading');
        expect(subheadingContainer).toBeFalsy();
    });
    it('should pass through cardBodyProps', () => {
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: "Thinking content", cardBodyProps: { className: 'custom-card-body-class' } })));
        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(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: "Thinking content" })));
        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(_jsx(DeepThinking, Object.assign({ isDefaultExpanded: false }, defaultProps, { body: "Thinking content" })));
        expect(screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'false');
        expect(screen.getByText('Thinking content')).not.toBeVisible();
    });
    it('expandableSectionProps.isExpanded overrides isDefaultExpanded', () => {
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { isDefaultExpanded: false, body: "Thinking content", expandableSectionProps: { isExpanded: true } })));
        expect(screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'true');
        expect(screen.getByText('Thinking content')).toBeVisible();
    });
    it('expandableSectionProps.onToggle overrides internal onToggle behavior', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = userEvent.setup();
        const customOnToggle = jest.fn();
        render(_jsx(DeepThinking, Object.assign({}, defaultProps, { isDefaultExpanded: false, body: "Thinking content", expandableSectionProps: { onToggle: customOnToggle } })));
        const toggleButton = screen.getByRole('button', { name: defaultProps.toggleContent });
        expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
        yield 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(_jsx(DeepThinking, { toggleContent: toggleContent, isToggleContentMarkdown: true }));
        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(_jsx(DeepThinking, { toggleContent: toggleContent }));
        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(_jsx(DeepThinking, Object.assign({}, defaultProps, { subheading: subheading, isSubheadingMarkdown: true })));
        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(_jsx(DeepThinking, Object.assign({}, defaultProps, { subheading: subheading })));
        expect(screen.getByText('**Bold subheading**')).toBeTruthy();
    });
    it('should render body as markdown when isBodyMarkdown is true', () => {
        const body = '**Bold body**';
        const { container } = render(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true })));
        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(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: body })));
        expect(screen.getByText('**Bold body**')).toBeTruthy();
    });
    it('should pass markdownContentProps to MarkdownContent component', () => {
        const body = '**Bold body**';
        const { container } = render(_jsx(DeepThinking, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true, markdownContentProps: { isPrimary: true } })));
        expect(container.querySelector('.pf-m-primary')).toBeTruthy();
    });
});
