From 24103335eec282fad8ded09087cf8502b0150ad6 Mon Sep 17 00:00:00 2001 From: Michaela Brydon Date: Mon, 4 Mar 2024 15:46:31 -0500 Subject: [PATCH] Fixing tests --- .../schedule-page/schedule-page.spec.js | 79 ------------------- src/layouts/schedule-page/schedule-page.vue | 7 +- 2 files changed, 4 insertions(+), 82 deletions(-) diff --git a/src/layouts/schedule-page/schedule-page.spec.js b/src/layouts/schedule-page/schedule-page.spec.js index bc0d80df..c025ece6 100644 --- a/src/layouts/schedule-page/schedule-page.spec.js +++ b/src/layouts/schedule-page/schedule-page.spec.js @@ -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); - }); }); diff --git a/src/layouts/schedule-page/schedule-page.vue b/src/layouts/schedule-page/schedule-page.vue index 13a8315e..4636b834 100644 --- a/src/layouts/schedule-page/schedule-page.vue +++ b/src/layouts/schedule-page/schedule-page.vue @@ -268,9 +268,7 @@ export default { return { mainStore }; }, data() { - const { supportingItems } = useMainStore().lineItems; return { - supportingItems, selectedDate: this.getSelectedDate(), selectedTimeSlotInfo: this.getSelectedTimeSlotInfo(), selectableDatesData: [], @@ -293,6 +291,9 @@ export default { } return this.selectableDatesData.days?.find((selectableDate) => selectableDate.date === this.selectedDate); + }, + supportingItems() { + return useMainStore().lineItems.supportingItems; } }, watch: { @@ -363,7 +364,7 @@ export default { }, getSelectedTimeSlotInfo() { const isPremiumAppointment = - !!this.supportingItems.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE) + !!(this.supportingItems?.filter((lineItem) => lineItem.partType === PREMIUM_FEE_PART_TYPE) ?? []) .length > 0; const selectedTimeSlotInfo = {