import { shallowMount } from '@vue/test-utils';
import cancelClaimModal from '@/layouts/coverage-statement/cancel-claim-modal/cancel-claim-modal.vue';

const mockDataStrings = {
    cmsBodyText: 'Some Body Text from CMS',
    cmsBodyText2: 'Some Text for Button in Body from CMS',
    cmsFooterText: 'Some Footer Text from CMS',
    cmsHeaderText: 'Some Header Text from CMS'
};

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

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

function setupMocks() {
    const wrapper = shallowMount(cancelClaimModal, {
        mixins: [mockMixin],
        props: {
            cmsWidgetName: 'test'
        },
        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 body text from Widget CMS', () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        const modalHeader = wrapper.vm.modalBodyText;

        // Assert
        expect(modalHeader).toBe(mockDataStrings.cmsBodyText);
    });

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

        // Act
        const modalHeader = wrapper.vm.modalBodyText2;

        // Assert
        expect(modalHeader).toBe(mockDataStrings.cmsBodyText2);
    });

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

        // Act
        const modalHeader = wrapper.vm.modalFooterText;

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

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

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

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

describe('Emits', () => {
    test('Should emit cancel-claim-confirmation when method called', async () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        wrapper.vm.cancelClaimConfirmation();
        await wrapper.vm.$nextTick();

        // Assert
        expect(wrapper.emitted('cancel-claim-confirmation')).toBeTruthy();
        expect(wrapper.emitted('cancel-claim-confirmation').length).toBe(1);
    });

    test('Should emit return-to-claim when method called', async () => {
        // Arrange
        const { wrapper } = setupMocks();

        // Act
        wrapper.vm.returnToClaim();
        await wrapper.vm.$nextTick();

        // Assert
        expect(wrapper.emitted('return-to-claim')).toBeTruthy();
        expect(wrapper.emitted('return-to-claim').length).toBe(1);
    });
});
