"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 react_1 = __importDefault(require("react"));
const react_2 = require("@testing-library/react");
const MessageBox_1 = require("./MessageBox");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
describe('MessageBox', () => {
    it('should render Message box', () => {
        (0, react_2.render)(react_1.default.createElement(MessageBox_1.MessageBox, null,
            react_1.default.createElement(react_1.default.Fragment, null, "Chatbot Messages")));
        expect(react_2.screen.getByText('Chatbot Messages')).toBeTruthy();
    });
    it('should assign ref to Message box', () => {
        const ref = react_1.default.createRef();
        (0, react_2.render)(react_1.default.createElement(MessageBox_1.MessageBox, { ref: ref },
            react_1.default.createElement("div", null, "Test message content")));
        expect(ref.current).not.toBeNull();
        expect(ref.current).toBeInstanceOf(HTMLDivElement);
    });
    it('should call onScrollToBottomClick when scroll to top button is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_2.render)(react_1.default.createElement(MessageBox_1.MessageBox, { onScrollToBottomClick: spy },
            react_1.default.createElement("div", null, "Test message content")));
        // this forces button to show
        const region = react_2.screen.getByRole('region');
        Object.defineProperty(region, 'scrollHeight', { configurable: true, value: 1000 });
        Object.defineProperty(region, 'clientHeight', { configurable: true, value: 500 });
        Object.defineProperty(region, 'scrollTop', { configurable: true, value: 0 });
        region.dispatchEvent(new Event('scroll'));
        yield (0, react_2.waitFor)(() => {
            user_event_1.default.click(react_2.screen.getByRole('button', { name: /Jump bottom/i }));
            expect(spy).toHaveBeenCalled();
        });
    }));
    it('should call onScrollToTopClick when scroll to top button is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_2.render)(react_1.default.createElement(MessageBox_1.MessageBox, { onScrollToTopClick: spy },
            react_1.default.createElement("div", null, "Test message content")));
        // this forces button to show
        const region = react_2.screen.getByRole('region');
        Object.defineProperty(region, 'scrollHeight', { configurable: true, value: 1000 });
        Object.defineProperty(region, 'clientHeight', { configurable: true, value: 500 });
        Object.defineProperty(region, 'scrollTop', {
            configurable: true,
            value: 500
        });
        region.dispatchEvent(new Event('scroll'));
        yield (0, react_2.waitFor)(() => {
            user_event_1.default.click(react_2.screen.getByRole('button', { name: /Jump top/i }));
            expect(spy).toHaveBeenCalled();
        });
    }));
});
