import { shallowMount } from "@vue/test-utils";
import addressVehiclesQuestion from "@/layouts/address-vehicles/address-vehicles-question/address-vehicles-question";
import { ValueToLogTypes } from "@/constants/analytics";

describe("addressVehiclesQuestion.vue", () => {
    it("Should return content for differentVehicleAlertHeader", () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin],
        });

        // Assert
        expect(wrapper.vm.differentVehicleAlertHeader).toEqual("FoundWindshieldTestReturn");
    });

    it("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("FoundWindshieldTestReturn");
    });

    it("Should emit a modelValue change when setting selectedVehicleVin", async () => {
        // Arrange
        const wrapper = shallowMount(addressVehiclesQuestion, {
            mixins: [mockMixin],
            propsData: {
                vehicles: ["1", "2", "newValue"],
                modelValue: "2",
            },
        });

        // Act
        const localThis = { $emit: jest.fn() };
        addressVehiclesQuestion.computed.selectedVehicleVin.set.call(localThis, "newValue");

        // Assert
        expect(localThis.$emit).toBeCalledWith("update:modelValue", "newValue");
    });
});

const mockMixin = {
    methods: {
        getCmsContent: jest.fn((contentName) => {
            if (contentName === "FoundWindshield") {
                return "FoundWindshieldTestReturn";
            }
            return null;
        }),
        vehicles: jest.fn(() => {
            return [{ vehicle: "test" }];
        }),
    },
    computed: {
        ValueToLogTypes() {
            return ValueToLogTypes;
        },
    },
};
