import { shallowMount } from '@vue/test-utils';
// eslint-disable-next-line max-len
import windshieldDamageTypeQuestion from '@/layouts/vehicle-damage/windshield-options/windshield-damage-type-question/windshield-damage-type-question.vue';
import { getMountOptions } from '@/helpers/unit-test-helper.js';

/** @ignore */
function setupMocks({
    modelValueProp = '',
    groupName = 'WindshieldDamageTypeQuestion',
    cmsQuestionText = "What's your windshield damage?",
    cmsAnswers = [{ Name: 'Repair' }, { Name: 'Replace' }],
    dataFromStoreApi = []
}) {
    const mountOptions = getMountOptions({
    });

    // Mock props
    mountOptions.propsData = {
        modelValue: modelValueProp
    };
    const mockMixin = {
        methods: {
            getCmsContent: jest.fn()
        }
    };
    mountOptions.mixins = [mockMixin];

    const wrapper = shallowMount(windshieldDamageTypeQuestion, mountOptions);

    // Mock CMS content
    const cmsContent = {
        groupName,
        QuestionText: cmsQuestionText,
        Answers: cmsAnswers
    };
    const damageOptions = dataFromStoreApi;
    return { wrapper, cmsContent, damageOptions };
}

describe('windshield-damage-type-question.vue', () => {
    test('Selected windshield damage is emitted upon selection.', async () => {
        // Arrange
        const { wrapper } = setupMocks({ modelValueProp: 'Repair' });

        // Act
        wrapper.setValue({ modelValue: 'Replace' });
        await wrapper.vm.$nextTick();

        // Assert
        expect(wrapper.vm.selectedValues).toEqual('Repair');
        expect(wrapper.emitted()['update:modelValue'][0]).toEqual([{ modelValue: 'Replace' }]);
    });
});
