"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");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
require("@testing-library/jest-dom");
const SourcesCardBase_1 = __importDefault(require("./SourcesCardBase"));
describe('SourcesCardBase', () => {
    it('should render card correctly if one source with only a link is passed in', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ link: '' }] }));
        expect(react_1.screen.getByText('Source 1')).toBeTruthy();
        // no buttons or navigation when there is only 1 source
        expect(react_1.screen.queryByRole('button')).toBeFalsy();
        expect(react_1.screen.queryByText('1/1')).toBeFalsy();
    });
    it('should render card correctly if one source with a title is passed in', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ title: 'How to make an apple pie', link: '' }] }));
        expect(react_1.screen.getByText('How to make an apple pie')).toBeTruthy();
    });
    it('should render card correctly if one source with a body is passed in', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ link: '', body: 'To make an apple pie, you must first...' }] }));
        expect(react_1.screen.getByText('To make an apple pie, you must first...')).toBeTruthy();
    });
    it('should render card correctly if one source with a title and body is passed in', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ title: 'How to make an apple pie', link: '', body: 'To make an apple pie, you must first...' }] }));
        expect(react_1.screen.getByText('How to make an apple pie')).toBeTruthy();
        expect(react_1.screen.getByText('To make an apple pie, you must first...')).toBeTruthy();
    });
    it('should render multiple cards correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ] }));
        expect(react_1.screen.getByText('How to make an apple pie')).toBeTruthy();
        expect(react_1.screen.getByText('1/2')).toBeTruthy();
        react_1.screen.getByRole('button', { name: /Go to previous page/i });
        react_1.screen.getByRole('button', { name: /Go to next page/i });
    });
    it('should navigate between cards correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ] }));
        expect(react_1.screen.getByText('How to make an apple pie')).toBeTruthy();
        expect(react_1.screen.getByText('1/2')).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Go to previous page/i })).toBeDisabled();
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to next page/i }));
        expect(react_1.screen.queryByText('How to make an apple pie')).toBeFalsy();
        expect(react_1.screen.getByText('How to make cookies')).toBeTruthy();
        expect(react_1.screen.getByText('2/2')).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Go to previous page/i })).toBeEnabled();
        expect(react_1.screen.getByRole('button', { name: /Go to next page/i })).toBeDisabled();
    }));
    it('should apply className appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], className: "test" }));
        const element = react_1.screen.getByRole('navigation');
        expect(element).toHaveClass('test');
    });
    it('should disable pagination appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], isDisabled: true }));
        expect(react_1.screen.getByRole('button', { name: /Go to previous page/i })).toBeDisabled();
        expect(react_1.screen.getByRole('button', { name: /Go to next page/i })).toBeDisabled();
    });
    it('should render navigation aria label appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ] }));
        expect(react_1.screen.getByRole('navigation', { name: /Pagination/i })).toBeTruthy();
    });
    it('should change paginationAriaLabel appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], paginationAriaLabel: "Navegaci\u00F3n" }));
        expect(react_1.screen.getByRole('navigation', { name: /Navegación/i })).toBeTruthy();
    });
    it('should change toNextPageAriaLabel appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], toNextPageAriaLabel: "Pase a la siguiente p\u00E1gina" }));
        expect(react_1.screen.getByRole('button', { name: /Pase a la siguiente página/i })).toBeTruthy();
    });
    it('should change toPreviousPageAriaLabel appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], toPreviousPageAriaLabel: "Presione para regresar a la p\u00E1gina anterior" }));
        expect(react_1.screen.getByRole('button', { name: /Presione para regresar a la página anterior/i })).toBeTruthy();
    });
    it('should call onNextClick appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], onNextClick: spy }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to next page/i }));
        expect(spy).toHaveBeenCalled();
    }));
    it('should call onPreviousClick appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], onPreviousClick: spy }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to next page/i }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to previous page/i }));
        expect(spy).toHaveBeenCalled();
    }));
    it('should call onSetPage appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                { title: 'How to make an apple pie', link: '' },
                { title: 'How to make cookies', link: '' }
            ], onSetPage: spy }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to next page/i }));
        expect(spy).toHaveBeenCalledTimes(1);
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Go to previous page/i }));
        expect(spy).toHaveBeenCalledTimes(2);
    }));
    it('should handle showMore appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [
                {
                    title: 'Getting started with Red Hat OpenShift',
                    link: '#',
                    body: 'Red Hat OpenShift on IBM Cloud is a managed offering to create your own cluster of compute hosts where you can deploy and manage containerized apps on IBM Cloud ...',
                    hasShowMore: true
                },
                {
                    title: 'Azure Red Hat OpenShift documentation',
                    link: '#',
                    body: 'Microsoft Azure Red Hat OpenShift allows you to deploy a production ready Red Hat OpenShift cluster in Azure ...'
                },
                {
                    title: 'OKD Documentation: Home',
                    link: '#',
                    body: 'OKD is a distribution of Kubernetes optimized for continuous application development and multi-tenant deployment. OKD also serves as the upstream code base upon ...'
                }
            ] }));
        expect(react_1.screen.getByRole('region')).toHaveAttribute('class', 'pf-v6-c-expandable-section__content');
    }));
    it('should call onClick appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ title: 'How to make an apple pie', link: '', onClick: spy }] }));
        yield user_event_1.default.click(react_1.screen.getByRole('link', { name: /How to make an apple pie/i }));
        expect(spy).toHaveBeenCalled();
    }));
    it('should apply titleProps appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCardBase_1.default, { sources: [{ title: 'How to make an apple pie', link: '', titleProps: { className: 'test' } }] }));
        expect(react_1.screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test');
    });
});
