"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 ChatbotFootnote_1 = __importDefault(require("./ChatbotFootnote"));
describe('ChatbotFooternote', () => {
    const onClick = jest.fn();
    const popoverProps = {
        title: 'Verify accuracy',
        description: 'description',
        bannerImage: {
            src: 'src',
            alt: 'alt'
        },
        cta: {
            label: 'Got it',
            onClick
        },
        link: {
            label: 'label',
            url: 'url'
        }
    };
    it('should render ChatbotFooternote', () => {
        (0, react_2.render)(react_1.default.createElement(ChatbotFootnote_1.default, { label: "Chatbot footer" }));
        expect(react_2.screen.getByText('Chatbot footer')).toBeTruthy();
    });
    it('should render ChatbotFooternote with popover', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_2.act)(() => {
            react_2.fireEvent.click(react_2.screen.getByRole('button'));
        });
        yield (0, react_2.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_2.screen.getByLabelText('More information');
            react_2.screen.getByText('Verify accuracy');
            react_2.fireEvent.click(react_2.screen.getByRole('button', { name: 'Got it' }));
            expect(onClick).toHaveBeenCalled();
        });
    }));
    it('should call onClick handler when popover cta button is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_2.act)(() => {
            react_2.fireEvent.click(react_2.screen.getByRole('button'));
        });
        yield (0, react_2.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_2.screen.getByLabelText('More information');
            react_2.screen.getByText('Verify accuracy');
            react_2.fireEvent.click(react_2.screen.getByRole('button', { name: 'Got it' }));
            expect(onClick).toHaveBeenCalled();
        });
    }));
    it('should close the popover when escape is pressed', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_2.act)(() => {
            react_2.fireEvent.click(react_2.screen.getByRole('button'));
        });
        yield (0, react_2.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_2.screen.getByLabelText('More information');
            react_2.screen.getByText('Verify accuracy');
        });
        (0, react_2.act)(() => {
            // trigger escape to close the popover
            react_2.fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' });
        });
        yield (0, react_2.waitFor)(() => {
            expect(react_2.screen.queryByText('Verify accuracy')).toBeFalsy();
        });
    }));
});
