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