import { shallowMount } from '@vue/test-utils';
import oemEndorsementModal from '@/layouts/coverage-statement/oem-endorsement-modal/oem-endorsement-modal.vue';


const mockDataStrings = {
    cmsBodyText: `Some Body Text from CMS`,
    cmsHeaderText: 'Some Header Text from CMS',
    cmsFooterText: 'Some Footer Text from CMS'
};

const mockCmsContent = {
    BodyText: mockDataStrings.cmsBodyText,
    HeaderText: mockDataStrings.cmsHeaderText,
    FooterText: mockDataStrings.cmsFooterText
};

const mockMixin = {
    methods: {
        getCmsContent: jest.fn((_, cmsFieldName) => mockCmsContent[cmsFieldName])
    },
};

function setupMocks() {
    const wrapper = shallowMount(oemEndorsementModal, {
        mixins: [mockMixin],
        props: {
            cmsWidgetName: 'OEMEndorsementModal'
        },
        attachTo: document.body
    });

    return { wrapper };
}

test('returns the initial data', () => {
    // Arrange
    const { wrapper } = setupMocks();

    // Assert
    expect(wrapper.vm.$data).toMatchSnapshot();
});

describe('Computed', () => {
    test('Should get modal header text from Widget CMS', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        const result = wrapper.vm.modalHeaderText;

        // Assert
        expect(result).toBe(mockDataStrings.cmsHeaderText);
    });

    test('Should get modal close button text from Widget CMS', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        const result = wrapper.vm.modalCloseButtonText;

        // Assert
        expect(result).toBe(mockDataStrings.cmsFooterText);
    });

    test('Should call getCmsContent with the correct widget name and field name for body text', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        wrapper.vm.modalBodyText;

        // Assert
        expect(mockMixin.methods.getCmsContent).toHaveBeenCalledWith('OEMEndorsementModal', 'BodyText');
    });

    test('Should call getCmsContent with the correct widget name and field name for header text', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        wrapper.vm.modalHeaderText;

        // Assert
        expect(mockMixin.methods.getCmsContent).toHaveBeenCalledWith('OEMEndorsementModal', 'HeaderText');
    });

    test('Should call getCmsContent with the correct widget name and field name for footer text', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        wrapper.vm.modalCloseButtonText;

        // Assert
        expect(mockMixin.methods.getCmsContent).toHaveBeenCalledWith('OEMEndorsementModal', 'FooterText');
    });
});

describe('Props', () => {
    test('Should use the default cmsWidgetName prop value of OEMEndorsementModal', () => {
        // Arrange
        const wrapper = shallowMount(oemEndorsementModal, {
            mixins: [mockMixin],
            attachTo: document.body
        });

        // Assert
        expect(wrapper.vm.cmsWidgetName).toBe('OEMEndorsementModal');
    });

    test('Should accept a custom cmsWidgetName prop', () => {
        // Arrange
        const customWidgetName = 'CustomOEMModal';
        const wrapper = shallowMount(oemEndorsementModal, {
            mixins: [mockMixin],
            props: {
                cmsWidgetName: customWidgetName
            },
            attachTo: document.body
        });

        // Assert
        expect(wrapper.vm.cmsWidgetName).toBe(customWidgetName);
    });
});
