diff --git a/src/layouts/schedule-page/schedule-page.spec.js b/src/layouts/schedule-page/schedule-page.spec.js index 411f7e4f..00829a6a 100644 --- a/src/layouts/schedule-page/schedule-page.spec.js +++ b/src/layouts/schedule-page/schedule-page.spec.js @@ -13,6 +13,7 @@ jest.mock('@/helpers/cms-content-helper', () => ({ })); const RECAL_ACK_MODAL_REF_NAME = 'recalAckModal'; +const BENEFIT_RECAL_MODAL_REF_NAME = 'benefitRecalModal'; const mockMixin = { methods: { @@ -74,6 +75,18 @@ const recalAckModalStub = { } }; +const benefitRecalModalStub = { + template: '
', + methods: { + openModal: jest.fn(), + footerButtonClick: jest.fn() + } +}; + +const mockBenefitRecalModalContent = { + HeaderText: 'Benefit Recalibration Modal Header' +} + function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) { const mountOptions = getMountOptions({ router: { @@ -85,7 +98,8 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) { siteFooter: footerStub, loadingModal: loadingModalStub, serviceLocation: serviceLocationStub, - recalAckModal: recalAckModalStub + recalAckModal: recalAckModalStub, + benefitRecalModal: benefitRecalModalStub }; methodToRun(); @@ -106,6 +120,16 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) { writable: false, configurable: true }); + + // Manually create the ref for benefitRecalModal since shallowMount doesn't populate it + Object.defineProperty(wrapper.vm.$refs, BENEFIT_RECAL_MODAL_REF_NAME, { + value: { + openModal: jest.fn(), + footerButtonClick: jest.fn() + }, + writable: false, + configurable: true + }); // Manually create the ref for serviceLocation since shallowMount doesn't populate it Object.defineProperty(wrapper.vm.$refs, 'serviceLocation', { @@ -158,6 +182,9 @@ beforeEach(() => { lineItems: { glassParts: [], supportingItems: [] + }, + issConfig: { + clientName: 'TestClient' } } } @@ -390,4 +417,88 @@ describe('schedule page methods...', () => { // Assert expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); }); -}); + test('backButtonAction opens benefitRecalModal when hasBenefitRecalModal returns true and benefitRecalModalAcknowledged is false', () => { + // Arrange + const { wrapper } = getShallowMountedComponent(); + wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header'); + wrapper.vm.benefitRecalModalAcknowledged = false; + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.$refs[BENEFIT_RECAL_MODAL_REF_NAME].openModal).toHaveBeenCalled(); + }); + test('backButtonAction pushes non-recalibration_version event when opening benefitRecalModal and hasRecalibrationPart is false', () => { + // Arrange + const { wrapper } = getShallowMountedComponent(); + wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header'); + wrapper.vm.benefitRecalModalAcknowledged = false; + wrapper.vm.mainStore.lineItems.glassParts = [ + { + partNumber: 'TEST123', + requiresRecalibration: false + } + ]; + wrapper.vm.pushEventToGA = jest.fn(); + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.pushEventToGA).toHaveBeenCalledWith( + 'safelite_benefit_modal_displayed', + wrapper.vm.mainStore.accountNameForEvents, + 'non-recalibration_version', + true + ); + }); + test('backButtonAction pushes recalibration_version event when opening benefitRecalModal and hasRecalibrationPart is true', () => { + // Arrange + const { wrapper } = getShallowMountedComponent(); + wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header'); + wrapper.vm.benefitRecalModalAcknowledged = false; + wrapper.vm.mainStore.lineItems.glassParts = [ + { + partNumber: 'TEST123', + requiresRecalibration: true + } + ]; + wrapper.vm.pushEventToGA = jest.fn(); + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.pushEventToGA).toHaveBeenCalledWith( + 'safelite_benefit_modal_displayed', + wrapper.vm.mainStore.accountNameForEvents, + 'recalibration_version', + true + ); + }); + test('backButtonAction navigates back when hasBenefitRecalModal is true and benefitRecalModalAcknowledged is true', () => { + // Arrange + const { wrapper } = getShallowMountedComponent(); + wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header'); + wrapper.vm.benefitRecalModalAcknowledged = true; + wrapper.vm.navigateBack = jest.fn(); + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.navigateBack).toHaveBeenCalled(); + }); + test('backButtonAction navigates back when hasBenefitRecalModal is false', () => { + // Arrange + const { wrapper } = getShallowMountedComponent(); + wrapper.vm.navigateBack = jest.fn(); + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.navigateBack).toHaveBeenCalled(); + }); +}); \ No newline at end of file