commit
4a35d907f3
3 changed files with 92 additions and 11 deletions
|
|
@ -291,17 +291,9 @@ export default {
|
|||
},
|
||||
|
||||
async forwardButtonAction() {
|
||||
await this.dispatchStoreAction(
|
||||
this.storeActions.SAVE_VEHICLE_DAMAGE,
|
||||
{
|
||||
isWindshieldRepair: this.isWindshieldRepair,
|
||||
selectedGlassToReplace: this.selectedGlassToReplace(),
|
||||
selectedWindshieldChipCount:
|
||||
this.selectedWindshieldOptions.selectedWindshieldChipCount,
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
await this.mainStore.saveVehicleDamage(this.isWindshieldRepair,
|
||||
this.selectedGlassToReplace(),
|
||||
this.selectedWindshieldOptions.selectedWindshieldChipCount);
|
||||
return this.navigateForward();
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { endpoints } from "@/constants/endpoints.js";
|
|||
import { getDateForSavedSessionTimeout } from "@/helpers/session-helper";
|
||||
import globalMethods from "@/global-methods";
|
||||
import { applicationConfig } from "@/constants/application-config";
|
||||
import { issPageValues } from "@/router/router-constants/issPage-values";
|
||||
|
||||
const storeId = 'main';
|
||||
|
||||
|
|
@ -38,6 +39,9 @@ const getDefaultState = () => {
|
|||
moldingQuestionAnswers: null,
|
||||
capabilityQuestionAnswers: null,
|
||||
},
|
||||
lineItems: {
|
||||
glassParts: null,
|
||||
},
|
||||
referralNumber: null,
|
||||
referralDate: null,
|
||||
accountNumber: 0,
|
||||
|
|
@ -220,6 +224,40 @@ export const useMainStore = defineStore({
|
|||
});
|
||||
},
|
||||
|
||||
saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) {
|
||||
const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort();
|
||||
const isGlassToReplaceTheSame =
|
||||
this.order.damage.glassToReplace?.length === selectedGlassToReplace.length &&
|
||||
this.order.damage.glassToReplace
|
||||
.slice()
|
||||
.sort()
|
||||
.every(
|
||||
(obj, index) =>
|
||||
obj.glassLocation === selectedGlassPassedInSorted[index].glassLocation &&
|
||||
obj.glassName === selectedGlassPassedInSorted[index].glassName
|
||||
);
|
||||
const isWindshieldRepairTheSame =
|
||||
isWindshieldRepair === this.order.damage.isRepair;
|
||||
|
||||
const isChipCountTheSame =
|
||||
selectedWindshieldChipCount === this.order.damage.numberOfChips;
|
||||
|
||||
const isDamageChanging =
|
||||
!isGlassToReplaceTheSame ||
|
||||
!isWindshieldRepairTheSame ||
|
||||
(isWindshieldRepair && !isChipCountTheSame);
|
||||
|
||||
if (isDamageChanging) {
|
||||
//Reset dependent state when changing
|
||||
this.resetGlassPartsState();
|
||||
|
||||
// Save new values
|
||||
this.updateIsRepair(isWindshieldRepair);
|
||||
this.updateNumberOfChips(isWindshieldRepair ? parseInt(selectedWindshieldChipCount) : null);
|
||||
this.updateGlassToReplace(selectedGlassToReplace);
|
||||
}
|
||||
},
|
||||
|
||||
updateVehicle(vehicle) {
|
||||
this.order.vehicle.carId = vehicle.carId;
|
||||
this.order.vehicle.category = vehicle.category;
|
||||
|
|
@ -242,10 +280,28 @@ export const useMainStore = defineStore({
|
|||
this.order.vehicle.imageColor = null;
|
||||
},
|
||||
|
||||
resetGlassPartsState() {
|
||||
this.order.lineItems.glassParts = null;
|
||||
this.order.damage.partQuestionAnswers = null;
|
||||
this.order.damage.moldingQuestionAnswers = null;
|
||||
this.order.damage.capabilityQuestionAnswers = null;
|
||||
this.applicationUser.pageData[issPageValues.PART_QUESTIONS] = null;
|
||||
this.applicationUser.pageData[issPageValues.VEHICLE_PARTS] = null;
|
||||
this.applicationUser.pageData[issPageValues.MOLDING_QUESTIONS] = null;
|
||||
this.applicationUser.pageData[issPageValues.CAPABILITY_QUESTIONS] = null;
|
||||
},
|
||||
|
||||
resetDamageState() {
|
||||
this.order.damage.isRepair = null;
|
||||
this.order.damage.numberOfChips = null;
|
||||
this.order.damage.glassToReplace = null;
|
||||
},
|
||||
|
||||
updateVehicleYear(year) {
|
||||
if(this.order.vehicle.year != year)
|
||||
{
|
||||
this.resetVehicleState();
|
||||
this.resetDamageState();
|
||||
this.order.vehicle.year = year;
|
||||
}
|
||||
},
|
||||
|
|
@ -256,6 +312,7 @@ export const useMainStore = defineStore({
|
|||
const year = this.order.vehicle.year;
|
||||
|
||||
this.resetVehicleState();
|
||||
this.resetDamageState();
|
||||
|
||||
this.order.vehicle.year = year;
|
||||
this.order.vehicle.make = make;
|
||||
|
|
@ -269,12 +326,14 @@ export const useMainStore = defineStore({
|
|||
const make = this.order.vehicle.make;
|
||||
|
||||
this.resetVehicleState();
|
||||
this.resetDamageState();
|
||||
|
||||
this.order.vehicle.year = year;
|
||||
this.order.vehicle.make = make;
|
||||
this.order.vehicle.model = model;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
updateVehicleStyle(style) {
|
||||
if(this.order.vehicle.style != style)
|
||||
|
|
@ -284,6 +343,7 @@ export const useMainStore = defineStore({
|
|||
const model = this.order.vehicle.model;
|
||||
|
||||
this.resetVehicleState();
|
||||
this.resetDamageState();
|
||||
|
||||
this.order.vehicle.year = year;
|
||||
this.order.vehicle.make = make;
|
||||
|
|
@ -291,6 +351,18 @@ export const useMainStore = defineStore({
|
|||
this.order.vehicle.style = style;
|
||||
}
|
||||
},
|
||||
|
||||
updateIsRepair(isRepair) {
|
||||
this.order.damage.isRepair = isRepair;
|
||||
},
|
||||
|
||||
updateNumberOfChips(numberOfChips) {
|
||||
this.order.damage.numberOfChips = numberOfChips;
|
||||
},
|
||||
|
||||
updateGlassToReplace(glassToReplace) {
|
||||
this.order.damage.glassToReplace = glassToReplace;
|
||||
},
|
||||
|
||||
addEventToBus (event) {
|
||||
this.applicationUser.eventBus.push(event);
|
||||
|
|
|
|||
|
|
@ -140,4 +140,21 @@ describe("Store", () => {
|
|||
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("saveVehicleDamage, should update damage", () => {
|
||||
// Arrange
|
||||
store.order.damage = {
|
||||
glassToReplace: [{ glassName: "Single", glassLocation: "Windshield" }],
|
||||
};
|
||||
|
||||
// Act
|
||||
store.saveVehicleDamage( false,
|
||||
[{ glassName: "Rear", glassLocation: "quarter" }],
|
||||
0);
|
||||
|
||||
// Assert
|
||||
expect(store.order.damage.glassToReplace).toEqual([{ glassName: "Rear", glassLocation: "quarter" }]);
|
||||
expect(store.order.damage.isRepair).toEqual(false);
|
||||
expect(store.order.damage.numberOfChips).toEqual(null);
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue