"use strict";
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("@testing-library/react");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
require("@testing-library/jest-dom");
const ToolResponse_1 = __importDefault(require("./ToolResponse"));
describe('ToolResponse', () => {
    const defaultProps = {
        toggleContent: 'Tool response: toolName',
        cardTitle: 'Title',
        cardBody: 'Body'
    };
    it('should render with required props only', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.getByText('Title')).toBeTruthy();
        expect(react_1.screen.getByText('Body')).toBeTruthy();
        expect(react_1.screen.getByText('Tool response: toolName')).toBeTruthy();
    });
    it('should render subheading when provided', () => {
        const subheading = 'Tool execution result';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { subheading: subheading })));
        expect(react_1.screen.getByText(subheading)).toBeTruthy();
    });
    it('should render body content when provided', () => {
        const body = 'This is the tool response body content';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body })));
        expect(react_1.screen.getByText(body)).toBeTruthy();
    });
    it('should render with complex content including React elements', () => {
        const body = ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { children: "Complex body content" }), (0, jsx_runtime_1.jsxs)("ul", { children: [(0, jsx_runtime_1.jsx)("li", { children: "Item 1" }), (0, jsx_runtime_1.jsx)("li", { children: "Item 2" })] })] }));
        const cardTitle = (0, jsx_runtime_1.jsx)("strong", { children: "API Response" });
        const cardBody = ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("code", { children: "{ status: 'success' }" }) }));
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body, cardTitle: cardTitle, cardBody: cardBody })));
        expect(react_1.screen.getByText('Complex body content')).toBeTruthy();
        expect(react_1.screen.getByText('Item 1')).toBeTruthy();
        expect(react_1.screen.getByText('Item 2')).toBeTruthy();
        expect(react_1.screen.getByText('API Response')).toBeTruthy();
        expect(react_1.screen.getByText("{ status: 'success' }")).toBeTruthy();
    });
    it('should apply custom className from cardProps', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardProps: { className: 'custom-tool-response-class' } })));
        expect(container.querySelector('.custom-tool-response-class')).toBeTruthy();
    });
    it('should pass through expandableSectionProps', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { expandableSectionProps: { className: 'custom-expandable-class' } })));
        expect(document.querySelector('.custom-expandable-class')).toBeTruthy();
    });
    it('should pass through toolResponseCardProps', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { toolResponseCardProps: { className: 'custom-card-class' } })));
        expect(document.querySelector('.custom-card-class')).toBeTruthy();
    });
    it('should not render subheading span when subheading is not provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps)));
        const subheadingContainer = container.querySelector('.pf-chatbot__tool-response-subheading');
        expect(subheadingContainer).toBeFalsy();
    });
    it('should not render card when cardTitle and cardBody are not provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: undefined, cardBody: undefined })));
        expect(container.querySelector('.pf-chatbot__tool-response-card')).toBeFalsy();
    });
    it('should render card when only cardTitle is provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: undefined })));
        expect(container.querySelector('.pf-chatbot__tool-response-card')).toBeTruthy();
    });
    it('should render card when only cardBody is provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: undefined })));
        expect(container.querySelector('.pf-chatbot__tool-response-card')).toBeTruthy();
    });
    it('should render divider when cardBody and cardTitle are provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps)));
        expect(container.querySelector('.pf-v6-c-divider')).toBeTruthy();
    });
    it('should not render divider when only cardBody is provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: undefined })));
        expect(container.querySelector('.pf-v6-c-divider')).toBeFalsy();
    });
    it('should not render divider when only cardTitle is provided', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: undefined })));
        expect(container.querySelector('.pf-v6-c-divider')).toBeFalsy();
    });
    it('Renders expanded by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'true');
        expect(react_1.screen.getByText(defaultProps.cardTitle)).toBeVisible();
        expect(react_1.screen.getByText(defaultProps.cardBody)).toBeVisible();
    });
    it('Renders collapsed when isDefaultExpanded is false', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({ isDefaultExpanded: false }, defaultProps)));
        expect(react_1.screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'false');
        expect(react_1.screen.getByText(defaultProps.cardTitle)).not.toBeVisible();
        expect(react_1.screen.getByText(defaultProps.cardBody)).not.toBeVisible();
    });
    it('expandableSectionProps.isExpanded overrides isDefaultExpanded', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { isDefaultExpanded: false, expandableSectionProps: { isExpanded: true } })));
        expect(react_1.screen.getByRole('button', { name: defaultProps.toggleContent })).toHaveAttribute('aria-expanded', 'true');
        expect(react_1.screen.getByText(defaultProps.cardTitle)).toBeVisible();
        expect(react_1.screen.getByText(defaultProps.cardBody)).toBeVisible();
    });
    it('expandableSectionProps.onToggle overrides internal onToggle behavior', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup();
        const customOnToggle = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { isDefaultExpanded: false, expandableSectionProps: { onToggle: customOnToggle } })));
        const toggleButton = react_1.screen.getByRole('button', { name: defaultProps.toggleContent });
        expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
        yield user.click(toggleButton);
        expect(customOnToggle).toHaveBeenCalledTimes(1);
        expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
        expect(react_1.screen.getByText(defaultProps.cardTitle)).not.toBeVisible();
        expect(react_1.screen.getByText(defaultProps.cardBody)).not.toBeVisible();
    }));
    it('should render toggleContent as markdown when isToggleContentMarkdown is true', () => {
        const toggleContent = '**Bold toggle**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { toggleContent: toggleContent, isToggleContentMarkdown: true })));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold toggle')).toBeTruthy();
    });
    it('should not render toggleContent as markdown when isToggleContentMarkdown is false', () => {
        const toggleContent = '**Bold toggle**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { toggleContent: toggleContent })));
        expect(react_1.screen.getByText('**Bold toggle**')).toBeTruthy();
    });
    it('should render subheading as markdown when isSubheadingMarkdown is true', () => {
        const subheading = '**Bold subheading**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { subheading: subheading, isSubheadingMarkdown: true })));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold subheading')).toBeTruthy();
    });
    it('should not render subheading as markdown when isSubheadingMarkdown is false', () => {
        const subheading = '**Bold subheading**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { subheading: subheading })));
        expect(react_1.screen.getByText('**Bold subheading**')).toBeTruthy();
    });
    it('should render body as markdown when isBodyMarkdown is true', () => {
        const body = '**Bold body**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true })));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold body')).toBeTruthy();
    });
    it('should not render body as markdown when isBodyMarkdown is false', () => {
        const body = '**Bold body**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body })));
        expect(react_1.screen.getByText('**Bold body**')).toBeTruthy();
    });
    it('should render cardTitle as markdown when isCardTitleMarkdown is true', () => {
        const cardTitle = '**Bold card title**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: cardTitle, isCardTitleMarkdown: true })));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold card title')).toBeTruthy();
    });
    it('should not render cardTitle as markdown when isCardTitleMarkdown is false', () => {
        const cardTitle = '**Bold card title**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: cardTitle })));
        expect(react_1.screen.getByText('**Bold card title**')).toBeTruthy();
    });
    it('should render cardBody as markdown when isCardBodyMarkdown is true', () => {
        const cardBody = '**Bold card body**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: cardBody, isCardBodyMarkdown: true })));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold card body')).toBeTruthy();
    });
    it('should not render cardBody as markdown when isCardBodyMarkdown is false', () => {
        const cardBody = '**Bold card body**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: cardBody })));
        expect(react_1.screen.getByText('**Bold card body**')).toBeTruthy();
    });
    it('should pass markdownContentProps to MarkdownContent component', () => {
        const body = '**Bold body**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true, markdownContentProps: { isPrimary: true } })));
        expect(container.querySelector('.pf-m-primary')).toBeTruthy();
    });
});
