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, jsxs as _jsxs } from "react/jsx-runtime";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import TermsOfUse from './TermsOfUse';
import { Content } from '@patternfly/react-core';
const handleModalToggle = jest.fn();
const onPrimaryAction = jest.fn();
const onSecondaryAction = jest.fn();
const body = (_jsxs(Content, { children: [_jsx("h1", { children: "Heading 1" }), _jsx("p", { children: "Legal text" })] }));
describe('TermsOfUse', () => {
    afterEach(() => {
        jest.clearAllMocks();
    });
    it('should render modal correctly', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, ouiaId: "Terms", children: body }));
        expect(screen.getByRole('heading', { name: /Terms of use/i })).toBeTruthy();
        expect(screen.getByRole('button', { name: /Accept/i })).toBeTruthy();
        expect(screen.getByRole('button', { name: /Decline/i })).toBeTruthy();
        expect(screen.getByRole('heading', { name: /Heading 1/i })).toBeTruthy();
        expect(screen.getByText(/Legal text/i)).toBeTruthy();
        expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal');
        expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal--default');
    });
    it('should handle image and altText props', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, image: "./image.png", altText: "Test image", children: body }));
        expect(screen.getByRole('img')).toBeTruthy();
        expect(screen.getByRole('img')).toHaveAttribute('alt', 'Test image');
    });
    it('should handle className prop', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, className: "test", children: body }));
        expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal');
        expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal--default');
        expect(screen.getByRole('dialog')).toHaveClass('test');
    });
    it('should handle title prop', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, title: "Updated title", children: body }));
        expect(screen.getByRole('heading', { name: /Updated title/i })).toBeTruthy();
        expect(screen.queryByRole('heading', { name: /Terms of use/i })).toBeFalsy();
    });
    it('should handle primary button prop', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, primaryActionBtn: "First", children: body }));
        expect(screen.getByRole('button', { name: /First/i })).toBeTruthy();
        expect(screen.queryByRole('button', { name: /Accept/i })).toBeFalsy();
    });
    it('should handle secondary button prop', () => {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, secondaryActionBtn: "Second", children: body }));
        expect(screen.getByRole('button', { name: /Second/i })).toBeTruthy();
        expect(screen.queryByRole('button', { name: /Deny/i })).toBeFalsy();
    });
    it('should handle primary button click', () => __awaiter(void 0, void 0, void 0, function* () {
        render(_jsx(TermsOfUse, { isModalOpen: true, onPrimaryAction: onPrimaryAction, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, children: body }));
        yield userEvent.click(screen.getByRole('button', { name: /Accept/i }));
        expect(onPrimaryAction).toHaveBeenCalledTimes(1);
        expect(handleModalToggle).toHaveBeenCalledTimes(1);
    }));
    it('should handle secondary button click', () => __awaiter(void 0, void 0, void 0, function* () {
        render(_jsx(TermsOfUse, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, children: body }));
        yield userEvent.click(screen.getByRole('button', { name: /Decline/i }));
        expect(onSecondaryAction).toHaveBeenCalledTimes(1);
        expect(handleModalToggle).not.toHaveBeenCalled();
    }));
});
