"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 AttachmentEdit_1 = __importDefault(require("./AttachmentEdit"));
describe('AttachmentEdit', () => {
    it('should open AttachmentEdit modal', () => {
        const props = {
            code: 'code',
            fileName: 'fileName',
            onCancel: jest.fn(),
            onSave: jest.fn(),
            isModalOpen: true,
            handleModalToggle: jest.fn()
        };
        (0, react_1.render)((0, jsx_runtime_1.jsx)(AttachmentEdit_1.default, Object.assign({}, props)));
        expect(react_1.screen.getByText('Edit attachment')).toBeTruthy();
    });
    it('should call onSave handler when the save button is clicked', () => {
        const onSaveHandler = jest.fn();
        const props = {
            code: 'code',
            fileName: 'fileName',
            onCancel: jest.fn(),
            onSave: onSaveHandler,
            isModalOpen: true,
            handleModalToggle: jest.fn()
        };
        (0, react_1.render)((0, jsx_runtime_1.jsx)(AttachmentEdit_1.default, Object.assign({}, props)));
        // Click on save button
        react_1.fireEvent.click(react_1.screen.getByText('Save'));
        expect(onSaveHandler).toHaveBeenCalledWith(expect.any(Object), 'code');
    });
    it('should call cancel handler when the cancel button is clicked', () => {
        const onCancelHandler = jest.fn();
        const props = {
            code: 'code',
            fileName: 'fileName',
            onCancel: onCancelHandler,
            onSave: jest.fn(),
            isModalOpen: true,
            handleModalToggle: jest.fn()
        };
        (0, react_1.render)((0, jsx_runtime_1.jsx)(AttachmentEdit_1.default, Object.assign({}, props)));
        // Click on cancel button
        react_1.fireEvent.click(react_1.screen.getByText('Cancel'));
        expect(onCancelHandler).toHaveBeenCalled();
    });
    it('should render custom button text for footer actions buttons', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(AttachmentEdit_1.default, { code: "Hello world", fileName: "greetings.txt", isModalOpen: true, onCancel: jest.fn(), onSave: jest.fn(), handleModalToggle: jest.fn(), primaryActionButtonText: "Save", secondaryActionButtonText: "Close" }));
        expect(react_1.screen.getByText('Save')).toBeInTheDocument();
        expect(react_1.screen.getByText('Close')).toBeInTheDocument();
    });
    it('should render AttachmentEdit with custom classNames', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(AttachmentEdit_1.default, { code: "Hello world", fileName: "greetings.txt", isModalOpen: true, onCancel: jest.fn(), onSave: jest.fn(), handleModalToggle: jest.fn(), primaryActionButtonText: "Save", secondaryActionButtonText: "Close", modalHeaderClassName: "custom-header-class", modalBodyClassName: "custom-body-class", modalFooterClassName: "custom-footer-class" }));
        const modal = react_1.screen.getByRole('dialog');
        const modalHeader = (0, react_1.within)(modal).getByRole('banner');
        expect(modalHeader).toHaveClass('custom-header-class');
        const modalBody = modal.querySelector('#code-modal-body');
        expect(modalBody).toHaveClass('custom-body-class');
        const modalfooter = (0, react_1.within)(modal).getByRole('contentinfo');
        expect(modalfooter).toHaveClass('custom-footer-class');
    }));
});
