"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");
require("@testing-library/jest-dom");
const react_core_1 = require("@patternfly/react-core");
const react_icons_1 = require("@patternfly/react-icons");
const react_1 = require("@testing-library/react");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const react_2 = require("react");
const SourceDetailsMenuItem_1 = __importDefault(require("../SourceDetailsMenuItem"));
const MessageBar_1 = require("./MessageBar");
const ATTACH_MENU_ITEMS = [
    (0, jsx_runtime_1.jsx)(react_core_1.DropdownList, { children: (0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { className: "pf-chatbot-source-details-dropdown-item", value: "auth-operator Pod", id: "0", children: (0, jsx_runtime_1.jsx)(SourceDetailsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsxs)("svg", { width: "24", height: "25", viewBox: "0 0 24 25", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [(0, jsx_runtime_1.jsx)("path", { d: "M0 12.5C0 5.87258 5.37258 0.5 12 0.5C18.6274 0.5 24 5.87258 24 12.5C24 19.1274 18.6274 24.5 12 24.5C5.37258 24.5 0 19.1274 0 12.5Z", fill: "currentColor" }), (0, jsx_runtime_1.jsx)("g", { clipPath: "url(#clip0_3280_27488)", children: (0, jsx_runtime_1.jsx)("path", { d: "M8.25 8.75C8.25 7.92266 8.92266 7.25 9.75 7.25H12C14.0719 7.25 15.75 8.92812 15.75 11C15.75 13.0719 14.0719 14.75 12 14.75H9.75V17C9.75 17.4148 9.41484 17.75 9 17.75C8.58516 17.75 8.25 17.4148 8.25 17V14V8.75ZM9.75 13.25H12C13.2422 13.25 14.25 12.2422 14.25 11C14.25 9.75781 13.2422 8.75 12 8.75H9.75V13.25Z", fill: "white" }) }), (0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsx)("clipPath", { id: "clip0_3280_27488", children: (0, jsx_runtime_1.jsx)("rect", { width: "7.5", height: "12", fill: "white", transform: "translate(8.25 6.5)" }) }) })] }), name: "auth-operator", type: "Pod" }) }) }, "list-1"),
    (0, jsx_runtime_1.jsx)(react_core_1.DropdownGroup, { children: (0, jsx_runtime_1.jsxs)(react_core_1.DropdownList, { children: [(0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { value: "Alerts", id: "1", icon: (0, jsx_runtime_1.jsx)(react_icons_1.BellIcon, {}), children: "Alerts" }), (0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { value: "Events", id: "2", icon: (0, jsx_runtime_1.jsx)(react_icons_1.CalendarAltIcon, {}), children: "Events" }), (0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { value: "Logs", id: "3", icon: (0, jsx_runtime_1.jsx)(react_icons_1.ClipboardIcon, {}), children: "Logs" }), (0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { value: "YAML - Status", id: "4", icon: (0, jsx_runtime_1.jsx)(react_icons_1.CodeIcon, {}), children: "YAML - Status" }), (0, jsx_runtime_1.jsx)(react_core_1.DropdownItem, { value: "YAML - All contents", id: "5", icon: (0, jsx_runtime_1.jsx)(react_icons_1.CodeIcon, {}), children: "YAML - All contents" })] }) }, "group2")
];
const originalSpeechRecognition = window.SpeechRecognition;
const mockSpeechRecognition = () => {
    const MockSpeechRecognition = jest.fn().mockImplementation(() => ({
        start: jest.fn(),
        stop: jest.fn()
    }));
    MockSpeechRecognition.prototype = {};
    window.SpeechRecognition = MockSpeechRecognition;
};
describe('Message bar', () => {
    afterAll(() => {
        window.SpeechRecognition = originalSpeechRecognition;
    });
    it('should render correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn }));
        expect(react_1.screen.getByRole('button', { name: 'Attach' })).toBeTruthy();
        expect(react_1.screen.queryByRole('button', { name: 'Send' })).toBeFalsy();
        expect(react_1.screen.queryByRole('button', { name: 'Use microphone' })).toBeFalsy();
        expect(react_1.screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
    });
    it('can send via enter key', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: spy }));
        const input = react_1.screen.getByRole('textbox', { name: /Send a message.../i });
        yield user_event_1.default.type(input, 'Hello world');
        expect(input).toHaveTextContent('Hello world');
        yield user_event_1.default.type(input, '[Enter]');
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('calls onChange callback appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, onChange: spy }));
        const input = react_1.screen.getByRole('textbox', { name: /Send a message.../i });
        yield user_event_1.default.type(input, 'A');
        expect(input).toHaveTextContent('A');
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy).toHaveBeenCalledWith(expect.any(Object), 'A');
    }));
    it('can use specified placeholder text', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, placeholder: "test placeholder" }));
        const input = react_1.screen.getByRole('textbox', { name: /test placeholder/i });
        yield user_event_1.default.type(input, 'Hello world');
        expect(input).toHaveTextContent('Hello world');
    }));
    // Send button
    // --------------------------------------------------------------------------
    it('shows send button when text is input', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn }));
        const input = react_1.screen.getByRole('textbox', { name: /Send a message.../i });
        yield user_event_1.default.type(input, 'Hello world');
        expect(input).toHaveTextContent('Hello world');
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeTruthy();
    }));
    it('can disable send button shown when text is input', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, isSendButtonDisabled: true }));
        const input = react_1.screen.getByRole('textbox', { name: /Send a message.../i });
        yield user_event_1.default.type(input, 'Hello world');
        expect(input).toHaveTextContent('Hello world');
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeDisabled();
    }));
    it('can click send button', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: spy }));
        const input = react_1.screen.getByRole('textbox', { name: /Send a message.../i });
        yield user_event_1.default.type(input, 'Hello world');
        expect(input).toHaveTextContent('Hello world');
        const sendButton = react_1.screen.getByRole('button', { name: 'Send' });
        expect(sendButton).toBeTruthy();
        yield user_event_1.default.click(sendButton);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('can always show send button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true }));
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeEnabled();
    });
    it('can disable send button if always showing', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true, isSendButtonDisabled: true }));
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeDisabled();
    });
    it('can handle buttonProps tooltipContent  appropriately for send', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true, buttonProps: { send: { tooltipContent: 'Test' } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Send' }));
        expect(react_1.screen.getByRole('tooltip', { name: 'Test' })).toBeTruthy();
    }));
    it('can handle buttonProps tooltipProps  appropriately for send', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true, buttonProps: { send: { tooltipProps: { isVisible: true } } } }));
        // isVisible, so no need for click
        expect(react_1.screen.getByRole('tooltip', { name: 'Send' })).toBeTruthy();
    });
    it('can handle buttonProps props appropriately for send', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true, buttonProps: { send: { props: { 'aria-label': 'Test' } } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Test' }));
    }));
    // Attach button
    // --------------------------------------------------------------------------
    it('can show attach menu', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, attachMenuProps: {
                isAttachMenuOpen: true,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: jest.fn(),
                onAttachMenuInputChange: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS
            } }));
        expect(react_1.screen.getByRole('textbox', { name: /Filter menu items/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /auth-operator/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /Alerts/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /Events/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /Logs/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /YAML - Status/i })).toBeTruthy();
        expect(react_1.screen.getByRole('menuitem', { name: /YAML - All contents/i })).toBeTruthy();
    }));
    it('can toggle attach menu', () => __awaiter(void 0, void 0, void 0, function* () {
        const attachToggleClickSpy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, attachMenuProps: {
                isAttachMenuOpen: false,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: attachToggleClickSpy,
                onAttachMenuInputChange: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS
            } }));
        expect(react_1.screen.queryByRole('textbox', { name: /Filter menu items/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /auth-operator/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /Alerts/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /Events/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /Logs/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /YAML - Status/i })).toBeFalsy();
        expect(react_1.screen.queryByRole('menuitem', { name: /YAML - All contents/i })).toBeFalsy();
        const attachButton = react_1.screen.getByRole('button', { name: 'Attach' });
        yield user_event_1.default.click(attachButton);
        expect(attachToggleClickSpy).toHaveBeenCalledTimes(1);
    }));
    it('can pass searchInputProps to search input in AttachMenu', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, value: "test", attachMenuProps: {
                isAttachMenuOpen: true,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: jest.fn(),
                onAttachMenuInputChange: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS,
                searchInputProps: { isDisabled: true }
            } }));
        expect(react_1.screen.getByRole('textbox', { name: /Filter menu items/i })).toBeDisabled();
    });
    it('can pass menuSearchProps to search input in AttachMenu', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, value: "test", attachMenuProps: {
                isAttachMenuOpen: true,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: jest.fn(),
                onAttachMenuInputChange: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS,
                menuSearchProps: { 'data-testid': 'menu-search' }
            } }));
        expect(react_1.screen.getByTestId('menu-search')).toBeTruthy();
    });
    it('can pass menuSearchInputProps to search input in AttachMenu', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, value: "test", attachMenuProps: {
                isAttachMenuOpen: true,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: jest.fn(),
                onAttachMenuInputChange: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS,
                menuSearchInputProps: { 'data-testid': 'menu-search-input' }
            } }));
        expect(react_1.screen.getByTestId('menu-search-input')).toBeTruthy();
    });
    it('can remove input from attach menu', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, attachMenuProps: {
                isAttachMenuOpen: true,
                setIsAttachMenuOpen: jest.fn(),
                onAttachMenuToggleClick: jest.fn(),
                attachMenuItems: ATTACH_MENU_ITEMS
            } }));
        expect(react_1.screen.queryByRole('textbox', { name: /Filter menu items/i })).not.toBeInTheDocument();
    }));
    it('can hide attach button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAttachButton: false }));
        expect(react_1.screen.queryByRole('button', { name: 'Attach' })).toBeFalsy();
    });
    // Based on this because I had no idea how to do this and was looking around: https://stackoverflow.com/a/75562651
    // See also https://developer.mozilla.org/en-US/docs/Web/API/File/File for what that file variable is doing
    it('can handle handleAttach', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAttachButton: true, handleAttach: spy, buttonProps: { attach: { inputTestId: 'input' } } }));
        expect(react_1.screen.getByRole('button', { name: 'Attach' })).toBeTruthy();
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Attach' }));
        const file = new File(['test'], 'test.json');
        const input = react_1.screen.getByTestId('input');
        yield user_event_1.default.upload(input, file);
        expect(input.files).toHaveLength(1);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('can handle buttonProps tooltipContent appropriately for attach', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAttachButton: true, buttonProps: { attach: { tooltipContent: 'Test' } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Attach' }));
        expect(react_1.screen.getByRole('tooltip', { name: 'Test' })).toBeTruthy();
    }));
    it('can handle buttonProps tooltipProps  appropriately for attach', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, alwayShowSendButton: true, buttonProps: { attach: { tooltipProps: { isVisible: true } } } }));
        // isVisible, so no need for click
        expect(react_1.screen.getByRole('tooltip', { name: 'Attach' })).toBeTruthy();
    });
    it('can handle buttonProps props appropriately for attach', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAttachButton: true, buttonProps: { attach: { props: { 'aria-label': 'Test' } } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Test' }));
    }));
    it('can change attach button icon', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAttachButton: true, buttonProps: {
                attach: {
                    icon: (0, jsx_runtime_1.jsx)("img", { alt: "", src: "" })
                }
            } }));
        expect(react_1.screen.getByRole('img')).toBeVisible();
    });
    // Stop button
    // --------------------------------------------------------------------------
    it('can show stop button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasStopButton: true, handleStopButton: jest.fn }));
        expect(react_1.screen.getByRole('button', { name: 'Stop' })).toBeTruthy();
    });
    it('can call handleStopButton', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasStopButton: true, handleStopButton: spy }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Stop' }));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('can handle buttonProps tooltipContent appropriately for stop', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasStopButton: true, handleStopButton: jest.fn, buttonProps: { stop: { tooltipContent: 'Test' } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Stop' }));
        expect(react_1.screen.getByRole('tooltip', { name: 'Test' })).toBeTruthy();
    }));
    it('can handle buttonProps tooltipProps  appropriately for stop', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasStopButton: true, handleStopButton: jest.fn, buttonProps: { stop: { tooltipProps: { isVisible: true } } } }));
        // isVisible, so no need for click
        expect(react_1.screen.getByRole('tooltip', { name: 'Stop' })).toBeTruthy();
    });
    it('can handle buttonProps props appropriately for stop', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasStopButton: true, handleStopButton: jest.fn, buttonProps: { stop: { props: { 'aria-label': 'Test' } } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Test' }));
    }));
    // Microphone button
    // --------------------------------------------------------------------------
    it('can hide microphone button when window.SpeechRecognition is not there', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true }));
        expect(react_1.screen.queryByRole('button', { name: 'Use microphone' })).toBeFalsy();
    });
    it('can show microphone button', () => {
        mockSpeechRecognition();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true }));
        expect(react_1.screen.getByRole('button', { name: 'Use microphone' })).toBeTruthy();
    });
    it('can handle buttonProps appropriately for microphone', () => __awaiter(void 0, void 0, void 0, function* () {
        mockSpeechRecognition();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: {
                microphone: { tooltipContent: { active: 'Currently listening', inactive: 'Not currently listening' } }
            } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Use microphone' }));
        expect(react_1.screen.getByRole('tooltip', { name: 'Currently listening' })).toBeTruthy();
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Stop listening' }));
        expect(react_1.screen.getByRole('tooltip', { name: 'Not currently listening' })).toBeTruthy();
    }));
    it('can customize the listening placeholder', () => __awaiter(void 0, void 0, void 0, function* () {
        mockSpeechRecognition();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, listeningText: "I am listening" }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Use microphone' }));
        const input = react_1.screen.getByRole('textbox', { name: /I am listening/i });
        expect(input).toBeTruthy();
    }));
    it('can handle buttonProps tooltipProps  appropriately for microphone', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { tooltipProps: { isVisible: true } } } }));
        // isVisible, so no need for click
        expect(react_1.screen.getByRole('tooltip', { name: 'Use microphone' })).toBeTruthy();
    });
    it('can handle buttonProps props appropriately for microphone', () => __awaiter(void 0, void 0, void 0, function* () {
        mockSpeechRecognition();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { props: { 'aria-label': 'Test' } } } }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Test' }));
    }));
    it('can be controlled', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, value: "test" }));
        expect(react_1.screen.getByRole('button', { name: 'Attach' })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: 'Send' })).toBeTruthy();
        expect(react_1.screen.queryByRole('button', { name: 'Use microphone' })).toBeFalsy();
        expect(react_1.screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
        expect(react_1.screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
    });
    it('should focus textarea when using a custom ref', () => {
        var _a;
        const ref = (0, react_2.createRef)();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, innerRef: ref }));
        (_a = ref.current) === null || _a === void 0 ? void 0 : _a.focus();
        expect(document.activeElement).toBe(react_1.screen.getByRole('textbox'));
    });
    it('should handle isPrimary', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { isPrimary: true, onSendMessage: jest.fn }));
        expect(container.querySelector('.pf-m-primary')).toBeTruthy();
    });
    it('Renders with class pf-v6-m-ai-indicator when hasAiIndicator is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasAiIndicator: true }));
        expect(react_1.screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-ai-indicator');
    });
    it('Renders with class pf-v6-m-thinking when isThinking is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, isThinking: true }));
        expect(react_1.screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-thinking');
    });
    it('Renders with flex-basis of auto by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn }));
        expect(react_1.screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: auto;');
    });
    it('Renders with flex-basis of 100% when forceMultilineLayout is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { forceMultilineLayout: true, onSendMessage: jest.fn }));
        expect(react_1.screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: 100%;');
    });
    it('Renders with flex-basis of 100% when additionalActions is truthy', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { additionalActions: "actions", onSendMessage: jest.fn }));
        expect(react_1.screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: 100%;');
    });
});
