import addressVehiclesQuestion from '@/layouts/address-vehicles/address-vehicles-question/address-vehicles-question.vue';
import { shallowMount } from '@vue/test-utils';
import { getMountOptions } from '@/helpers/unit-test-helper.js';

/** @ignore */
function setupMocks({
    modelValueProp = 'TESTCAR',
    cmsQuestionText = 'CMS text goes here'
}) {
    const mountOptions = getMountOptions();

    // Mock props
    mountOptions.propsData = {
        modelValue: modelValueProp
    };

    const wrapper = shallowMount(addressVehiclesQuestion, mountOptions);

    // Mock CMS content
    const cmsContent = {
        QuestionText: cmsQuestionText
    };
    return { wrapper, cmsContent };
}

const mockMixin = {
    methods: {
        getCmsContent: jest.fn((contentName) => {
            if (contentName === 'AlertMatchedDifferentVehicleWidget') {
                return 'AlertMatchedDifferentVehicleWidgetTestReturn';
            }
            if (contentName === 'AlertMatchedTwoIdenticalYMMVehicleWidget') {
                return 'AlertMatchedTwoIdenticalYMMVehicleWidgetTestReturn';
            }
            return null;
        }),
        vehicles: jest.fn(() => [{ vehicle: 'test' }])
    }
};

describe('address-vehicles-question.vue', () => {
    test('Selected vehicle is emitted upon selection', async () => {
        // Arrange
        const { wrapper } = setupMocks({ modelValueProp: '2020 Audi A6' });
        const vehicleToSelect = '2016 Jaguar F-Type';

        // Act
        wrapper.setValue({ selectedVehicle: vehicleToSelect });
        await wrapper.vm.$nextTick();

        // Assert
        expect(wrapper.emitted()['update:modelValue'][0]).toEqual([
            { selectedVehicle: '2016 Jaguar F-Type' }
        ]);
    });
    test('Should return content for differentVehicleAlertHeader', () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin]
        });

        // Assert
        expect(wrapper.vm.differentVehicleAlertHeader).toEqual('AlertMatchedDifferentVehicleWidgetTestReturn');
    });
    test('Should return content for differentVehicleAlertBody', () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin],
            propsData: {
                vehicles: ['1', '2'],
                modelValue: ['1', '2']
            }
        });

        // Assert
        expect(wrapper.vm.differentVehicleAlertBody).toEqual('AlertMatchedDifferentVehicleWidgetTestReturn');
    });
    test('Should return content for AlertMatchedTwoIdenticalYMMVehicleHeader', () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin]
        });

        // Assert
        expect(wrapper.vm.AlertMatchedTwoIdenticalYMMVehicleHeader).toEqual('AlertMatchedTwoIdenticalYMMVehicleWidgetTestReturn');
    });
    test('Should return content for AlertMatchedTwoIdenticalYMMVehicleBody', () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin],
            propsData: {
                vehicles: ['1', '2'],
                modelValue: ['1', '2']
            }
        });

        // Assert
        expect(wrapper.vm.AlertMatchedTwoIdenticalYMMVehicleBody).toEqual('AlertMatchedTwoIdenticalYMMVehicleWidgetTestReturn');
    });
});
