diff --git a/src/constants/query-strings.js b/src/constants/query-strings.js index 9b486517..576d1e5b 100644 --- a/src/constants/query-strings.js +++ b/src/constants/query-strings.js @@ -1,5 +1,21 @@ const queryStrings = Object.freeze({ - ISS_PAGE: 'issPage' + ISS_PAGE: 'issPage', + AUTH_CODE: 'auth_code', + BILL_TO_FIRST_NAME: 'billto_firstname', + BILL_TO_LAST_NAME: 'billto_lastname', + BILL_TO_POSTAL_CODE: 'billto_postalcode', + CARD_EXPIRATION_MONTH: 'card_expirationmonth', + CARD_EXPIRATION_YEAR: 'card_expirationyear', + CARD_TYPE: 'sgcardtype', + DISPLAY_PAY_IN_ADVANCE_ALERT: 'displayPayInAdvanceAlert', + ERROR: 'error', + LAST_FOUR: 'last_four', + REFERENCE_NUMBER: 'req_reference_number', + REFERRAL_SEQ_NUM: 'referralseqnum', + SUBSCRIPTIONID: 'subscriptionid', + TRANS_REFERENCE_NUMBER: 'auth_trans_ref_no', + TRANSACTION_ID: 'transaction_id' + }); export default queryStrings; diff --git a/src/constants/web-storage-constants.js b/src/constants/web-storage-constants.js new file mode 100644 index 00000000..29c814cf --- /dev/null +++ b/src/constants/web-storage-constants.js @@ -0,0 +1,5 @@ +const webStorageConstants = Object.freeze({ + SUBMITTED_ORDER: 'submittedOrder' +}); + +export default webStorageConstants; diff --git a/src/helpers/order-helper.js b/src/helpers/order-helper.js index 85d0bec2..33e7d3c4 100644 --- a/src/helpers/order-helper.js +++ b/src/helpers/order-helper.js @@ -1,6 +1,17 @@ import { useMainStore } from '@/store'; import { updateOrCreateISSCookie } from '@/helpers/cookie-helper'; +/* + Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing +*/ +async function saveSessionHelper(store) { + const savedSessionInfo = await store.saveSession(); + if (savedSessionInfo) { + store.setSaveSessionInfo(savedSessionInfo.data); + } + updateOrCreateISSCookie(); +} + /* Will call API to save existing order, or create new one depending where it's called from. This will also set Referral information in the store after saving, and then @@ -8,8 +19,8 @@ import { updateOrCreateISSCookie } from '@/helpers/cookie-helper'; */ export async function saveSession({ shouldAwaitSaveSessionQueue = false }) { const store = useMainStore(); - var saveSessionPromise = store.applicationUser.saveSessionPromise - ? store.applicationUser.saveSessionPromise.then(() => { return saveSessionHelper(store); }) + const saveSessionPromise = store.applicationUser.saveSessionPromise + ? store.applicationUser.saveSessionPromise.then(() => saveSessionHelper(store)) : saveSessionHelper(store); store.setSaveSessionPromise(saveSessionPromise); @@ -20,12 +31,18 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false }) { } /* - Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing + Will determine if to submitWorkOrder. + TODO: Add more description to this */ -async function saveSessionHelper(store) { - const savedSessionInfo = await store.saveSession(); - if (savedSessionInfo) { - store.setSaveSessionInfo(savedSessionInfo.data); - } - updateOrCreateISSCookie(); -} \ No newline at end of file +export async function submitWorkOrder({ + pageNameToLog, + submitAfterSave = false, + createDeleteStatusWorkOrderForPia = false +}) { + await saveSession({ + pageNameToLog, + shouldAwaitSaveSessionQueue: true, + submitAfterSave, + createDeleteStatusWorkOrderForPia + }); +} diff --git a/src/helpers/price-calculator.js b/src/helpers/price-calculator.js new file mode 100644 index 00000000..b44abc5a --- /dev/null +++ b/src/helpers/price-calculator.js @@ -0,0 +1,12 @@ +function getPriceOfLineItem(lineItem) { + return (lineItem?.kitPrice ?? 0) + + (lineItem?.laborAmount ?? 0) + + (lineItem?.sellingPrice ?? 0); +} + +export default function getPriceOfLineItems(lineItems) { + return lineItems.reduce( + (accumulator, lineItem) => accumulator + getPriceOfLineItem(lineItem), + 0 + ); +} diff --git a/src/helpers/price-calculator.spec.js b/src/helpers/price-calculator.spec.js new file mode 100644 index 00000000..4d09128b --- /dev/null +++ b/src/helpers/price-calculator.spec.js @@ -0,0 +1,56 @@ +import getPriceOfLineItems from "@/helpers/price-calculator.js"; + +describe('getPriceOfLineItems', () => { + test('Returns zero when no line items', () => { + // Arrange + const lineItems = []; + + // Act + const result = getPriceOfLineItems(lineItems); + + // Assert + expect(result).toBe(0); + }); + test('Returns expected when one line item', () => { + // Arrange + const lineItems = [ + { + kitPrice: 1, + laborAmount: 2, + sellingPrice: 3 + } + ]; + const expected = 6; + + // Act + const result = getPriceOfLineItems(lineItems); + + // Assert + expect(result).toBe(expected); + }); + test('Returns expected when multiple line items', () => { + // Arrange + const lineItems = [ + { + kitPrice: 1, + laborAmount: 2, + sellingPrice: 3 + }, + { + kitPrice: 1 + }, + { + kitPrice: 10, + laborAmount: 100, + sellingPrice: 1000 + } + ]; + const expected = 1117; + + // Act + const result = getPriceOfLineItems(lineItems); + + // Assert + expect(result).toBe(expected); + }); +}); diff --git a/src/helpers/querystring-helper.js b/src/helpers/querystring-helper.js new file mode 100644 index 00000000..f4df1ed7 --- /dev/null +++ b/src/helpers/querystring-helper.js @@ -0,0 +1,11 @@ +export default function getQueryStringParameter(key) { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const lowerCaseParams = new URLSearchParams(); + + urlParams.forEach((value, name) => { + lowerCaseParams.append(name.toLowerCase(), value); + }); + + return lowerCaseParams.get(key.toLowerCase()); +} diff --git a/src/layouts/coverage-statement/__snapshots__/coverage-statement.spec.js.snap b/src/layouts/coverage-statement/__snapshots__/coverage-statement.spec.js.snap new file mode 100644 index 00000000..aca040ba --- /dev/null +++ b/src/layouts/coverage-statement/__snapshots__/coverage-statement.spec.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`coverageStatement.vue-working returns the initial data 1`] = ` +Object { + "baseServiceLineItems": Array [], + "currencyFormatter": NumberFormat {}, + "deductibleText": "Your deductible is", + "isNoComp": false, + "isRepair": true, + "loadingText": Array [ + "Connecting to your insurance company", + "Nearly there", + "Finishing up", + ], + "policyLookupSuccessful": true, + "rules": Object { + "selectionRequired": "option-required", + }, + "selectedProvider": "", + "supportingItems": null, + "widget": Object { + "explanatoryText": "ExplanatoryTextWidget", + "nextStep": "NextStepsWidget", + "serviceProviderQuestion": "ServiceProviderQuestion", + "subheader": "SiteSubHeaderWidget", + "verifiedItacAlert": "VerifiedITACAlert", + }, +} +`; diff --git a/src/layouts/coverage-statement/coverage-statement.spec.js b/src/layouts/coverage-statement/coverage-statement.spec.js index a597b7f9..65cfd347 100644 --- a/src/layouts/coverage-statement/coverage-statement.spec.js +++ b/src/layouts/coverage-statement/coverage-statement.spec.js @@ -3,17 +3,18 @@ import coverageStatement from '@/layouts/coverage-statement/coverage-statement.v // Supporting Files import { nextTick } from 'vue'; -import { mount } from '@vue/test-utils'; +import { shallowMount } from '@vue/test-utils'; import { getMountOptions } from '@/helpers/unit-test-helper.js'; import { createTestingPinia } from '@pinia/testing'; import navigationScenarios from '@/router/router-constants/navigation-scenarios.js'; import { getRandomString, getRandomInt } from '@/helpers/data-generation.js'; import settleAllPromises from '@/helpers/layout-helper.js'; import { fetchCmsContentForPage } from '@/helpers/cms-content-helper'; -import routerParams from '@/router/router-constants/router-params'; import { useMainStore } from '@/store/index.js'; +import getPriceOfLineItems from '@/helpers/price-calculator.js'; jest.mock('@/helpers/layout-helper.js', () => jest.fn()); +jest.mock('@/helpers/price-calculator.js', () => jest.fn()); jest.mock('@/helpers/cms-content-helper', () => ({ fetchCmsContentForPage: jest.fn(), @@ -21,10 +22,15 @@ jest.mock('@/helpers/cms-content-helper', () => ({ processIfStatements: jest.fn() })); +const SAFELITE_PROVIDER = 'Safelite'; + const mockMixin = { methods: { getCmsContent: jest.fn().mockImplementation(() => ''), - setCmsContent: jest.fn() + setCmsContent: jest.fn(), + onSubmit: jest.fn(), + onInvalidSubmit: jest.fn(), + navigateBackByVehicleQuestions: jest.fn() } }; @@ -51,6 +57,7 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu }); mountOptions.global.stubs = { + ...mountOptions.global.stubs, siteFooter: footerStub, siteHeader: true, recalModal: true, @@ -79,44 +86,28 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu settleAllPromises.mockImplementation(() => apiPromise); fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); - const wrapper = mount(coverageStatement, mountOptions); + const wrapper = shallowMount(coverageStatement, mountOptions); return { wrapper }; } -describe.skip('coverageStatement.vue', () => { - describe('method arePagePrerequisitesValid...', () => { - test('Should return true for valid page requisites if vin exists', () => { - // Arrange - const { wrapper } = getMountedComponent({ - order: { - vehicle: { - vin: getRandomString(5, 20) - } +describe('coverageStatement.vue-working', () => { + test('returns the initial data', () => { + // Arrange + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + policyLookupSuccessful: true, + noCoverage: false } - }); + } + }; + const { wrapper } = getMountedComponent(mainInitialState); - // Act - const arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - - // Assert - expect(arePagePrerequisitesValid).toBeTruthy(); - }); - test('Should return false for valid page requisites if vin is missing', () => { - // Arrange - const { wrapper } = getMountedComponent({ - order: { - vehicle: { - vin: null - } - } - }); - - // Act - const arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - - // Assert - expect(arePagePrerequisitesValid).not.toBeTruthy(); - }); + // Assert + expect(wrapper.vm.$data).toMatchSnapshot(); }); describe('Rendering', () => { test('Should render site header', () => { @@ -171,663 +162,920 @@ describe.skip('coverageStatement.vue', () => { expect(footer.exists()).toBe(true); }); }); - describe('Verified ITAC scenario', () => { - test('If policy lookup successful, not No Comp, and deductible > service price, verifiedITAC returns true', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice + 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible - }, - policyLookupSuccessful: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] - }); - - // Assert - expect(wrapper.vm.verifiedITAC).toBeTruthy(); - }); - test('If policy lookup unsuccessful, verifiedITAC returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - policyLookupSuccessful: false - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedITAC).toBeFalsy(); - }); - test('If No Comp, verifiedITAC returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedITAC).toBeFalsy(); - }); - test('If deductible < service price, verifiedITAC returns false', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice - 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + describe('Computed', () => { + describe('verifiedNoComp', () => { + test.each([true, false])('returns false when policyLookupSuccessful false', (isNoComp) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: isNoComp, + policyLookupSuccessful: false } } - } - }; + }; + const { wrapper } = getMountedComponent(mainInitialState); - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] + // Act + const result = wrapper.vm.verifiedNoComp; + + // Assert + expect(result).toBeFalsy(); }); - - // Assert - expect(wrapper.vm.verifiedITAC).toBeFalsy(); - }); - }); - describe('Verified Deductible scenario', () => { - test('If policy lookup successful, not No Comp, and service price > deductible, verifiedITAC returns true', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice - 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible - }, - policyLookupSuccessful: true - } - } - }; - - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] - }); - - // Assert - expect(wrapper.vm.verifiedDeductible).toBeTruthy(); - }); - test('If policy lookup unsuccessful, verifiedDeductible returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - policyLookupSuccessful: false - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedDeductible).toBeFalsy(); - }); - test('If No Comp, verifiedDeductible returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedDeductible).toBeFalsy(); - }); - test('If service price < deductible, verifiedDeductible returns false', () => { - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice + 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + test.each([true, false])('returns false when isNoComp false', (policyLookupSuccessful) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: false, + policyLookupSuccessful } } - } - }; + }; + const { wrapper } = getMountedComponent(mainInitialState); - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] + // Act + const result = wrapper.vm.verifiedNoComp; + + // Assert + expect(result).toBeFalsy(); }); - - // Assert - expect(wrapper.vm.verifiedDeductible).toBeFalsy(); - }); - test('If deductible is null, verifiedDeductible returns false', () => { - const sellingPrice = getRandomInt(100, 500); - const deductible = null; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + test('returns true when policyLookupSuccessful true and policyLookupSuccessful true', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: true, + policyLookupSuccessful: true } } - } - }; + }; + const { wrapper } = getMountedComponent(mainInitialState); - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] + // Act + const result = wrapper.vm.verifiedNoComp; + + // Assert + expect(result).toBeTruthy(); }); - - // Assert - expect(wrapper.vm.verifiedDeductible).toBeFalsy(); }); - }); - describe('No Comp scenario', () => { - test('If noCoverage = true, verifiedNoComp returns true', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: true, - policyLookupSuccessful: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedNoComp).toBeTruthy(); - }); - test('If noCoverage = false, verifiedNoComp returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.verifiedNoComp).toBeFalsy(); - }); - }); - describe('Unverified scenario', () => { - test('If policyLookupSuccessful false, unverified returns true', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - policyLookupSuccessful: false - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.unverified).toBeTruthy(); - }); - test('If policyLookupSuccessful is true, unverified returns false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - policyLookupSuccessful: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Assert - expect(wrapper.vm.unverified).toBeFalsy(); - }); - }); - describe('Navigation', () => { - test('If Unverified, navigate forward with CLICKED_FORWARD scenario', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - policyLookupSuccessful: false - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - - // Act - wrapper.vm.forwardButtonAction(); - - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); - }); - test('If Verified Deductible, navigate forward with CLICKED_FORWARD scenario', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice - 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + describe('verifiedITAC', () => { + const priceOfLineItems = 213; + test.each([true, false])('returns false when policyLookupSuccessful false', (isNoComp) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: isNoComp, + policyLookupSuccessful: false }, - policyLookupSuccessful: true + currentDeductible: priceOfLineItems + 1 } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ] + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedITAC; + + // Assert + expect(result).toBeFalsy(); }); - - // Act - wrapper.vm.forwardButtonAction(); - - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); - }); - test('If Verified ITAC and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice + 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + test.each([true, false])('returns false when isNoComp true', (policyLookupSuccessful) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: true, + policyLookupSuccessful }, - policyLookupSuccessful: true + currentDeductible: priceOfLineItems + 1 } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ], - selectedProvider: 'Safelite' + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedITAC; + + // Assert + expect(result).toBeFalsy(); }); - - // Act - wrapper.vm.forwardButtonAction(); - - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); - }); - test('If Verified ITAC, selected other shop, and TPA enabled, navigate forward w/ CLICKED_FORWARD_WITH_TPA_ENABLED', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice + 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + test.each([ + [true, false], + [true, true], + [false, false], + [false, true] + ])('returns false when deductibleValue equals totalServicePrice', (noCoverage, policyLookupSuccessful) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage, + policyLookupSuccessful }, - policyLookupSuccessful: true + currentDeductible: priceOfLineItems } - }, - issConfig: { - enableTPAFlow: true - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ], - selectedProvider: 'Other' + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedITAC; + + // Assert + expect(result).toBeFalsy(); }); + test.each([ + [true, false], + [true, true], + [false, false], + [false, true] + ])( + 'returns false when deductibleValue less than totalServicePrice when noCoverage is %p and policyLookupSuccessful is %p', + (noCoverage, policyLookupSuccessful) => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage, + policyLookupSuccessful + }, + currentDeductible: priceOfLineItems - 1 + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); - // Act - wrapper.vm.forwardButtonAction(); + // Act + const result = wrapper.vm.verifiedITAC; - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD_WITH_TPA_ENABLED, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); - }); - test('If Verified ITAC, selected other shop, and TPA disabled, navigate forward w/ CLICKED_FORWARD_WITH_TPA_DISABLED', () => { - // Arrange - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice + 1; - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: false, - deductible: { - repair: deductible + // Assert + expect(result).toBeFalsy(); + } + ); + test('returns true when deductibleValue more than totalServicePrice, noComp is false, and policyLookupSuccessful true', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + noCoverage: false, + policyLookupSuccessful: true }, - policyLookupSuccessful: true + currentDeductible: priceOfLineItems + 1 } - }, - issConfig: { - enableTPAFlow: false - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - availableLineItems: [ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 - } - ], - selectedProvider: 'Other' + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedITAC; + + // Assert + expect(result).toBeTruthy(); }); - - // Act - wrapper.vm.forwardButtonAction(); - - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD_WITH_TPA_DISABLED, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); }); - test('If No Comp and selected Safelite, navigate forward with CLICKED_FORWARD scenario', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true - }, - policy: { - noCoverage: true, - policyLookupSuccessful: true - } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); - wrapper.setData({ - isVerified: false, - selectedProvider: 'Safelite' + describe('verifiedDeductible', () => { + const servicePrice = 123; + describe('claim registration required', () => { + const issConfig = { isClaimRegistrationRequired: true }; + let verifiedDeductibleStoreState; + beforeEach(() => { + verifiedDeductibleStoreState = { + issConfig, + order: { + payment: { + insuranceCoverage: { + isVerified: true + } + }, + policy: { + noCoverage: false, + policyLookupSuccessful: false + }, + currentDeductible: servicePrice - 1 + } + }; + getPriceOfLineItems.mockImplementation(() => servicePrice); + }); + test('returns false when deductible is null', () => { + // Arrange + const mainInitialState = verifiedDeductibleStoreState; + mainInitialState.order.currentDeductible = null; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when register claim not successful', () => { + // Arrange + const mainInitialState = verifiedDeductibleStoreState; + mainInitialState.order.payment.insuranceCoverage.isVerified = false; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns true when register claim successful, isNoComp false, and service price over deductible', () => { + // Arrange + const { wrapper } = getMountedComponent(verifiedDeductibleStoreState); + + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeTruthy(); + }); }); + describe('claim registration not required', () => { + const issConfig = { isClaimRegistrationRequired: false }; + let verifiedDeductibleStoreState; + beforeEach(() => { + verifiedDeductibleStoreState = { + issConfig, + order: { + payment: { + insuranceCoverage: { + isVerified: false + } + }, + policy: { + noCoverage: false, + policyLookupSuccessful: true + }, + currentDeductible: servicePrice - 1 + } + }; + }); + test('returns false when policy lookup not successful', () => { + // Arrange + const mainInitialState = verifiedDeductibleStoreState; + mainInitialState.order.policy.policyLookupSuccessful = false; + const { wrapper } = getMountedComponent(mainInitialState); - // Act - wrapper.vm.forwardButtonAction(); + // Act + const result = wrapper.vm.verifiedDeductible; - // Assert - expect(wrapper.vm.$router.navigate) - .toHaveBeenCalledWith( - navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, - undefined, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); - }); - }); - describe('ADAS', () => { - test('if Replace and parts require recalibration, isADAS should return true', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: false + // Assert + expect(result).toBeFalsy(); + }); + test('returns true when policyLookupSuccessful, isNoComp false, and deductible over service price', () => { + // Arrange + const { wrapper } = getMountedComponent(verifiedDeductibleStoreState); + + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeTruthy(); + }); + }); + test('returns false when isNoComp true', () => { + // Arrange + const isNoComp = true; + const storeState = { + issConfig: { + isClaimRegistrationRequired: false }, - lineItems: { - glassParts: [ - { - requiresRecalibration: true + order: { + payment: { + insuranceCoverage: { + isVerified: true } - ] + }, + policy: { + noCoverage: isNoComp, + policyLookupSuccessful: true + }, + currentDeductible: servicePrice - 1 } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); + }; + const { wrapper } = getMountedComponent(storeState); - // Assert - expect(wrapper.vm.isADAS).toBeTruthy(); - }); - test('if Replace and parts do not require recalibration, isADAS should return false', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: false + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when service price below deductible', () => { + // Arrange + const storeState = { + issConfig: { + isClaimRegistrationRequired: false }, - lineItems: { - glassParts: [ - { - requiresRecalibration: false + order: { + payment: { + insuranceCoverage: { + isVerified: true } - ] + }, + policy: { + noCoverage: false, + policyLookupSuccessful: true + }, + currentDeductible: servicePrice + 1 } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); + }; + const { wrapper } = getMountedComponent(storeState); - // Assert - expect(wrapper.vm.isADAS).toBeFalsy(); + // Act + const result = wrapper.vm.verifiedDeductible; + + // Assert + expect(result).toBeFalsy(); + }); }); - test('if Repair, isADAS should return true', () => { - // Arrange - const mainInitialState = { - order: { - damage: { - isRepair: true + describe('isADAS', () => { + test('returns false when glassParts null', () => { + // Arrange + const mainInitialState = { + order: { + lineItems: { + glassParts: null + } } - } - }; - const { wrapper } = getMountedComponent(mainInitialState); + }; + const { wrapper } = getMountedComponent(mainInitialState); - // Assert - expect(wrapper.vm.isADAS).toBeFalsy(); + // Act + const result = wrapper.vm.isADAS; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when glassParts empty', () => { + // Arrange + const mainInitialState = { + order: { + lineItems: { + glassParts: [] + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isADAS; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when no parts in glassParts require recalibration', () => { + // Arrange + const mainInitialState = { + order: { + lineItems: { + glassParts: [ + { + partNumber: 123, + requiresRecalibration: false + }, + { + partNumber: 111, + requiresRecalibration: false + } + ] + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isADAS; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns true when a part in glassParts require recalibration', () => { + // Arrange + const mainInitialState = { + order: { + lineItems: { + glassParts: [ + { + partNumber: 123, + requiresRecalibration: true + }, + { + partNumber: 111, + requiresRecalibration: false + } + ] + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isADAS; + + // Assert + expect(result).toBeTruthy(); + }); + }); + describe('isQuoteDisplayed', () => { + test('returns false when policy lookup not successful', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: false + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeFalsy(); + }); + describe('not no comp', () => { + const priceOfLineItems = 341; + test('returns false when deductible equal to service price', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + currentDeductible: priceOfLineItems + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when deductible less than service price', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + currentDeductible: priceOfLineItems - 1 + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns true when policy lookup successful and deductible over service price', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + currentDeductible: priceOfLineItems + 1 + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeTruthy(); + }); + }); + describe('not itac', () => { + const priceOfLineItems = 23; + test('returns false when isNoComp false', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + currentDeductible: priceOfLineItems + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns true when isNoComp true', () => { + // Arrange + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + noCoverage: true + }, + currentDeductible: priceOfLineItems + } + }; + getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems); + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.isQuoteDisplayed; + + // Assert + expect(result).toBeTruthy(); + }); + }); + }); + describe.each([[0], [12]])('shouldRegisterClaim', (policyVehicleId) => { + const servicePrice = 90; + let shouldRegisterClaimStoreStateItac; + beforeEach(() => { + shouldRegisterClaimStoreStateItac = { + order: { + payment: { + insuranceCoverage: { claimNumber: null } + }, + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + vehicle: { + policyVehicleId + }, + currentDeductible: servicePrice - 1 + }, + issConfig: { + isClaimRegistrationRequired: true + } + }; + getPriceOfLineItems.mockImplementation(() => servicePrice); + }); + test('returns false when policy lookup not successful', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.order.policy.policyLookupSuccessful = false; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when policy vehicle id is less than 0', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.order.vehicle.policyVehicleId = -3; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when policy vehicle id is null', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.order.vehicle.policyVehicleId = null; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when claim registration is not required', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.issConfig.isClaimRegistrationRequired = false; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when claim already registered', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.order.payment.insuranceCoverage.claimNumber = 13; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false when no comp', () => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.order.policy.noCoverage = true; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeFalsy(); + }); + describe('returns true when policy lookup success, vehicleId set to %p, claim reg req, claim not yet reg', () => { + test('and itac', () => { + // Arrange + const { wrapper } = getMountedComponent(shouldRegisterClaimStoreStateItac); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeTruthy(); + }); + test.each([ + [servicePrice], + [servicePrice + 1] + ])('and deductible case', (deductibleValue) => { + // Arrange + const mainInitialState = shouldRegisterClaimStoreStateItac; + mainInitialState.currentDeductible = deductibleValue; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.shouldRegisterClaim; + + // Assert + expect(result).toBeTruthy(); + }); + }); }); }); - describe('claim registration api call', () => { - it('claim registration not required => method not called', async () => { - // Arrange - const { wrapper } = getMountedComponent({ - issConfig: { - isClaimRegistrationRequired: false - } - }); - - // Assert - expect(wrapper.vm.mainStore.registerClaim).not.toHaveBeenCalled(); - }); - - it('claim registration required => register claim method called', async () => { - // Arrange - const sellingPrice = getRandomInt(50, 100); - const deductible = sellingPrice - 1; - const initialStore = { - order: { - policy: { - policyLookupSuccessful: true, - noCoverage: false, - deductible: { - repair: deductible + describe('methods', () => { + describe('arePagePrerequisitesValid', () => { + test('returns false if car id not set', () => { + // Arrange + const mainInitialState = { + order: { + vehicle: { + carId: null } - }, - damage: { - isRepair: true } - }, - issConfig: { - isClaimRegistrationRequired: true - } - }; - const mockStoreActions = () => { - useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve()); - useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve()); - useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve()); - useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve([ - { - sellingPrice, - kitPrice: 0, - laborAmount: 0 + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(result).toBeFalsy(); + }); + test('returns false if car id set to 0', () => { + // Arrange + const mainInitialState = { + order: { + vehicle: { + carId: 0 + } } - ])); - }; - const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions); - const next = (method) => { method(wrapper.vm); }; + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(result).toBeFalsy(); + }); + test.each([[-1], [1], [123]])('returns true if car id set to %p', (carId) => { + // Arrange + const mainInitialState = { + order: { + vehicle: { carId } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(result).toBeTruthy(); + }); + }); + test.each([ + [0, '$0.00'], + [1, '$1.00'], + [12, '$12.00'], + [1.2, '$1.20'], + [1.25, '$1.25'], + [1.254, '$1.25'], + [1.255, '$1.26'], + [-1, '-$1.00'] + ])('getFormattedAmount given %p returns "%p"', (value, expected) => { + // Arrange + const { wrapper } = getMountedComponent(); // Act - coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next); - for (let i = 0; i < 7; i++) { - // eslint-disable-next-line no-await-in-loop - await nextTick(); - } + const result = wrapper.vm.getFormattedAmount(value); // Assert - expect(wrapper.vm.mainStore.registerClaim).toHaveBeenCalled(); + expect(result).toBe(expected); + }); + describe('navigateForward', () => { + const servicePrice = 82; + beforeEach(() => { + getPriceOfLineItems.mockImplementation(() => servicePrice); + }); + test('If Unverified, navigate forward with CLICKED_FORWARD scenario', () => { + // Arrange + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + policyLookupSuccessful: false + }, + currentDeductible: null + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD, + undefined + ); + }); + test('If Verified Deductible, navigate forward with CLICKED_FORWARD scenario', () => { + // Arrange + const deductible = servicePrice - 1; + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + noCoverage: false, + policyLookupSuccessful: true + }, + currentDeductible: deductible + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD, + undefined + ); + }); + test('If Verified ITAC and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => { + // Arrange + const deductible = servicePrice + 1; + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + noCoverage: false, + policyLookupSuccessful: true + }, + currentDeductible: deductible + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + wrapper.setData({ + selectedProvider: SAFELITE_PROVIDER + }); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, + undefined + ); + }); + test('If Verified ITAC, selected other shop, navigate forward w/ CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP', () => { + // Arrange + const deductible = servicePrice + 1; + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + noCoverage: false, + policyLookupSuccessful: true + }, + currentDeductible: deductible + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + wrapper.setData({ + selectedProvider: 'Other' + }); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP, + undefined + ); + }); + test('If No Comp and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => { + // Arrange + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + noCoverage: true, + policyLookupSuccessful: true + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + wrapper.setData({ + selectedProvider: SAFELITE_PROVIDER + }); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, + undefined + ); + }); + test('If No comp and selected other shop, navigate forward with CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP ', () => { + // Arrange + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + policy: { + noCoverage: true, + policyLookupSuccessful: true + } + } + }; + const { wrapper } = getMountedComponent(mainInitialState); + wrapper.setData({ + selectedProvider: 'other' + }); + + // Act + wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP, + undefined + ); + }); }); }); -}); - -describe('coverageStatement.vue-working', () => { describe('ITAC flag', () => { test('ITAC flag updated once component is initialized', async () => { // Arrange @@ -903,4 +1151,74 @@ describe('coverageStatement.vue-working', () => { expect(wrapper.vm.mainStore.registerClaim).toHaveBeenCalledTimes(0); }); }); + describe('claim registration api call', () => { + it('claim registration not required => method not called', async () => { + // Arrange + const mockStoreActions = () => { + useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve()); + }; + const { wrapper } = getMountedComponent({ + issConfig: { + isClaimRegistrationRequired: false + } + }, {}, mockStoreActions); + const next = (method) => { method(wrapper.vm); }; + + // Act + coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next); + for (let i = 0; i < 7; i++) { + // eslint-disable-next-line no-await-in-loop + await nextTick(); + } + + // Assert + expect(wrapper.vm.mainStore.registerClaim).not.toHaveBeenCalled(); + }); + + it('claim registration required => register claim method called', async () => { + // Arrange + const servicePrice = 7283; + const deductible = servicePrice - 1; + const initialStore = { + order: { + payment: { + insuranceCoverage: { claimNumber: null } + }, + policy: { + policyLookupSuccessful: true, + noCoverage: false + }, + vehicle: { + policyVehicleId: 1 + }, + currentDeductible: deductible + }, + issConfig: { + isClaimRegistrationRequired: true + } + }; + getPriceOfLineItems.mockImplementation(() => servicePrice); + const mockStoreActions = () => { + useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve()); + useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve()); + }; + const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions); + const next = (method) => { method(wrapper.vm); }; + + // Act + coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next); + for (let i = 0; i < 7; i++) { + // eslint-disable-next-line no-await-in-loop + await nextTick(); + } + + // Assert + expect(wrapper.vm.mainStore.registerClaim).toHaveBeenCalled(); + }); + }); }); diff --git a/src/layouts/coverage-statement/coverage-statement.vue b/src/layouts/coverage-statement/coverage-statement.vue index 00a84f1a..cc0987be 100644 --- a/src/layouts/coverage-statement/coverage-statement.vue +++ b/src/layouts/coverage-statement/coverage-statement.vue @@ -35,26 +35,26 @@
- {{ formattedDeductible }} + {{ deductibleForDisplay }}
- {{ formattedServicePrice }} + {{ servicePriceForDisplay }}
{{ deductibleText }}  - {{ formattedDeductible }} + {{ deductibleForDisplay }}
@@ -67,18 +67,18 @@ v-html="nextStepsBody"> @@ -88,7 +88,7 @@ cmsWidgetName="SiteFooterWidget" :isForwardActionDisabled="!meta.valid" @backClicked="navigateBackByVehicleQuestions" - @forwardClicked="forwardButtonAction" /> + @forwardClicked="navigateForward" /> @@ -126,11 +126,17 @@ import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin.js'; import globalRules from '@/constants/global-rules.js'; import baseFormMixin from '@/mixins/base-form-mixin.js'; import navigationScenarios from '@/router/router-constants/navigation-scenarios.js'; -import routerParams from '@/router/router-constants/router-params'; import issPageValues from '@/router/router-constants/issPage-values'; -import bailoutCode from '@/constants/bailoutCode'; import bailoutMessage from '@/constants/bailoutMessage'; import coverageStatuses from '@/constants/coverage-statuses'; +import widgetFields from '@/constants/cms-widget-fields.js'; +import getPriceOfLineItems from '@/helpers/price-calculator.js'; + +const SAFELITE_PROVIDER = 'Safelite'; + +function setBailout(currentRoute, message) { + useMainStore().setBailout(currentRoute, message); +} export default { name: 'coverage-statement', @@ -165,8 +171,8 @@ export default { ]; const resultMap = await settleAllPromises(promiseResultMap); - const clonedGlassParts = useMainStore().order.lineItems.glassParts - ? JSON.parse(JSON.stringify(useMainStore().order.lineItems.glassParts)) + const clonedGlassParts = useMainStore().lineItems.glassParts + ? JSON.parse(JSON.stringify(useMainStore().lineItems.glassParts)) : []; const availableLineItems = [ ...(resultMap.supportingItems ?? []), @@ -175,17 +181,14 @@ export default { let hasBailedOut = false; let pricingResults = []; - if (useMainStore().order.policy.policyLookupSuccessful && useMainStore().order.vehicle.policyVehicleId >= 0) { + if (useMainStore().policy.policyLookupSuccessful && useMainStore().vehicle.policyVehicleId >= 0) { await useMainStore().getFinalDeductible(); pricingResults = await useMainStore().getPriceOrderItems(availableLineItems) .catch((err) => { - useMainStore().setBailout( - to, - bailoutMessage.pricingResponseError( - availableLineItems.map((li) => li.partNumber), - { code: err.code, message: err.message, data: err.data } - ) - ); + 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}`); }); @@ -197,22 +200,27 @@ export default { vm.setCmsContent(resultMap.cmsContent); vm.setSupportingItems(resultMap.supportingItems); // eslint-disable-next-line no-param-reassign - vm.availableLineItems = pricingResults; + vm.setBaseServiceLineItems(pricingResults); vm.$refs.loadingModal.showModal(); - vm.initializeComponent(availableLineItems); + vm.initializeComponent(); if (!vm.unverified) { useMainStore().disableKeyFields(); } }); } }, - setup() { - const mainStore = useMainStore(); - return { mainStore }; - }, data() { + const { isRepair } = useMainStore().damage; + const { policyLookupSuccessful, noCoverage } = useMainStore().policy; return { - availableLineItems: [], + currencyFormatter: new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD' + }), + isRepair, + policyLookupSuccessful, + isNoComp: noCoverage ?? false, + baseServiceLineItems: [], selectedProvider: '', deductibleText: 'Your deductible is', // TODO update when design team gives appropriate text @@ -224,83 +232,90 @@ export default { rules: { selectionRequired: globalRules.OPTION_REQUIRED }, - supportingItems: null + supportingItems: null, + widget: { + subheader: 'SiteSubHeaderWidget', + verifiedItacAlert: 'VerifiedITACAlert', + explanatoryText: 'ExplanatoryTextWidget', + nextStep: 'NextStepsWidget', + serviceProviderQuestion: 'ServiceProviderQuestion' + } }; }, computed: { - verifiedITACAlertHeader() { - return this.getCmsContent( - 'VerifiedITACAlert', - 'HeadlineText' + coverageStatementSubHeader() { + return this.getTextFromCmsWithCustomIfStatements( + this.widget.subheader, + widgetFields.SUB_HEADER_WIDGET.SUB_HEADER_TEXT ); }, - verifiedITACAlertBody() { + verifiedItacAlertHeader() { return this.getCmsContent( - 'VerifiedITACAlert', - 'BodyText' + this.widget.verifiedItacAlert, + widgetFields.ALERT_WIDGET.HEADLINE_TEXT + ); + }, + verifiedItacAlertBody() { + return this.getCmsContent( + this.widget.verifiedItacAlert, + widgetFields.ALERT_WIDGET.BODY_TEXT )?.replaceAll('{custom:costSavings}', this.costSavings); }, - coverageStatementSubHeader() { - return this.getSubheaderTextFromCms('SiteSubHeaderWidget'); - }, secondaryText() { - return this.getSecondaryTextFromCms('SiteSubHeaderWidget'); + return this.getTextFromCmsWithCustomIfStatements( + this.widget.subheader, + widgetFields.CONTENT_GROUP_WIDGET.SECONDARY_TEXT + ); }, explanatoryText() { - return this.getExplantoryTextFromCms('ExplanatoryTextWidget'); + return this.getTextFromCmsWithCustomIfStatements( + this.widget.explanatoryText, + widgetFields.CONTENT_GROUP_WIDGET.BODY_TEXT + ); }, nextStepsHeader() { - return this.getHeaderTextFromCms('NextStepsWidget'); + return this.getTextFromCmsWithCustomIfStatements( + this.widget.nextStep, + widgetFields.CONTENT_GROUP_WIDGET.HEADER_TEXT + ); }, nextStepsBody() { - return this.getBodyTextFromCms('NextStepsWidget')?.replaceAll('{custom:damage}', this.damageText); - }, - continueWithSchedulingBodyText() { - return this.getCmsContent('continueWithSchedulingCopy', 'BodyText'); - }, - unverifiedADASNextStepsBodyText() { - return this.getCmsContent('UnverifiedADASNextStepsWidget', 'BodyText')?.replaceAll('{custom:damage}', this.damageText); - }, - unverifiedNonADASNextStepsBodyText() { - return this.getCmsContent('UnverifiedNonADASNextStepsWidget', 'BodyText')?.replaceAll('{custom:damage}', this.damageText); - }, - unverifiedNonADASRepairBodyText() { - return this.getCmsContent('UnverifiedNonADASRepairWidget', 'BodyText'); + return this.getTextFromCmsWithCustomIfStatements( + this.widget.nextStep, + widgetFields.CONTENT_GROUP_WIDGET.BODY_TEXT + )?.replaceAll('{custom:damage}', this.damageText); }, damageText() { const damageString = getDamageString(); return damageString === 'match' ? '' : damageString; }, - vehicleDeductible() { + deductibleValue() { return useMainStore().order.currentDeductible; }, - formattedDeductible() { - return this.getDeductibleString(this.vehicleDeductible); - }, - isDeductibleZero() { - return this.vehicleDeductible === 0; - }, - policyLookupSuccessful() { - return useMainStore().order.policy.policyLookupSuccessful; + deductibleForDisplay() { + return this.getFormattedAmount(this.deductibleValue); }, registerClaimSuccessful() { return useMainStore().payment.insuranceCoverage.isVerified; }, verifiedNoComp() { - return this.policyLookupSuccessful ? useMainStore().order.policy.noCoverage : false; + return this.policyLookupSuccessful && this.isNoComp; }, verifiedITAC() { return this.policyLookupSuccessful - && !this.verifiedNoComp - && this.vehicleDeductible > this.totalServicePrice; + && !this.isNoComp + && this.deductibleValue > this.totalServicePrice; }, coveredAndServicePriceAboveOrEqualDeductible() { - return !this.verifiedNoComp && this.totalServicePrice >= this.vehicleDeductible; + return !this.verifiedNoComp && this.totalServicePrice >= this.deductibleValue; }, verifiedDeductible() { return useMainStore().isClaimRegistrationRequired - ? this.registerClaimSuccessful && this.coveredAndServicePriceAboveOrEqualDeductible && this.vehicleDeductible !== null - : this.policyLookupSuccessful && this.coveredAndServicePriceAboveOrEqualDeductible; + ? this.registerClaimSuccessful + && this.coveredAndServicePriceAboveOrEqualDeductible + && this.deductibleValue !== null + : this.policyLookupSuccessful + && this.coveredAndServicePriceAboveOrEqualDeductible; }, unverified() { return !this.verifiedDeductible && !this.verifiedITAC && !this.verifiedNoComp; @@ -309,42 +324,46 @@ export default { const parts = useMainStore().order.lineItems.glassParts; return parts !== null && !!parts.find((part) => part.requiresRecalibration); }, - isRepair() { - return useMainStore().order.damage.isRepair; - }, - // TODO share totalServicePrice() { - let total = 0; - this.availableLineItems.forEach((lineItem) => { - total += this.getTotalLineItemPrice(lineItem); - }); - return total; + return getPriceOfLineItems(this.baseServiceLineItems); }, - formattedServicePrice() { - return this.getServicePriceString(this.totalServicePrice); + servicePriceForDisplay() { + return this.getFormattedAmount(this.totalServicePrice); }, - costSavings() { - const savings = this.getITACCostSavings(this.vehicleDeductible, this.totalServicePrice); - const formattedSavings = parseFloat(savings).toFixed(2); - return `$${formattedSavings}`; + itacCostSavings() { + return this.deductibleValue - this.totalServicePrice; }, - questionText() { - return this.getCmsContent('ServiceProviderQuestion', 'QuestionText'); + itacCostSavingsForDisplay() { + return this.getFormattedAmount(this.itacCostSavings); }, - answersFromCms() { - return this.getCmsContent('ServiceProviderQuestion', 'Answers'); + serviceProviderQuestionText() { + return this.getCmsContent( + this.widget.serviceProviderQuestion, + widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT + ); }, - displayQuote() { + serviceProviderQuestionAnswers() { + return this.getCmsContent( + this.widget.serviceProviderQuestion, + widgetFields.INPUT_QUESTION_WIDGET.ANSWERS + ); + }, + isQuoteDisplayed() { return this.verifiedITAC || this.verifiedNoComp; + }, + shouldRegisterClaim() { + return this.policyLookupSuccessful + && useMainStore().vehicle.policyVehicleId != null + && useMainStore().vehicle.policyVehicleId >= 0 + && useMainStore().isClaimRegistrationRequired + && !useMainStore().isClaimAlreadyRegistered + && (this.coveredAndServicePriceAboveOrEqualDeductible || this.verifiedITAC); } }, watch: { selectedProvider() { - if (this.selectedProvider === 'Safelite') { - this.$refs.siteFooter.updateButtonText('Continue with Safelite'); - } else { - this.$refs.siteFooter.updateButtonText('Continue'); - } + const buttonText = this.selectedProvider === SAFELITE_PROVIDER ? 'Continue with Safelite' : 'Safelite'; + this.$refs.siteFooter.updateButtonText(buttonText); }, nextStepsBody(newValue, oldValue) { if (newValue !== oldValue) { @@ -360,82 +379,47 @@ export default { arePagePrerequisitesValid() { return !!useMainStore().vehicle.carId; }, + getFormattedAmount(amount) { + return this.currencyFormatter.format(amount); + }, async initializeComponent() { useMainStore().updatePolicyITACFlag(this.verifiedITAC); const coverageStatus = this.verifiedITAC || this.verifiedNoComp ? coverageStatuses.VERIFIED : coverageStatuses.PENDING; useMainStore().updateCoverageStatus(coverageStatus); - if (this.policyLookupSuccessful - && useMainStore().order.vehicle.policyVehicleId >= 0 - && useMainStore().isClaimRegistrationRequired - && !useMainStore().isClaimAlreadyRegistered - && (this.coveredAndServicePriceAboveOrEqualDeductible || this.verifiedITAC)) { + if (this.shouldRegisterClaim) { await useMainStore().registerClaim()?.catch(() => {}); } this.$refs.loadingModal.hideModal(); }, - async forwardButtonAction() { - return this.navigateForward(); - }, async navigateForward() { if (this.unverified || this.verifiedDeductible) { - this.mainStore.saveSupportingItems(this.supportingItems); - this.$router.navigate( - navigationScenarios.CLICKED_FORWARD, - this.$route, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); + useMainStore().updateSupportingItems(this.supportingItems); + this.navigateWithScenario(navigationScenarios.CLICKED_FORWARD); } else if (this.verifiedITAC || this.verifiedNoComp) { - useMainStore().updateIsSafeliteProvider(this.selectedProvider === 'Safelite'); - if (this.selectedProvider === 'Safelite') { - this.mainStore.saveSupportingItems(this.supportingItems); - this.$router.navigate( - navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, - this.$route, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); + useMainStore().updateIsSafeliteProvider(this.selectedProvider === SAFELITE_PROVIDER); + if (this.selectedProvider === SAFELITE_PROVIDER) { + useMainStore().updateSupportingItems(this.supportingItems); + this.navigateWithScenario(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE); } else { - this.mainStore.setBailout(this.$router.currentRoute, bailoutMessage.RequestCallback()); - this.$router.navigate( - navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP, - this.$route, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); + this.setBailoutWithMessage(bailoutMessage.RequestCallback()); + this.navigateWithScenario(navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP); } } else { - this.mainStore.setBailout(this.$router.currentRoute, bailoutMessage.coverageStatementInvalidState()); - this.$router.navigate( - navigationScenarios.CLICKED_FORWARD_WITH_INVALID_STATE, - this.$route, - {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } - ); + this.setBailoutWithMessage(bailoutMessage.coverageStatementInvalidState()); + this.navigateWithScenario(navigationScenarios.CLICKED_FORWARD_WITH_INVALID_STATE); } }, - processIfStatements, - getHeaderTextFromCms(cmsWidgetName) { - const header = this.getCmsContent(cmsWidgetName, 'HeaderText'); - return this.processIfStatements(header, 'custom', this.getCustomValueFromString); + setBailoutWithMessage(message) { + setBailout(this.$router.currentRoute, message); }, - getSubheaderTextFromCms(cmsWidgetName) { - const subHeader = this.getCmsContent(cmsWidgetName, 'SubHeaderText'); - return this.processIfStatements(subHeader, 'custom', this.getCustomValueFromString); + navigateWithScenario(scenario) { + this.$router.navigate(scenario, this.$route); }, - getBodyTextFromCms(cmsWidgetName) { - const bodyText = this.getCmsContent(cmsWidgetName, 'BodyText'); - return this.processIfStatements(bodyText, 'custom', this.getCustomValueFromString); - }, - getSecondaryTextFromCms(cmsWidgetName) { - const secondaryText = this.getCmsContent(cmsWidgetName, 'SecondaryText'); - return this.processIfStatements(secondaryText, 'custom', this.getCustomValueFromString); - }, - getExplantoryTextFromCms(cmsWidgetName) { - const explanatoryText = this.getCmsContent(cmsWidgetName, 'BodyText'); - return this.processIfStatements(explanatoryText, 'custom', this.getCustomValueFromString); + getTextFromCmsWithCustomIfStatements(widgetName, widgetField) { + const rawText = this.getCmsContent(widgetName, widgetField); + return processIfStatements(rawText, 'custom', this.getCustomValueFromString); }, getCustomValueFromString(str) { switch (str) { @@ -454,29 +438,18 @@ export default { case 'nonADASRepair': return this.isRepair; case 'deductibleOverZero': - return this.verifiedDeductible && !this.isDeductibleZero; // TODO what if deductible is negative? + return this.verifiedDeductible && this.deductibleValue !== 0; // TODO what if deductible is negative? case 'isDeductibleZero': - return this.verifiedDeductible && this.isDeductibleZero; + return this.verifiedDeductible && this.deductibleValue === 0; default: return null; } }, - getTotalLineItemPrice(lineItem) { - return lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice; - }, - getDeductibleString(deductible) { - const formattedDeductibleFloat = parseFloat(deductible).toFixed(2); - return `$${formattedDeductibleFloat}`; - }, - getServicePriceString(price) { - const formattedPriceFloat = parseFloat(price).toFixed(2); - return `$${formattedPriceFloat}`; - }, - getITACCostSavings(vehicleDeductible, totalServicePrice) { - return vehicleDeductible - totalServicePrice; - }, setSupportingItems(newSupportingItems) { this.supportingItems = newSupportingItems; + }, + setBaseServiceLineItems(lineItems) { + this.baseServiceLineItems = lineItems; } } }; @@ -486,7 +459,7 @@ export default { .cost { color: $green; font-size: 2rem; - font-weight: 300; + font-weight: $font-weight-light; line-height: 2.75rem; } diff --git a/src/layouts/order-confirmation/order-confirmation.spec.js b/src/layouts/order-confirmation/order-confirmation.spec.js index 590b5c1b..5883b9d1 100644 --- a/src/layouts/order-confirmation/order-confirmation.spec.js +++ b/src/layouts/order-confirmation/order-confirmation.spec.js @@ -12,7 +12,8 @@ import { createTestingPinia } from '@pinia/testing'; jest.mock('@/helpers/layout-helper.js', () => jest.fn()); jest.mock('@/helpers/cms-content-helper', () => ({ - fetchCmsContentForPage: jest.fn() + fetchCmsContentForPage: jest.fn(), + processIfStatements: jest.fn() })); const wordingText = 'wording Text {custom:address}'; @@ -34,12 +35,18 @@ const headerStub = { render: () => {} }; +const vehicleBannerStub = { + render: () => {} +}; + const initialStore = { order: { schedule: { date: '2024-03-01', startTime: '09:00', - endTime: '10:00' + endTime: '10:00', + jobMinMinutes: 60, + jobMaxMinutes: 90 }, serviceLocation: { address: '123 Test Way', @@ -70,7 +77,8 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu mountOptions.global.stubs = { siteFooter: footerStub, - siteHeader: headerStub + siteHeader: headerStub, + vehicleBanner: vehicleBannerStub }; const testingPinia = createTestingPinia({ @@ -110,6 +118,16 @@ describe('OrderConfirmation.vue', () => { // Assert expect(siteHeader.exists()).toBe(true); }); + test('Should render Vehicle Banner', () => { + // Arrange + const { wrapper } = getMountedComponent(initialStore); + + // Act + const vehicleBanner = wrapper.findComponent(vehicleBannerStub); + + // Assert + expect(vehicleBanner.exists()).toBe(true); + }); test('If Advanced flow, should display Site Footer', () => { // Arrange const testStore = { @@ -215,7 +233,7 @@ describe('OrderConfirmation.vue', () => { endTime: '10:00' }, serviceLocation: { - appointmentType: 'Drop Off' + appointmentType: 'Dropoff' } } }; @@ -282,7 +300,7 @@ describe('OrderConfirmation.vue', () => { zipCode: '12345' } }, - appointmentType: 'Drop Off' + appointmentType: 'Dropoff' } } }; @@ -324,5 +342,74 @@ describe('OrderConfirmation.vue', () => { // Assert expect(testValue).toEqual('
123 Safelite Street,
Mesa, AZ 12345
'); }); + test('appointmentWordingText2 should return Mobile text in expected format', () => { + // Arrange + const testStore = { + order: { + schedule: { + date: '2019-01-01', + startTime: '09:00', + endTime: '10:00' + }, + serviceLocation: { + address: '123 Test Way', + address2: '#1', + city: 'Mesa', + state: 'AZ', + zipCode: '12345', + appointmentType: 'Mobile' + } + } + }; + const { wrapper } = getMountedComponent(testStore); + + // Act + const testValue = wrapper.vm.appointmentWordingText2; + + // Assert + expect(testValue).toEqual(wordingText); + }); + test('appointmentWordingText2 should return Drop Off and text in expected format', () => { + // Arrange + const testStore = { + order: { + schedule: { + date: '2019-01-01', + startTime: '09:00', + endTime: '10:00' + }, + serviceLocation: { + provider: { + address: { + streetAddress: '123 Safelite Street', + city: 'Mesa', + state: 'AZ', + zipCode: '12345' + } + }, + appointmentType: 'Dropoff' + } + } + }; + const { wrapper } = getMountedComponent(testStore); + + // Act + const testValue = wrapper.vm.appointmentWordingText2; + const expected = wrapper.vm.getBodyText2FromCms('Test Widget'); + + // Assert + expect(testValue).toEqual(expected); + }); + test('appointmentWordingText2 should return In Shop text in expected format', () => { + // Arrange + const { wrapper } = getMountedComponent(initialStore); + + // Act + const testValue = wrapper.vm.appointmentWordingText2; + const expected = wrapper.vm.getBodyText2FromCms('Test Widget'); + + // Assert + expect(testValue).toEqual(expected); + }); }); }); diff --git a/src/layouts/order-confirmation/order-confirmation.vue b/src/layouts/order-confirmation/order-confirmation.vue index 38f2dc9e..f1bddf9e 100644 --- a/src/layouts/order-confirmation/order-confirmation.vue +++ b/src/layouts/order-confirmation/order-confirmation.vue @@ -26,9 +26,13 @@

{{ appointmentTimeFormatted }}

+
+
${this.providerAddress},
${this.providerCity}, ${this.providerState} ${this.providerZipCode}
`; }, appointmentWordingText() { - return this.formatWordingText(this.appointmentType); + switch (this.appointmentType) { + case AppointmentTypeStrings.MOBILE: + case AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP: + return this.mobileWordingText?.replaceAll( + '{custom:address}', + this.serviceLocationFullAddress + ); + case AppointmentTypeStrings.DROP_OFF: + return this.dropOffAndInShopWordingText?.replaceAll( + '{custom:address}', + this.providerFullAddress + ); + case AppointmentTypeStrings.IN_SHOP: + return this.dropOffAndInShopWordingText?.replaceAll( + '{custom:address}', + this.providerFullAddress + ); + default: + return null; + } + }, + appointmentWordingText2() { + switch (this.appointmentType) { + case AppointmentTypeStrings.MOBILE: + case AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP: + return this.mobileWordingText2; + case AppointmentTypeStrings.DROP_OFF: + return this.dropOffAndInShopWordingText2; + case AppointmentTypeStrings.IN_SHOP: + return this.dropOffAndInShopWordingText2?.replaceAll( + '{custom:inShopDuration}', + this.inShopAppointmentDuration + ); + default: + return null; + } + }, + mobileAppointment() { + return this.mainStore.isMobileAppointment; + }, + inShopAppointment() { + return this.mainStore.isInShopAppointment; + }, + dropOffAppointment() { + return this.mainStore.isDropOffAppointment; + }, + inShopAppointmentDuration() { + const inshopDurationTime = getDisplayTextForDurationLength( + this.mainStore.order.schedule.jobMinMinutes, + this.mainStore.order.schedule.jobMaxMinutes + ); + return inshopDurationTime; } }, mounted() { @@ -181,34 +244,29 @@ export default { }, formatAppointmentTime(appointmentType) { switch (appointmentType) { - case 'MOBILE': + case AppointmentTypeStrings.MOBILE: + case AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP: // eslint-disable-next-line max-len return `Between ${get12HourTimeMobileFormat(this.appointmentStartTime)} - ${get12HourTimeMobileFormat(this.appointmentEndTime)}`; - case 'DROP OFF': + case AppointmentTypeStrings.DROP_OFF: return 'Drop off before 9:30 AM'; - case 'INSHOP': + case AppointmentTypeStrings.IN_SHOP: return `at ${get12HourTimeFormat(this.appointmentStartTime)}`; default: return null; } }, - formatWordingText(appointmentType) { - switch (appointmentType) { - case 'MOBILE': - return this.mobileWordingText?.replaceAll( - '{custom:address}', - this.serviceLocationFullAddress - ); - case 'DROP OFF': - return this.dropOffAndInShopWordingText?.replaceAll( - '{custom:address}', - this.providerFullAddress - ); - case 'INSHOP': - return this.dropOffAndInShopWordingText?.replaceAll( - '{custom:address}', - this.providerFullAddress - ); + processIfStatements, + getBodyText2FromCms(cmsWidgetName) { + const body2Text = this.getCmsContent(cmsWidgetName, 'BodyText2'); + return this.processIfStatements(body2Text, 'custom', this.getCustomValueFromString); + }, + getCustomValueFromString(str) { + switch (str) { + case 'inShopAppointment': + return this.inShopAppointment; + case 'dropOffAppointment': + return this.dropOffAppointment; default: return null; } @@ -254,6 +312,7 @@ $page-side-padding: 1.5rem; .appointment-text { :deep(strong) { font-weight: $font-weight-bold; + color: $black; } } diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index d7c6b0df..24ee6102 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -197,7 +197,8 @@ export default { && providerLocation.zipCode ); - const isMobile = serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE; + const isMobile = serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE + || serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP; const serviceLocationReqs = (isMobile && mobileReqs) || (!isMobile && dropOffInshopReqs); diff --git a/src/layouts/payment-page/payment-page.vue b/src/layouts/payment-page/payment-page.vue index 7612e842..1f77de74 100644 --- a/src/layouts/payment-page/payment-page.vue +++ b/src/layouts/payment-page/payment-page.vue @@ -460,15 +460,11 @@ export default { computed: { payInAdvanceResponseUrl() { const { protocol, host } = window.location; - return `${protocol}//${host}/?issPage=${ - issPageValues.PAYMENT_RETURN - }&src=iss-nextgen`; + return `${protocol}//${host}/?issPage=${issPageValues.PAYMENT_RETURN}&src=iss-nextgen`; }, payInAdvanceCancelUrl() { const { protocol, host } = window.location; - return `${protocol}//${host}/?issPage=${ - issPageValues.PAYMENT_METHOD - }&src=iss-nextgen`; + return `${protocol}//${host}/?issPage=${issPageValues.PAYMENT_METHOD}&src=iss-nextgen`; }, dynamicCSSUrl() { const { protocol, hostname, port } = window.location; diff --git a/src/layouts/payment-return/payment-return.vue b/src/layouts/payment-return/payment-return.vue new file mode 100644 index 00000000..8e5d3de6 --- /dev/null +++ b/src/layouts/payment-return/payment-return.vue @@ -0,0 +1,143 @@ + + + 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 5a3fb0d4..4636b834 100644 --- a/src/layouts/schedule-page/schedule-page.vue +++ b/src/layouts/schedule-page/schedule-page.vue @@ -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); diff --git a/src/layouts/service-packages/service-packages.vue b/src/layouts/service-packages/service-packages.vue index 8644ad85..ea1cb229 100644 --- a/src/layouts/service-packages/service-packages.vue +++ b/src/layouts/service-packages/service-packages.vue @@ -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); } diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index dd78afc0..2771b30e 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -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) { diff --git a/src/router/index.js b/src/router/index.js index 4cd2dc45..fda08794 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,7 +2,7 @@ import { createWebHistory, createRouter } from 'vue-router'; import lazyLoadComponent from '@/router/dynamic-routing/component-loader'; import issPageValues from '@/router/router-constants/issPage-values'; -import { routingTable } from '@/router/router-constants/routing-table'; +import routingTable from '@/router/router-constants/routing-table'; import { useMainStore } from '@/store'; import eventBus from '@/helpers/event-bus/event-bus'; import { globalEvents, globalEventTypes } from '@/constants/events'; @@ -16,11 +16,9 @@ import showIssLoadingModal from '@/helpers/loading-modal-helper'; import analyticsMixin from '@/mixins/analytics-mixin'; import { saveSession } from '@/helpers/order-helper.js'; import routerParams from '@/router/router-constants/router-params'; -import bailoutCode from '@/constants/bailoutCode'; -import IssPageValues from '@/router/router-constants/issPage-values'; +import canBailoutNavigateBack from '@/helpers/bailout-helper'; +import bailoutMessage from '@/constants/bailoutMessage'; import navigationScenarios from './router-constants/navigation-scenarios'; -import canBailoutNavigateBack from "@/helpers/bailout-helper"; -import bailoutMessage from "@/constants/bailoutMessage"; const routes = [ { @@ -129,7 +127,7 @@ router.beforeEach(async (to, from) => { showIssLoadingModal(true); } - const isInIframe = fromQueryPage === IssPageValues.PAYMENT_PAGE; + const isInIframe = fromQueryPage === issPageValues.PAYMENT_PAGE; if (isInIframe) { // need to set window.top.location.href directly when navigating out of an iframe // especially when navigating with browser buttons @@ -139,7 +137,7 @@ router.beforeEach(async (to, from) => { const store = useMainStore(); // Prevent navigating backwards if we enter a bailout that we are not allowed to go back on - if (store.isBailout && from.name === IssPageValues.BAILOUT_PAGE && to.name !== 'root' && to.name !== IssPageValues.CONTACT_CONFIRMATION + if (store.isBailout && from.name === issPageValues.BAILOUT_PAGE && to.name !== 'root' && to.name !== issPageValues.CONTACT_CONFIRMATION && !canBailoutNavigateBack()) { return false; } diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 967b99d4..bd079640 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -96,6 +96,9 @@ const navigationScenarios = Object.freeze({ // Payment CLICKED_PAY_NOW: 'CLICKED_PAY_NOW', + PAY_IN_ADVANCE_ERROR: 'PAY_IN_ADVANCE_ERROR', + PAY_IN_ADVANCE_CREDIT_CARD_ERROR: 'PAY_IN_ADVANCE_CREDIT_CARD_ERROR', + PAY_IN_ADVANCE_SUCCESS: 'PAY_IN_ADVANCE_SUCCESS', // Bailout CLICKED_FORWARD_WITH_BAILOUT: 'CLICKED_FORWARD_WITH_BAILOUT' diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index d20f59cd..99582af8 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -641,6 +641,23 @@ const routingTable = () => [ } ] }, + { + issPageValue: issPageValues.PAYMENT_RETURN, + maps: [ + { + scenario: navigationScenarios.PAY_IN_ADVANCE_ERROR, + destinationIssPageValue: issPageValues.PAYMENT_METHOD + }, + { + scenario: navigationScenarios.PAY_IN_ADVANCE_CREDIT_CARD_ERROR, + destinationIssPageValue: issPageValues.PAYMENT_PAGE + }, + { + scenario: navigationScenarios.PAY_IN_ADVANCE_SUCCESS, + destinationIssPageValue: issPageValues.CONFIRMATION + } + ] + }, { issPageValue: issPageValues.TPA_CONFIRMATION, maps: [ @@ -746,4 +763,4 @@ const routingTable = () => [ ]; -export { routingTable }; +export default routingTable; diff --git a/src/store/index.js b/src/store/index.js index 2f02613d..218df336 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -11,9 +11,10 @@ import applicationConfig from '@/constants/application-config'; import issPageValues from '@/router/router-constants/issPage-values'; import damageLocationsSelected from '@/constants/damage-locations-selected'; import coverageStatuses from '@/constants/coverage-statuses'; -import { AppointmentTypeStrings, PREMIUM_FEE_PART_TYPE } from '@/constants/schedule-constants'; +import { AppointmentTypeStrings } from '@/constants/schedule-constants'; import { convertDateStringToDate, getDateDifferenceInDays, militaryToTwelveHourTime } from '@/helpers/date-helper'; import { paymentMethods } from '@/constants/payment-method-constants'; +import webStorageConstants from '@/constants/web-storage-constants'; import { deductibleForSelectedVehicle, endorsementsForSelectedVehicle, noCoverageForSelectedVehicle, @@ -155,7 +156,22 @@ const getDefaultState = () => ({ }, parentAccountNumber: 0, isPayInAdvance: null, - payInAdvanceType: null + payInAdvanceType: null, + paypalToken: null, + creditCardToken: { + subscriptionId: null, + expMonth: null, + expYear: null, + cardType: null, + billToPostalCode: null, + billToFirstName: null, + billToLastName: null, + referenceNumber: null, + authCode: null, + transactionId: null, + transReferenceNumber: null, + lastFour: null + } }, contactInfo: { firstName: null, @@ -237,6 +253,7 @@ export const useMainStore = defineStore({ isMobileAppointment: (state) => state.order.serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE || state.order.serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, isDropOffAppointment: (state) => state.order.serviceLocation.appointmentType === AppointmentTypeStrings.DROP_OFF, + isInShopAppointment: (state) => state.order.serviceLocation.appointmentType === AppointmentTypeStrings.IN_SHOP, isClaimRegistrationRequired: (state) => state.issConfig.isClaimRegistrationRequired, isClaimAlreadyRegistered: (state) => state.order.payment.insuranceCoverage.claimNumber !== null, isBailout: (state) => state.applicationUser.pageData[issPageValues.BAILOUT_PAGE] != null, @@ -935,7 +952,6 @@ export const useMainStore = defineStore({ }).then((response) => resolve(response), (error) => reject(error)); }); }, - getCarrierAccountInfo() { return new Promise((resolve, reject) => { globalMethods.callHttpClient({ @@ -947,12 +963,10 @@ export const useMainStore = defineStore({ }).catch((error) => reject(error)); }); }, - 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; return globalMethods .callHttpClient({ @@ -962,7 +976,7 @@ export const useMainStore = defineStore({ carId, damageType: isRepair ? 'Repair' : 'Replace', parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER, - parts: glassPartsArray, + parts: glassParts ?? [], numberOfRepairChips: isRepair ? numberOfChips : 0 } }); @@ -1201,7 +1215,7 @@ export const useMainStore = defineStore({ submitToMainframe: !!this.order.referralNumber, loadedFromDupeCheck }, - additionalSuccessEventDataHandler: (response) => + additionalSuccessEventDataHandler: () => `Email provided: ${customer.emailAddress ? 'true' : 'false'}` }).then((response) => { if (loadedFromDupeCheck) { @@ -1303,7 +1317,23 @@ export const useMainStore = defineStore({ throw ex; } }, - + updateCreditCardToken(token) { + this.order.payment.creditCardToken.subscriptionId = token.subscriptionId; + this.order.payment.creditCardToken.expMonth = token.expMonth; + this.order.payment.creditCardToken.expYear = token.expYear; + this.order.payment.creditCardToken.cardType = token.cardType; + this.order.payment.creditCardToken.billToPostalCode = token.billToPostalCode; + this.order.payment.creditCardToken.billToFirstName = token.billToFirstName; + this.order.payment.creditCardToken.billToLastName = token.billToLastName; + this.order.payment.creditCardToken.referenceNumber = token.referenceNumber; + this.order.payment.creditCardToken.authCode = token.authCode; + this.order.payment.creditCardToken.transactionId = token.transactionId; + this.order.payment.creditCardToken.transReferenceNumber = token.transReferenceNumber; + this.order.payment.creditCardToken.lastFour = token.lastFour; + }, + updatePaypalToken(token) { + this.order.payment.paypalToken = token; + }, setSaveSessionPromise(promise) { this.applicationUser.saveSessionPromise = promise; }, @@ -1385,6 +1415,10 @@ export const useMainStore = defineStore({ this.order.serviceLocation.searchFilter = serviceLocationInfo.searchFilter; }, + resetState() { + Object.assign(this, getDefaultState()); + }, + resetRegistrationState() { this.order.vehicle.registration.licensePlate = null; this.order.vehicle.registration.address = null; @@ -1394,7 +1428,7 @@ export const useMainStore = defineStore({ this.order.vehicle.registration.firstName = null; this.order.vehicle.registration.lastName = null; }, - resetServiceLocationAndDependencies(context) { + resetServiceLocationAndDependencies() { this.resetServiceLocationAppointmentType(); this.resetServiceLocationProvider(); this.resetSchedule(); @@ -1470,8 +1504,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) { @@ -1494,6 +1528,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; @@ -1509,21 +1544,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; @@ -1683,8 +1703,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 }); @@ -1728,18 +1748,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) { @@ -2108,21 +2116,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(); }, @@ -2150,7 +2155,6 @@ export const useMainStore = defineStore({ this.resetInsurance(); this.resetBailout(); }, - savePaymentMethodChoice(paymentMethod) { const isPayInAdvance = paymentMethod !== paymentMethods.PAY_AT_TIME_OF_SERVICE; this.order.payment.isPayInAdvance = isPayInAdvance; @@ -2162,8 +2166,33 @@ export const useMainStore = defineStore({ method: endpoints.GetPaymentSignature.method, endpoint: endpoints.GetPaymentSignature.url }); - } + }, + hasSubmittedOrder() { + return window.sessionStorage.getItem(webStorageConstants.SUBMITTED_ORDER) !== null; + }, + + createSubmittedOrder() { + if (this.hasSubmittedOrder()) { + return; + } + const submittedOrder = this.order; + const { experiments } = this.applicationUser; + + // set to local storage + window.sessionStorage.setItem(webStorageConstants.SUBMITTED_ORDER, JSON.stringify(submittedOrder)); + + // clear vuex + this.resetState(); + + // restore user's experiments + this.applicationUser.experiments = experiments; + }, + + resetSubmittedOrder() { + // clear from local storage + window.sessionStorage.removeItem(webStorageConstants.SUBMITTED_ORDER); + } }, persist: true });