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