"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 ToolCall_1 = __importDefault(require("./ToolCall"));
describe('ToolCall', () => {
    const defaultProps = {
        titleText: 'ToolCall Title',
        loadingText: 'Loading ToolCall'
    };
    it('Renders with passed in titleText', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.getByText(defaultProps.titleText)).toBeVisible();
    });
    it('Does not render with passed in loadingText when isLoading is false', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.queryByText(defaultProps.loadingText)).not.toBeInTheDocument();
    });
    it('Renders with passed in loadingText when isLoading is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isLoading: true })));
        expect(react_1.screen.getByText(defaultProps.loadingText)).toBeVisible();
    });
    it('Does not render titleText when isLoading is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isLoading: true })));
        expect(react_1.screen.queryByText(defaultProps.titleText)).not.toBeInTheDocument();
    });
    it('Passes spinnerProps to Spinner', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isLoading: true, spinnerProps: { id: 'spinner-test-id' } })));
        expect(react_1.screen.getByRole('progressbar')).toHaveAttribute('id', 'spinner-test-id');
    });
    it('Does not render expandable toggle by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.queryByRole('button', { name: defaultProps.titleText })).not.toBeInTheDocument();
    });
    it('Renders titleText inside expandable toggle when expandableContent is passed', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        expect(react_1.screen.getByRole('button', { name: defaultProps.titleText })).toBeVisible();
    });
    it('Does not render expandable content when expandableContent is passed by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        expect(react_1.screen.queryByText('Expandable Content')).not.toBeVisible();
    });
    it('Renders expandable content when expandableContent is passed and toggle is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        yield user.click(react_1.screen.getByRole('button', { name: defaultProps.titleText }));
        expect(react_1.screen.getByText('Expandable Content')).toBeVisible();
    }));
    it('Passes expandableSectionProps to ExpandableSection', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: "Expandable Content", expandableSectionProps: { id: 'expandable-section-test-id', isExpanded: true } })));
        expect(react_1.screen.getByRole('region').parentElement).toHaveAttribute('id', 'expandable-section-test-id');
    });
    it('Renders "run" action button by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' })).toBeVisible();
    });
    it('Renders "cancel" action button by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps)));
        expect(react_1.screen.getByRole('button', { name: 'Cancel' })).toBeVisible();
    });
    it('Does not render "run" action button when isLoading is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isLoading: true })));
        expect(react_1.screen.queryByRole('button', { name: 'Run tool' })).not.toBeInTheDocument();
    });
    it('Does not render "cancel" action button when isLoading is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isLoading: true })));
        expect(react_1.screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
    });
    it('Renders runButtonText when passed', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { runButtonText: "Run my custom tool" })));
        expect(react_1.screen.getByRole('button', { name: 'Run my custom tool' })).toBeVisible();
    });
    it('Renders cancelButtonText when passed', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cancelButtonText: "Cancel my custom tool" })));
        expect(react_1.screen.getByRole('button', { name: 'Cancel my custom tool' })).toBeVisible();
    });
    it('Passes runButtonProps to Button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { runButtonProps: { id: 'run-button-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' })).toHaveAttribute('id', 'run-button-test-id');
    });
    it('Passes cancelButtonProps to Button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cancelButtonProps: { id: 'cancel-button-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Cancel' })).toHaveAttribute('id', 'cancel-button-test-id');
    });
    it('Passes runActionItemProps to ActionListItem', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { runActionItemProps: { id: 'run-action-item-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).parentElement).toHaveAttribute('id', 'run-action-item-test-id');
    });
    it('Passes cancelActionItemProps to ActionListItem', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cancelActionItemProps: { id: 'cancel-action-item-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Cancel' }).parentElement).toHaveAttribute('id', 'cancel-action-item-test-id');
    });
    it('Passes actionListProps to ActionList', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { actionListProps: { id: 'action-list-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).closest('#action-list-test-id')).toBeVisible();
    });
    it('Passes actionListGroupProps to ActionListGroup', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { actionListGroupProps: { id: 'action-list-group-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).closest('#action-list-group-test-id')).toBeVisible();
    });
    it('Passes actionListItemProps to ActionListItem for default actions', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { actionListItemProps: { className: 'action-list-item-test-class' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).parentElement).toHaveClass('action-list-item-test-class');
        expect(react_1.screen.getByRole('button', { name: 'Cancel' }).parentElement).toHaveClass('action-list-item-test-class');
    });
    it('Renders custom actions instead of default actions when actions are passed', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { actions: [(0, jsx_runtime_1.jsx)("div", { children: "Custom action 1" }, "custom-action-1"), (0, jsx_runtime_1.jsx)("div", { children: "Custom action 2" }, "custom-action-2")] })));
        expect(react_1.screen.getByText('Custom action 1')).toBeVisible();
        expect(react_1.screen.getByText('Custom action 2')).toBeVisible();
        expect(react_1.screen.queryByRole('button', { name: 'Run tool' })).not.toBeInTheDocument();
        expect(react_1.screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
    });
    it('Passes actionListItemProps to ActionListItem for custom actions', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { actions: [(0, jsx_runtime_1.jsx)("div", { children: "Custom action 1" }, "custom-action-1"), (0, jsx_runtime_1.jsx)("div", { children: "Custom action 2" }, "custom-action-2")], actionListItemProps: { className: 'action-list-item-test-class' } })));
        expect(react_1.screen.getByText('Custom action 1').parentElement).toHaveClass('action-list-item-test-class');
        expect(react_1.screen.getByText('Custom action 2').parentElement).toHaveClass('action-list-item-test-class');
    });
    it('Passes cardProps to Card', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cardProps: { id: 'card-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).closest('#card-test-id')).toBeVisible();
    });
    it('Passes cardBodyProps to CardBody', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cardBodyProps: { id: 'card-body-test-id' } })));
        expect(react_1.screen.getByText(defaultProps.titleText).closest('#card-body-test-id')).toBeVisible();
    });
    it('Passes cardFooterProps to CardFooter', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { cardFooterProps: { id: 'card-footer-test-id' } })));
        expect(react_1.screen.getByRole('button', { name: 'Run tool' }).closest('#card-footer-test-id')).toBeVisible();
    });
    it('Renders collapsed by default when expandableContent is provided', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        expect(react_1.screen.getByRole('button', { name: defaultProps.titleText })).toHaveAttribute('aria-expanded', 'false');
        expect(react_1.screen.queryByText('Expandable Content')).not.toBeVisible();
    });
    it('Renders expanded when isDefaultExpanded is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isDefaultExpanded: true, expandableContent: "Expandable Content" })));
        expect(react_1.screen.getByRole('button', { name: defaultProps.titleText })).toHaveAttribute('aria-expanded', 'true');
        expect(react_1.screen.getByText('Expandable Content')).toBeVisible();
    });
    it('expandableSectionProps.isExpanded overrides isDefaultExpanded', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { isDefaultExpanded: false, expandableContent: "Expandable Content", expandableSectionProps: { isExpanded: true } })));
        expect(react_1.screen.getByRole('button', { name: defaultProps.titleText })).toHaveAttribute('aria-expanded', 'true');
        expect(react_1.screen.getByText('Expandable Content')).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)(ToolCall_1.default, Object.assign({}, defaultProps, { isDefaultExpanded: false, expandableContent: "Expandable Content", expandableSectionProps: { onToggle: customOnToggle } })));
        const toggleButton = react_1.screen.getByRole('button', { name: defaultProps.titleText });
        expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
        yield user.click(toggleButton);
        expect(customOnToggle).toHaveBeenCalledTimes(1);
        expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
        expect(react_1.screen.queryByText('Expandable Content')).not.toBeVisible();
    }));
    it('should render titleText as markdown when isTitleMarkdown is true', () => {
        const titleText = '**Bold title**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText, isTitleMarkdown: true }));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold title')).toBeTruthy();
    });
    it('should not render titleText as markdown when isTitleMarkdown is false', () => {
        const titleText = '**Bold title**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText }));
        expect(react_1.screen.getByText('**Bold title**')).toBeTruthy();
    });
    it('should render expandableContent as markdown when isExpandableContentMarkdown is true', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup();
        const expandableContent = '**Bold expandable content**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: expandableContent, isExpandableContentMarkdown: true })));
        yield user.click(react_1.screen.getByRole('button', { name: defaultProps.titleText }));
        expect(container.querySelector('strong')).toBeTruthy();
        expect(react_1.screen.getByText('Bold expandable content')).toBeTruthy();
    }));
    it('should not render expandableContent as markdown when isExpandableContentMarkdown is false', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup();
        const expandableContent = '**Bold expandable content**';
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: expandableContent })));
        yield user.click(react_1.screen.getByRole('button', { name: defaultProps.titleText }));
        expect(react_1.screen.getByText('**Bold expandable content**')).toBeTruthy();
    }));
    it('should pass markdownContentProps to MarkdownContent component', () => {
        const titleText = '**Bold title**';
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText, isTitleMarkdown: true, markdownContentProps: { isPrimary: true } }));
        expect(container.querySelector('.pf-m-primary')).toBeTruthy();
    });
});
