Merge pull request #574 from Safelite/feature/digital/SSR-1135.5

Refactoring Supporting Items Code to Only Get When Needed
This commit is contained in:
michaela-brydon-safelite 2024-03-05 09:44:13 -05:00 committed by GitHub
commit bc7947187a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 37 additions and 169 deletions

View file

@ -369,7 +369,7 @@ export default {
},
async navigateForward() {
if (this.unverified || this.verifiedDeductible) {
this.mainStore.saveSupportingItems(this.supportingItems);
useMainStore().updateSupportingItems(this.supportingItems);
this.$router.navigate(
navigationScenarios.CLICKED_FORWARD,
this.$route,
@ -379,7 +379,7 @@ export default {
} else if (this.verifiedITAC || this.verifiedNoComp) {
useMainStore().updateIsSafeliteProvider(this.selectedProvider === 'Safelite');
if (this.selectedProvider === 'Safelite') {
this.mainStore.saveSupportingItems(this.supportingItems);
useMainStore().updateSupportingItems(this.supportingItems);
this.$router.navigate(
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
this.$route,

View file

@ -75,8 +75,6 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
}
});
// mountOptions.global.mocks["$store"] = store;
mountOptions.global.stubs = {
siteFooter: footerStub,
loadingModal: loadingModalStub
@ -337,81 +335,4 @@ describe('schedule-page.vue', () => {
// Assert
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
});
test('for mobile appts, updateSupportingItems should call store action to save supporting items', async () => {
// Arrange
const { wrapper } = getShallowMountedComponent();
wrapper.vm.mainStore.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
wrapper.vm.mobilePremiumAppointmentFee = 14.99;
wrapper.vm.selectedTimeSlotInfo.isPremiumAppointment = true;
wrapper.vm.mainStore.lineItems.supportingItems = [
{
partNumber: 'EARLY BIRD',
description: null,
partType: 'EARLY BIRD',
laborAmount: 0,
sellingPrice: 0,
kitPrice: 0
}
];
const store = useMainStore();
// Act
await wrapper.vm.updateSupportingItems();
// Assert
expect(store.saveSupportingItemsSuppressingStateResetting).toHaveBeenCalledTimes(1);
expect(wrapper.vm.mainStore.lineItems.supportingItems)
.toEqual(expect.arrayContaining([
expect.objectContaining({
partType: 'EARLY BIRD'
})
]));
});
test(
'for Inshop appts, updateSupportingItems should call store action to save supporting items WITHOUT the EARLY BIRD supporting item',
async () => {
// Arrange
const { wrapper } = getShallowMountedComponent();
wrapper.vm.mainStore.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
wrapper.vm.mobilePremiumAppointmentFee = 14.99;
wrapper.vm.selectedTimeSlotInfo.isPremiumAppointment = true;
wrapper.vm.mainStore.lineItems.supportingItems = [
{
partNumber: 'EARLY BIRD',
description: null,
partType: 'EARLY BIRD',
laborAmount: 0,
sellingPrice: 0,
kitPrice: 0
}
];
const store = useMainStore();
// Act
await wrapper.vm.updateSupportingItems();
// Assert
expect(store.saveSupportingItemsSuppressingStateResetting).toHaveBeenCalledTimes(1);
expect(wrapper.vm.mainStore.lineItems.supportingItems)
.not.toEqual(expect.arrayContaining([
expect.objectContaining({
partType: 'EARLY BIRD'
})
]));
}
);
test('if no EARLY BIRD supporting item, then updateSupportingItems should NOT call store action', async () => {
// Arrange
const { wrapper } = getShallowMountedComponent();
wrapper.vm.mainStore.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
wrapper.vm.mobilePremiumAppointmentFee = 14.99;
wrapper.vm.selectedTimeSlotInfo.isPremiumAppointment = false;
wrapper.vm.mainStore.lineItems.supportingItems = [];
const store = useMainStore();
// Act
await wrapper.vm.updateSupportingItems();
// Assert
expect(store.saveSupportingItemsSuppressingStateResetting).toHaveBeenCalledTimes(0);
});
});

View file

@ -291,6 +291,9 @@ export default {
}
return this.selectableDatesData.days?.find((selectableDate) => selectableDate.date === this.selectedDate);
},
supportingItems() {
return useMainStore().lineItems.supportingItems;
}
},
watch: {
@ -324,7 +327,7 @@ export default {
&& ((serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE
|| serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP)
|| serviceLocation.provider.providerNumber);
const supportingItems = useMainStore().lineItems.supportingItems !== null;
const supportingItems = this.supportingItems !== null;
const damageInfo =
useMainStore().order.damage.isRepair
|| (useMainStore().order.lineItems?.glassParts != null
@ -360,9 +363,8 @@ export default {
return this.mainStore.order.schedule.date;
},
getSelectedTimeSlotInfo() {
const supportingItems = this.getSupportingItems();
const isPremiumAppointment =
!!supportingItems.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE)
!!(this.supportingItems?.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE) ?? [])
.length > 0;
const selectedTimeSlotInfo = {
@ -372,9 +374,6 @@ export default {
return selectedTimeSlotInfo;
},
getSupportingItems() {
return this.mainStore.lineItems.supportingItems;
},
timeSlotModalClosed() {
// Clear the selectedDate if no timeSlot has been selected
if (this.selectedTimeSlotInfo.timeSlot.routeCode == null) {
@ -424,40 +423,7 @@ export default {
}
return `${hours}:${minutes} ${meridianNotation}`;
},
updateSupportingItems() {
const supportingItems = this.getSupportingItems();
// if we have a premium fee(early bird), then save/update supporting items
if (
this.appointmentType === AppointmentTypeStrings.MOBILE
&& this.selectedTimeSlotInfo?.isPremiumAppointment
) {
const premiumFeeIndex = supportingItems.findIndex((item) => item.partType === PREMIUM_FEE_PART_TYPE);
if (premiumFeeIndex >= 0) {
supportingItems[premiumFeeIndex].laborAmount =
this.mobilePremiumAppointmentFee.laborAmount;
supportingItems[premiumFeeIndex].sellingPrice =
this.mobilePremiumAppointmentFee.sellingPrice;
supportingItems[premiumFeeIndex].kitPrice =
this.mobilePremiumAppointmentFee.kitPrice;
} else {
supportingItems.push(this.mobilePremiumAppointmentFee);
}
this.mainStore.saveSupportingItemsSuppressingStateResetting(supportingItems);
} else {
// if it's not a mobile and/or premium early bird, then make sure we remove any that may have been added
const removePremiumFeeIndex = supportingItems.findIndex((item) => item.partType === PREMIUM_FEE_PART_TYPE);
if (removePremiumFeeIndex >= 0) {
supportingItems.splice(removePremiumFeeIndex, 1);
this.mainStore.saveSupportingItemsSuppressingStateResetting(supportingItems);
}
}
},
forwardButtonAction() {
this.updateSupportingItems();
this.mainStore.saveSchedule(this.selectedTimeSlotInfo.timeSlot);
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route);

View file

@ -124,7 +124,13 @@ export default {
let hasBailedOut = false;
const pricingResults = await store.getPriceOrderItems(availableLineItems)
.catch((err) => {
useMainStore().setBailout(to, bailoutMessage.pricingResponseError(availableLineItems.map((li) => li.partNumber), { code: err.code, message: err.message, data: err.data }));
useMainStore().setBailout(
to,
bailoutMessage.pricingResponseError(
availableLineItems.map((li) => li.partNumber),
{ code: err.code, message: err.message, data: err.data }
)
);
hasBailedOut = true;
next(`/?issPage=${issPageValues.BAILOUT_PAGE}`);
});
@ -179,15 +185,19 @@ export default {
this.selectedVaps = vapsItemsSelected;
},
forwardButtonAction() {
const parts = { glassParts: this.pricedGlassParts, supportingItems: this.supportingItems, vaps: this.selectedVaps };
const parts = {
glassParts: this.pricedGlassParts,
supportingItems: this.supportingItems,
vaps: this.selectedVaps
};
if (!allGlassPartsAndItemsHavePrices(parts)) {
window.console.error('One or more items have no price assigned!');
}
if (this.pricedGlassParts.length > 0) {
store.saveGlassParts(this.pricedGlassParts);
store.updateGlassParts(this.pricedGlassParts);
}
store.saveSupportingItems(this.supportingItems);
store.saveVaps(this.selectedVaps);
store.updateSupportingItems(this.supportingItems);
store.updateVaps(this.selectedVaps);
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route);
}

View file

@ -361,7 +361,7 @@ export default {
if (this.isWindshieldRepair) {
const supportingItems = await useMainStore().getSupportingItems();
this.mainStore.saveSupportingItems(supportingItems.data);
useMainStore().updateSupportingItems(supportingItems.data);
}
if (this.mainStore.damage.isRepair) {

View file

@ -947,10 +947,10 @@ export const useMainStore = defineStore({
},
async getSupportingItems() {
const glassPartsArray = this.order.lineItems.glassParts ?? [];
const { carId } = this.order.vehicle;
const { isRepair } = this.order.damage;
const { numberOfChips } = this.order.damage;
const { glassParts } = this.lineItems;
const { carId } = this.vehicle;
const { isRepair, numberOfChips } = this.damage;
const { parentAccountNumber } = this.issConfig;
return globalMethods
.callHttpClient({
@ -959,8 +959,8 @@ export const useMainStore = defineStore({
payload: {
carId,
damageType: isRepair ? 'Repair' : 'Replace',
parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER,
parts: glassPartsArray,
parentAccountNumber,
parts: glassParts ?? [],
numberOfRepairChips: isRepair ? numberOfChips : 0
}
});
@ -1472,8 +1472,8 @@ export const useMainStore = defineStore({
this.order.originalDeductible = vehicle.deductible;
this.order.currentDeductible = vehicle.deductible;
this.resetSupportingItemsState();
this.resetVapsState();
this.updateSupportingItems(null);
this.updateVaps(null);
},
updateVehicleVin(vin) {
@ -1496,6 +1496,7 @@ export const useMainStore = defineStore({
resetGlassPartsState() {
this.order.lineItems.glassParts = null;
this.order.lineItems.supportingItems = null;
this.order.damage.partQuestionAnswers = null;
this.order.damage.moldingQuestionAnswers = null;
this.order.damage.capabilityQuestionAnswers = null;
@ -1511,21 +1512,6 @@ export const useMainStore = defineStore({
this.order.schedule.routeCode = null;
this.order.schedule.jobMaxMinutes = null;
this.order.schedule.jobMinMinutes = null;
// premium appointment fee used on schedule page also needs reset when schedule is reset
const { supportingItems } = this.order.lineItems;
const premiumAppointmentFeeIndex = supportingItems?.findIndex((item) => item.partType === PREMIUM_FEE_PART_TYPE);
if (premiumAppointmentFeeIndex >= 0) {
supportingItems.splice(premiumAppointmentFeeIndex, 1);
state.order.lineItems.supportingItems = supportingItems;
}
},
resetSupportingItemsState() {
this.order.lineItems.supportingItems = null;
},
resetVapsState() {
this.order.lineItems.vaps = null;
},
resetDamageState() {
this.order.damage.isRepair = null;
@ -1685,8 +1671,8 @@ export const useMainStore = defineStore({
this.updateGlassParts(null);
this.updateMoldingQuestionAnswers(null);
this.updateCapabilityQuestionAnswers(null);
this.resetSupportingItemsState();
this.resetVapsState();
this.updateSupportingItems(null);
this.updateVaps(null);
this.updatePageData({ page: issPageValues.VEHICLE_PARTS, data: null });
this.updatePageData({ page: issPageValues.MOLDING_QUESTIONS, data: null });
@ -1730,18 +1716,6 @@ export const useMainStore = defineStore({
// Save new values
this.updateCapabilityQuestionAnswers(capabilityQuestionAnswersArray);
},
saveGlassParts(glassParts) {
this.order.lineItems.glassParts = glassParts;
},
saveSupportingItems(supportingItems) {
this.order.lineItems.supportingItems = supportingItems;
},
saveSupportingItemsSuppressingStateResetting(supportingItems) {
this.order.lineItems.supportingItems = supportingItems;
},
saveVaps(vaps) {
this.order.lineItems.vaps = vaps;
},
// Price order actions
async priceOrderItemsAndSaveServerData(availableLineItems, serviceZipCode, serviceZipCodeCtu) {
@ -2110,21 +2084,18 @@ export const useMainStore = defineStore({
resetRegistrationAndDependencies() {
this.resetRegistrationState();
this.resetGlassPartsState();
this.resetSupportingItemsState();
this.resetVapsState();
this.updateVaps(null);
},
resetDamageAndDependencies() {
this.resetDamageState();
this.resetGlassPartsState();
this.resetSupportingItemsState();
this.resetVapsState();
this.updateVaps(null);
},
resetPartsAndDependencies() {
this.resetGlassPartsState();
this.resetSupportingItemsState();
this.resetVapsState();
this.updateVaps(null);
this.resetServiceLocationAndDependencies();
},