add bailout to vehicle-damage + unit test
This commit is contained in:
parent
ee08bed3ea
commit
acc7241658
3 changed files with 55 additions and 12 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue