From 406dc075db1264943c90cbc45df28896df15aac2 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Wed, 8 Jun 2022 10:48:50 -0400 Subject: [PATCH] vin-lookup-tests | Created base setupmock and added two tests Also added a 'lite' mode for running tests --- package.json | 1 + src/layouts/vin-lookup/vin-lookup.spec.js | 113 +++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ec3d65d79..304fc2afd 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "serve": "vue-cli-service serve", "build": "vue-cli-service build", "test:unit": "vue-cli-service test:unit --coverage --ci", + "test:unit:lite": "vue-cli-service test:unit --ci", "lint": "vue-cli-service lint" }, "dependencies": { diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 3d0843e10..ce2ac71af 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -1 +1,112 @@ -test.todo("some test to be written in the future"); +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"), + } + } \ No newline at end of file