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 } from "react/jsx-runtime";
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import ToolCall from './ToolCall';
describe('ToolCall', () => {
    const defaultProps = {
        titleText: 'ToolCall Title',
        loadingText: 'Loading ToolCall'
    };
    it('Renders with passed in titleText', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps)));
        expect(screen.getByText(defaultProps.titleText)).toBeVisible();
    });
    it('Does not render with passed in loadingText when isLoading is false', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps)));
        expect(screen.queryByText(defaultProps.loadingText)).not.toBeInTheDocument();
    });
    it('Renders with passed in loadingText when isLoading is true', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { isLoading: true })));
        expect(screen.getByText(defaultProps.loadingText)).toBeVisible();
    });
    it('Does not render titleText when isLoading is true', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { isLoading: true })));
        expect(screen.queryByText(defaultProps.titleText)).not.toBeInTheDocument();
    });
    it('Passes spinnerProps to Spinner', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { isLoading: true, spinnerProps: { id: 'spinner-test-id' } })));
        expect(screen.getByRole('progressbar')).toHaveAttribute('id', 'spinner-test-id');
    });
    it('Does not render expandable toggle by default', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps)));
        expect(screen.queryByRole('button', { name: defaultProps.titleText })).not.toBeInTheDocument();
    });
    it('Renders titleText inside expandable toggle when expandableContent is passed', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        expect(screen.getByRole('button', { name: defaultProps.titleText })).toBeVisible();
    });
    it('Does not render expandable content when expandableContent is passed by default', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        expect(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 = userEvent.setup();
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { expandableContent: "Expandable Content" })));
        yield user.click(screen.getByRole('button', { name: defaultProps.titleText }));
        expect(screen.getByText('Expandable Content')).toBeVisible();
    }));
    it('Passes expandableSectionProps to ExpandableSection', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { expandableContent: "Expandable Content", expandableSectionProps: { id: 'expandable-section-test-id', isExpanded: true } })));
        expect(screen.getByRole('region').parentElement).toHaveAttribute('id', 'expandable-section-test-id');
    });
    it('Renders "run" action button by default', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps)));
        expect(screen.getByRole('button', { name: 'Run tool' })).toBeVisible();
    });
    it('Renders "cancel" action button by default', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps)));
        expect(screen.getByRole('button', { name: 'Cancel' })).toBeVisible();
    });
    it('Does not render "run" action button when isLoading is true', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { isLoading: true })));
        expect(screen.queryByRole('button', { name: 'Run tool' })).not.toBeInTheDocument();
    });
    it('Does not render "cancel" action button when isLoading is true', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { isLoading: true })));
        expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
    });
    it('Renders runButtonText when passed', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { runButtonText: "Run my custom tool" })));
        expect(screen.getByRole('button', { name: 'Run my custom tool' })).toBeVisible();
    });
    it('Renders cancelButtonText when passed', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cancelButtonText: "Cancel my custom tool" })));
        expect(screen.getByRole('button', { name: 'Cancel my custom tool' })).toBeVisible();
    });
    it('Passes runButtonProps to Button', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { runButtonProps: { id: 'run-button-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' })).toHaveAttribute('id', 'run-button-test-id');
    });
    it('Passes cancelButtonProps to Button', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cancelButtonProps: { id: 'cancel-button-test-id' } })));
        expect(screen.getByRole('button', { name: 'Cancel' })).toHaveAttribute('id', 'cancel-button-test-id');
    });
    it('Passes runActionItemProps to ActionListItem', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { runActionItemProps: { id: 'run-action-item-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).parentElement).toHaveAttribute('id', 'run-action-item-test-id');
    });
    it('Passes cancelActionItemProps to ActionListItem', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cancelActionItemProps: { id: 'cancel-action-item-test-id' } })));
        expect(screen.getByRole('button', { name: 'Cancel' }).parentElement).toHaveAttribute('id', 'cancel-action-item-test-id');
    });
    it('Passes actionListProps to ActionList', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { actionListProps: { id: 'action-list-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).closest('#action-list-test-id')).toBeVisible();
    });
    it('Passes actionListGroupProps to ActionListGroup', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { actionListGroupProps: { id: 'action-list-group-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).closest('#action-list-group-test-id')).toBeVisible();
    });
    it('Passes actionListItemProps to ActionListItem for default actions', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { actionListItemProps: { className: 'action-list-item-test-class' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).parentElement).toHaveClass('action-list-item-test-class');
        expect(screen.getByRole('button', { name: 'Cancel' }).parentElement).toHaveClass('action-list-item-test-class');
    });
    it('Renders custom actions instead of default actions when actions are passed', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { actions: [_jsx("div", { children: "Custom action 1" }, "custom-action-1"), _jsx("div", { children: "Custom action 2" }, "custom-action-2")] })));
        expect(screen.getByText('Custom action 1')).toBeVisible();
        expect(screen.getByText('Custom action 2')).toBeVisible();
        expect(screen.queryByRole('button', { name: 'Run tool' })).not.toBeInTheDocument();
        expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
    });
    it('Passes actionListItemProps to ActionListItem for custom actions', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { actions: [_jsx("div", { children: "Custom action 1" }, "custom-action-1"), _jsx("div", { children: "Custom action 2" }, "custom-action-2")], actionListItemProps: { className: 'action-list-item-test-class' } })));
        expect(screen.getByText('Custom action 1').parentElement).toHaveClass('action-list-item-test-class');
        expect(screen.getByText('Custom action 2').parentElement).toHaveClass('action-list-item-test-class');
    });
    it('Passes cardProps to Card', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cardProps: { id: 'card-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).closest('#card-test-id')).toBeVisible();
    });
    it('Passes cardBodyProps to CardBody', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cardBodyProps: { id: 'card-body-test-id' } })));
        expect(screen.getByText(defaultProps.titleText).closest('#card-body-test-id')).toBeVisible();
    });
    it('Passes cardFooterProps to CardFooter', () => {
        render(_jsx(ToolCall, Object.assign({}, defaultProps, { cardFooterProps: { id: 'card-footer-test-id' } })));
        expect(screen.getByRole('button', { name: 'Run tool' }).closest('#card-footer-test-id')).toBeVisible();
    });
});
