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 React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { MessageBox } from './MessageBox';
import userEvent from '@testing-library/user-event';
describe('MessageBox', () => {
    it('should render Message box', () => {
        render(React.createElement(MessageBox, null,
            React.createElement(React.Fragment, null, "Chatbot Messages")));
        expect(screen.getByText('Chatbot Messages')).toBeTruthy();
    });
    it('should assign ref to Message box', () => {
        const ref = React.createRef();
        render(React.createElement(MessageBox, { ref: ref },
            React.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();
        render(React.createElement(MessageBox, { onScrollToBottomClick: spy },
            React.createElement("div", null, "Test message content")));
        // this forces button to show
        const region = 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 waitFor(() => {
            userEvent.click(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();
        render(React.createElement(MessageBox, { onScrollToTopClick: spy },
            React.createElement("div", null, "Test message content")));
        // this forces button to show
        const region = 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 waitFor(() => {
            userEvent.click(screen.getByRole('button', { name: /Jump top/i }));
            expect(spy).toHaveBeenCalled();
        });
    }));
});
