From 0ae55bf21af88ebbdb54586b8dd0cbb6ad0263ab Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 15 Jun 2022 14:28:54 -0400 Subject: [PATCH] Updated unit tests --- jest.config.js | 4 +-- src/layouts/vin-lookup/vin-lookup.spec.js | 40 +++++++++++++++++++++-- src/layouts/vin-lookup/vin-lookup.vue | 5 ++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/jest.config.js b/jest.config.js index a511fdc02..6662c43cf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,14 +6,14 @@ module.exports = { transform: { "^.+\\.vue$": "vue-jest" }, moduleFileExtensions: ["js", "vue"], collectCoverageFrom: [ - "src/**/*.{js,vue}", + //"src/**/*.{js,vue}", "!src/main.js", "!src/constants/*.js", "!src/router/**/*.js", "!src/helpers/unit-test-helper.js", "!src/layouts/component-test/component-test.vue", "!src/layouts/form-test/form-test.vue", - "!src/layouts/vin-lookup/vin-lookup.vue", + "src/layouts/vin-lookup/vin-lookup.vue", "!src/layouts/vehicle-damage/windshield-damage-type-question/windshield-damage-type-question.vue", "!src/layouts/vehicle-damage/windshield-options/windshield-options.vue", "!src/layouts/part-questions/**/*.vue", diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 1c580f4a6..e782f345e 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -69,9 +69,38 @@ describe("vin-lookup.vue", () => { expect(wrapper.vm.navigateForward).toHaveBeenCalled(); }); + it("Should do a VIN lookup if the user has clicked on the VIN field and entered a new VIN or changed a previously matched VIN.", async () => { + // Arrange + const { wrapper } = setupMocks({}); + wrapper.vm.vinTouched = true; + wrapper.vm.vin = "foo"; + wrapper.vm.initialVin = "!foo"; + + wrapper.vm.navigateForward = jest.fn(); + const vehicleLookupApiResponse = { + data: { + carId: 'new carId' // does not match the store value + } + }; + const vinPromise = Promise.resolve(vehicleLookupApiResponse); + + wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise); + + // Act + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.lookupVehicle).toHaveBeenCalled(); + }); + it("Should not call navigateForward() if the store carId does not match the vin response carId and forward button is clicked", async () => { // Arrange const { wrapper } = setupMocks({}); + // New lookup + wrapper.vm.vinTouched = true; + wrapper.vm.vin = ""; + wrapper.vm.initialVin = "foo"; + const vehicleLookupApiResponse = { data: { carId: 'new carId' // does not match the store value @@ -138,14 +167,21 @@ describe("vin-lookup.vue", () => { it("Should not call navigateForward() when forward button is clicked but lookupVehicle errors out.", async () => { // Arrange const { wrapper } = setupMocks({}); + wrapper.vm.vinTouched = true; + wrapper.vm.vin = "foo"; + wrapper.vm.initialVin = "!foo"; + const vehicleLookupApiResponse = { - data: { + status: { carId: 'new carId' // does not match the store value } }; const vinPromise = Promise.reject(vehicleLookupApiResponse); - wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise); + const response = { + status: 404 + }; + wrapper.vm.lookupVehicle = jest.fn().mockImplementation((response) => vinPromise); wrapper.vm.navigateForward = jest.fn(); wrapper.vm.previouslyEnteredCarId = 'new carId'; diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 851b5e012..699856b79 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -320,11 +320,10 @@ export default { return; } - // If the vin has been touched and we've gotten this far it means they've entered vin or it's already been entered. + // If the user has clicked on the VIN field, either they are doing a new VIN lookup or changing the VIN previously matched. + // Therefore we need to do a VIN Lookup let vehicleLookupResponse; if (this.vinTouched && this.vin != this.initialVin) { - console.log(this.vin); - const vinToLookup = this.vinTouched ? this.vin : this.initialVin; const vehicleLookup = this.lookupVehicle(vinToLookup); vehicleLookupResponse = await vehicleLookup.catch((response) => {