From acc72416583578521dd33c42955dc1e829b3ba00 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Wed, 24 Apr 2024 09:02:49 -0400 Subject: [PATCH] add bailout to vehicle-damage + unit test --- .../vehicle-damage/vehicle-damage.spec.js | 37 +++++++++++++++++++ src/layouts/vehicle-damage/vehicle-damage.vue | 29 +++++++++------ src/layouts/vin-lookup/vin-lookup.vue | 1 - 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/layouts/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index f2f911f7..8d772176 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -6,6 +6,8 @@ import routerParams from '@/router/router-constants/router-params'; import { useMainStore } from '@/store'; import vehicleCategories from '@/constants/vehicle-categories'; import VehicleDamageComponent from '@/layouts/vehicle-damage/vehicle-damage.vue'; +import bailoutCode from '@/constants/bailoutCode'; +import issPageValues from '@/router/router-constants/issPage-values'; const mockRoute = { params: {} @@ -51,6 +53,7 @@ const mountOptions = { } } }; + beforeEach(() => { jest.clearAllMocks(); }); @@ -92,4 +95,38 @@ describe('vehicle-damage.vue', () => { expect(mockRouter.navigate) .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_REPAIR, mockRoute); }); + test('Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', async () => { + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: { + order: { + damage: { + isRepair: false + }, + vehicle: { + vin: 'MOCK VIN' + } + } + } + } + })]; + mountOptions.data = () => ({ + hasBailedOut: true + }); + + const wrapper = mount(VehicleDamageComponent, mountOptions); + const siteFooterWrapper = wrapper.getComponent({ ref: 'siteFooter' }); + const partsQuestionsErrorResponse = { + error: 'Error getting parts' + }; + useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => ( + partsQuestionsErrorResponse + )); + siteFooterWrapper.vm.$emit('forwardClicked'); + + await flushPromises(); + expect(mockRouter.navigate).toHaveBeenCalledTimes(1); + expect(mockRouter.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, mockRoute); + }); }); diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index e2e541ae..f42d4d76 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -121,6 +121,7 @@ import errorMessages from '@/constants/error-messages'; import damageLocationsCms from '@/constants/damage-locations-cms.js'; import damageLocationsSelected from '@/constants/damage-locations-selected.js'; import { useMainStore } from '@/store'; +import bailoutMessage from '@/constants/bailoutMessage'; // DEFINE VALIDATION RULES defineRule( @@ -295,6 +296,9 @@ export default { this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT ]; }, + hasBailedOut() { + return false; + } }, methods: { arePagePrerequisitesValid() { @@ -479,22 +483,25 @@ export default { } else if (this.mainStore.order.vehicle.vin) { // If vin already exists, navigate directly to vin-lookup - const partsOrQuestionsResponse = - await this.getPartsOrQuestions(); + const partsOrQuestionsResponse = await this.getPartsOrQuestions(); if (partsOrQuestionsResponse.error) { - // To Do: Need requirement on what to do here - window.console.error( - 'Error on retrieving PartsOrQuestions' - ); + this.mainStore.setBailout(bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data)); + window.console.error('Error on retrieving PartsOrQuestions'); this.$refs.siteFooter.removeLoader(); - return null; + this.hasBailedOut = true; + this.$router.navigate( + this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, + this.$route + ); } // Comes from vehicleQuestionsMixin.navigateForward() - await this.navigateForward( - partsOrQuestionsResponse.data.partsOrQuestions, - this - ); + if (!this.hasBailedOut) { + await this.navigateForward( + partsOrQuestionsResponse.data.partsOrQuestions, + this + ); + } } else { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 9bbf2c59..0b135e08 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -61,7 +61,6 @@ import vehicleBanner from '@/iss-components/vehicle-banner/vehicle-banner.vue'; import vinLocationInformation from '@/layouts/vin-lookup/vin-location-information/vin-location-information.vue'; import vinLookupAlerts from '@/layouts/vin-lookup/vin-lookup-alerts/vin-lookup-alerts.vue'; import vinQuestion from '@/layouts/vin-lookup/vin-question/vin-question.vue'; -import bailoutCode from '@/constants/bailoutCode'; import bailoutMessage from '@/constants/bailoutMessage'; export default {