import { shallowMount } from '@vue/test-utils';
import settleAllPromises from '@/helpers/layout-helper.js';
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import tpaRecalModal from '@/layouts/provider-preference/tpa-recal-modal/tpa-recal-modal.vue';

// Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => jest.fn());

// Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({
    fetchCmsContentForPage: jest.fn(),
    setupModalLinks: jest.fn()
}));

/** @ignore */
function setupMocks() {
    const mountOptions = getMountOptions({
        router: {
            navigate: jest.fn()
        }
    });

    const wrapper = shallowMount(
        tpaRecalModal,
        mountOptions
    );

    const apiResponses = {};

    settleAllPromises.mockImplementation(() => apiResponses);
    fetchCmsContentForPage.mockImplementation(() => { });

    return { wrapper };
}

describe('tpa-Recal-Modal.vue', () => {
    test('should show error if not acknowledged', () => {
        const { wrapper } = setupMocks();
        wrapper.vm.acknowledged = false;
        wrapper.vm.tpaRecalAnswer = 'TPAOption';
        wrapper.vm.footerButtonClick();

        expect(wrapper.vm.showAcknowledgementError).toBeTruthy();
    });

    test('should not show error if acknowledged', () => {
        const { wrapper } = setupMocks();
        wrapper.vm.acknowledged = true;
        wrapper.vm.tpaRecalAnswer = 'TPAOption';
        wrapper.vm.footerButtonClick();

        expect(wrapper.vm.showAcknowledgementError).toBeFalsy();
    });
    test('should show error if no answer selected', () => {
        const { wrapper } = setupMocks();
        wrapper.vm.tpaRecalAnswer = '';
        wrapper.vm.tpaRecalAnswer = undefined;
        wrapper.vm.footerButtonClick();

        expect(wrapper.vm.showNoSelectionError).toBeTruthy();
    });
});
