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