import { shallowMount } from "@vue/test-utils";
import windshieldDamageTypeQuestion from "@/layouts/vehicle-damage/windshield-options/windshield-damage-type-question/windshield-damage-type-question";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import store from "@/store";

jest.mock(
    "@/store",
    () => {
        return {};
    },
    { virtual: true }
);

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" }]);
    });
});

function setupMocks({
    modelValueProp = "",
    groupName = "WindshieldDamageTypeQuestion",
    cmsQuestionText = "What's your windshield damage?",
    cmsAnswers = [{ Name: "Repair" }, { Name: "Replace" }],
    dataFromStoreApi = [],
}) {
    //Mock store
    store.dispatch = jest.fn(() => dataFromStoreApi);
    store.getters = {
        vehicle: { year: 2019, make: "honda", model: "civc", style: "2 Door", category: "CAR" },
    };
    const mountOptions = getMountOptions({
        store: {
            dispatch: store.dispatch,
            getters: store.getters,
        },
    });

    //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: groupName,
        QuestionText: cmsQuestionText,
        Answers: cmsAnswers,
    };
    const damageOptions = dataFromStoreApi;
    return { wrapper, cmsContent, damageOptions };
}
