import { shallowMount } from "@vue/test-utils"; import vinLookup from "./vin-lookup.vue"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import store from "@/store"; jest.mock("@/store", () => ({ commit: jest.fn(), dispatch: jest.fn(), getters: { vehicle: { year: 2019, carId: 'initial carId' }, order: { serviceLocation: { zipCode: "45253" }, customer: { emailAddress: "builddigitaltest@safelite.com" } }, payment: { insuranceCoverage: { isVerified: true } }, damage: { glassToReplace: "windshield" } }, })); import { getDamageString, getIsWindshieldOnly,isGlassAvailableForCarId } from "@/helpers/damage-helper"; jest.mock("@/helpers/damage-helper", () => ({ isGlassAvailableForCarId: jest.fn(() => { return Promise.resolve(); }), getIsWindshieldOnly: jest.fn(), getDamageString: jest.fn(), })); describe("vin-lookup.vue", () => { it("Should update the funnel-footer forward button when VIN is changed", (done) => { //Arrange const { wrapper } = setupMocks({ }); wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); //Act wrapper.setData({vin: "newValue"}); //Assert wrapper.vm.$nextTick(() => { expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toBeCalled(); done(); }); }); it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => { // Arrange const { wrapper } = setupMocks({ }); const zipValidationApiResponse = { data: { isServiceable: true } }; const vehicleLookupApiResponse = { data: { carId: 'initial carId' } }; const zipPromise = Promise.resolve(zipValidationApiResponse); const vinPromise = Promise.resolve(vehicleLookupApiResponse); wrapper.vm.validateZip = jest.fn().mockImplementation(() => zipPromise); wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise); wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); wrapper.vm.navigateForward = jest.fn(); // Act await wrapper.vm.forwardButtonAction(); //Assert expect(wrapper.vm.navigateForward).toHaveBeenCalled(); }); }); function setupMocks({ customMountOptions }) { const mountOptions = getMountOptions({}); const finalMountOptions = Object.assign(mountOptions, customMountOptions); // Modify/augment default mount options finalMountOptions.global.mocks["$store"] = store; finalMountOptions.global.mixins = [mockMixin]; finalMountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods const wrapper = shallowMount(vinLookup, finalMountOptions); return { wrapper }; } const mockMixin = { methods: { getCmsContent: jest.fn(() => "placeholder CMS content"), } }