"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");
const react_1 = 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_1.render)((0, jsx_runtime_1.jsx)(ChatbotFootnote_1.default, { label: "Chatbot footer" }));
        expect(react_1.screen.getByText('Chatbot footer')).toBeTruthy();
    });
    it('should render ChatbotFooternote with popover', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_1.act)(() => {
            react_1.fireEvent.click(react_1.screen.getByRole('button'));
        });
        yield (0, react_1.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_1.screen.getByLabelText('More information');
            react_1.screen.getByText('Verify accuracy');
            react_1.fireEvent.click(react_1.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_1.render)((0, jsx_runtime_1.jsx)(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_1.act)(() => {
            react_1.fireEvent.click(react_1.screen.getByRole('button'));
        });
        yield (0, react_1.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_1.screen.getByLabelText('More information');
            react_1.screen.getByText('Verify accuracy');
            react_1.fireEvent.click(react_1.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_1.render)((0, jsx_runtime_1.jsx)(ChatbotFootnote_1.default, { label: "Chatbot footer", popover: popoverProps }));
        // click on the footer button
        (0, react_1.act)(() => {
            react_1.fireEvent.click(react_1.screen.getByRole('button'));
        });
        yield (0, react_1.waitFor)(() => {
            // Check if the popover is visible and click on the cta button
            react_1.screen.getByLabelText('More information');
            react_1.screen.getByText('Verify accuracy');
        });
        (0, react_1.act)(() => {
            // trigger escape to close the popover
            react_1.fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' });
        });
        yield (0, react_1.waitFor)(() => {
            expect(react_1.screen.queryByText('Verify accuracy')).toBeFalsy();
        });
    }));
});
