diff --git a/src/layouts/coverage-statement/coverage-statement.spec.js b/src/layouts/coverage-statement/coverage-statement.spec.js index de0d2ba7..c1c730ad 100644 --- a/src/layouts/coverage-statement/coverage-statement.spec.js +++ b/src/layouts/coverage-statement/coverage-statement.spec.js @@ -2,28 +2,30 @@ import coverageStatement from '@/layouts/coverage-statement/coverage-statement'; // Supporting Files -import { mount, shallowMount } from '@vue/test-utils'; +import { mount } 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 { useMainStore } from '@/store/index.js'; import { getRandomString, getRandomInt } from '@/helpers/data-generation.js'; +import { settleAllPromises } from '@/helpers/layout-helper.js'; +import { fetchCmsContentForPage } from '@/helpers/cms-content-helper'; -// Mock fetchCmsContentForPage -// jest.mock('@/helpers/cms-content-helper', () => ({ -// fetchCmsContentForPage: jest.fn(), -// processIfStatements: jest.fn(), -// getBodyTextFromCms: jest.fn(), -// })); +// Mock our module for promises +jest.mock("@/helpers/layout-helper.js", () => ({ + settleAllPromises: jest.fn(), +})); -// // Mock our module for promises. -// jest.mock('@/helpers/layout-helper.js', () => ({ -// settleAllPromises: jest.fn(), -// })); +// Mock fetchCmsContentForPage, setupModalLinks, and processIfStatements +jest.mock("@/helpers/cms-content-helper", () => ({ + fetchCmsContentForPage: jest.fn(), + setupModalLinks: jest.fn(), + processIfStatements: jest.fn() +})); describe('coverageStatement.vue', () => { describe("method arePagePrerequisitesValid...", () => { - test.only("Should return true for valid page requisites if vin exists", () => { + test("Should return true for valid page requisites if vin exists", () => { // Arrange const { wrapper } = setupMocks({}); useMainStore().order.vehicle.vin = getRandomString(5,20); @@ -100,15 +102,20 @@ describe('coverageStatement.vue', () => { }); }); describe('Verified ITAC scenario', () => { - test('If coverage verified, not No Comp, and deductible > service price, verifiedITAC returns true', () => { + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + const sellingPrice = getRandomInt(100, 500); + + test('If policy lookup successful, not No Comp, and deductible > service price, verifiedITAC returns true', () => { // Arrange - const mountOptions = getMountOptions({ - methods: { - getCmsContent: jest.fn().mockImplementation(() => ''), - setCmsContent: jest.fn(), - }, - }); - const sellingPrice = getRandomInt(100, 500); + const mountOptions = { + mixins: [mockMixin] + }; const deductible = sellingPrice + 1; const mainInitialState = { order: { @@ -119,7 +126,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } } }; @@ -128,13 +136,20 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); + const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -147,14 +162,20 @@ describe('coverageStatement.vue', () => { // Assert expect(wrapper.vm.verifiedITAC).toBeTruthy(); }); - test('If coverage unverified, verifiedITAC returns false', () => { + test('If policy lookup unsuccessful, verifiedITAC returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; + const mainInitialState = { order: { damage: { isRepair: true }, + policy: { + policyLookupSuccessful: false + } } }; mountOptions.global = { @@ -162,21 +183,28 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) + const wrapper = mount(coverageStatement, mountOptions); // Assert expect(wrapper.vm.verifiedITAC).toBeFalsy(); }); test('If No Comp, verifiedITAC returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { @@ -192,22 +220,28 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) + const wrapper = mount(coverageStatement, mountOptions); // Assert expect(wrapper.vm.verifiedITAC).toBeFalsy(); }); test('If deductible < service price, verifiedITAC returns false', () => { // Arrange - const mountOptions = getMountOptions(); - const sellingPrice = getRandomInt(100, 500); + const mountOptions = { + mixins: [mockMixin] + }; const deductible = sellingPrice - 1; const mainInitialState = { order: { @@ -227,13 +261,20 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); + const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -248,9 +289,19 @@ describe('coverageStatement.vue', () => { }); }); describe('Verified Deductible scenario', () => { - test('If coverage verified, not No Comp, and service price > deductible, verifiedITAC returns true', () => { + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + + test('If policy lookup successful, not No Comp, and service price > deductible, verifiedITAC returns true', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice - 1; const mainInitialState = { @@ -262,7 +313,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } } }; @@ -271,13 +323,20 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); + const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -290,14 +349,19 @@ describe('coverageStatement.vue', () => { // Assert expect(wrapper.vm.verifiedDeductible).toBeTruthy(); }); - test('If coverage unverified, verifiedDeductible returns false', () => { + test('If policy lookup unsuccessful, verifiedDeductible returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { isRepair: true }, + policy: { + policyLookupSuccessful: false + } } }; mountOptions.global = { @@ -305,21 +369,29 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) + const wrapper = mount(coverageStatement, mountOptions); // Assert expect(wrapper.vm.verifiedDeductible).toBeFalsy(); }); test('If No Comp, verifiedDeductible returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; + const mainInitialState = { order: { damage: { @@ -335,21 +407,28 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) - + const wrapper = mount(coverageStatement, mountOptions); + // Assert expect(wrapper.vm.verifiedDeductible).toBeFalsy(); }); test('If service price < deductible, verifiedDeductible returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice + 1; const mainInitialState = { @@ -370,13 +449,20 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); + const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -391,9 +477,19 @@ describe('coverageStatement.vue', () => { }); }); describe('No Comp scenario', () => { + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + test('If noCoverage = true, verifiedNoComp returns true', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { @@ -401,6 +497,7 @@ describe('coverageStatement.vue', () => { }, policy: { noCoverage: true, + policyLookupSuccessful: true } } }; @@ -409,21 +506,28 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) - + const wrapper = mount(coverageStatement, mountOptions); + // Assert expect(wrapper.vm.verifiedNoComp).toBeTruthy(); }); test('If noCoverage = false, verifiedNoComp returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { @@ -439,28 +543,46 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) - + const wrapper = mount(coverageStatement, mountOptions); + // Assert expect(wrapper.vm.verifiedNoComp).toBeFalsy(); }); }); describe('Unverified scenario', () => { - test('If isVerified is false, coverageUnverified returns true, coverageVerified returns false', () => { + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + + test('If policyLookupSuccessful false, unverified returns true', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { isRepair: true }, + policy: { + policyLookupSuccessful: false + } } }; mountOptions.global = { @@ -468,27 +590,36 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) - + const wrapper = mount(coverageStatement, mountOptions); + // Assert - expect(wrapper.vm.coverageUnverified).toBeTruthy(); - expect(wrapper.vm.coverageVerified).toBeFalsy(); + expect(wrapper.vm.unverified).toBeTruthy(); }); - test('If isVerified is true, coverageVerified returns true, coverageUnverified returns false', () => { + test('If policyLookupSuccessful is true, unverified returns false', () => { // Arrange - const mountOptions = getMountOptions(); + const mountOptions = { + mixins: [mockMixin] + }; const mainInitialState = { order: { damage: { isRepair: true }, + policy: { + policyLookupSuccessful: true + } } }; mountOptions.global = { @@ -496,37 +627,42 @@ describe('coverageStatement.vue', () => { initialState: { main: mainInitialState } - })] + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, } // Act - const wrapper = shallowMount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: true, - }) + const wrapper = mount(coverageStatement, mountOptions); // Assert - expect(wrapper.vm.coverageVerified).toBeTruthy(); - expect(wrapper.vm.coverageUnverified).toBeFalsy(); + expect(wrapper.vm.unverified).toBeFalsy(); }); }); describe('Navigation', () => { + const footer = { + render: () => {}, + methods: { + updateButtonText: jest.fn() + } + } + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + const sellingPrice = getRandomInt(100, 500); + test('If Unverified, navigate forward with CLICKED_FORWARD scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const loadingModal = { - render: () => {}, - methods: { - showModal: jest.fn(), - hideModal: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() @@ -538,6 +674,9 @@ describe('coverageStatement.vue', () => { damage: { isRepair: true }, + policy: { + policyLookupSuccessful: false + } } }; mountOptions.global = { @@ -563,9 +702,6 @@ describe('coverageStatement.vue', () => { // Act const wrapper = mount(coverageStatement, mountOptions); - wrapper.setData({ - isVerified: false, - }) // Act wrapper.vm.forwardButtonAction(); @@ -576,13 +712,6 @@ describe('coverageStatement.vue', () => { }); test('If Verified Deductible, navigate forward with CLICKED_FORWARD scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() @@ -590,7 +719,6 @@ describe('coverageStatement.vue', () => { mixins: [mockMixin] }; - const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice - 1; const mainInitialState = { order: { @@ -601,7 +729,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } } }; @@ -617,6 +746,7 @@ describe('coverageStatement.vue', () => { recalModal: true, contentGroupModal: true, alert: true, + 'loadingModal': loadingModal }, mocks: { $router: { @@ -627,7 +757,6 @@ describe('coverageStatement.vue', () => { const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -646,20 +775,12 @@ describe('coverageStatement.vue', () => { }); test('If Verified ITAC and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() }, mixins: [mockMixin] }; - const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice + 1; const mainInitialState = { order: { @@ -670,7 +791,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } }, @@ -687,6 +809,7 @@ describe('coverageStatement.vue', () => { recalModal: true, contentGroupModal: true, alert: true, + 'loadingModal': loadingModal }, mocks: { $router: { @@ -697,7 +820,6 @@ describe('coverageStatement.vue', () => { const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -712,19 +834,11 @@ describe('coverageStatement.vue', () => { wrapper.vm.forwardButtonAction(); // Assert - //expect(wrapper.vm.verifiedITAC).toBeTruthy(); expect(wrapper.vm.$router.navigate) .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, undefined); }); test('If Verified ITAC, selected other shop, and TPA enabled, navigate forward with CLICKED_FORWARD_WITH_TPA_ENABLED scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() @@ -732,7 +846,6 @@ describe('coverageStatement.vue', () => { mixins: [mockMixin] }; - const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice + 1; const mainInitialState = { order: { @@ -743,7 +856,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } }, issConfig: { @@ -762,6 +876,7 @@ describe('coverageStatement.vue', () => { recalModal: true, contentGroupModal: true, alert: true, + 'loadingModal': loadingModal }, mocks: { $router: { @@ -772,7 +887,6 @@ describe('coverageStatement.vue', () => { const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -783,24 +897,15 @@ describe('coverageStatement.vue', () => { selectedProvider: 'Other' }); - // Act wrapper.vm.forwardButtonAction(); // Assert - //expect(wrapper.vm.verifiedITAC).toBeTruthy(); expect(wrapper.vm.$router.navigate) .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_TPA_ENABLED, undefined); }); test('If Verified ITAC, selected other shop, and TPA disabled, navigate forward with CLICKED_FORWARD_WITH_TPA_DISABLED scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() @@ -808,7 +913,6 @@ describe('coverageStatement.vue', () => { mixins: [mockMixin] }; - const sellingPrice = getRandomInt(100, 500); const deductible = sellingPrice + 1; const mainInitialState = { order: { @@ -819,7 +923,8 @@ describe('coverageStatement.vue', () => { noCoverage: false, deductible: { repair: deductible, - } + }, + policyLookupSuccessful: true } }, issConfig: { @@ -838,6 +943,7 @@ describe('coverageStatement.vue', () => { recalModal: true, contentGroupModal: true, alert: true, + 'loadingModal': loadingModal }, mocks: { $router: { @@ -848,7 +954,6 @@ describe('coverageStatement.vue', () => { const wrapper = mount(coverageStatement, mountOptions); wrapper.setData({ - isVerified: true, availableLineItems: [ { sellingPrice: sellingPrice, @@ -859,7 +964,6 @@ describe('coverageStatement.vue', () => { selectedProvider: 'Other' }); - // Act wrapper.vm.forwardButtonAction(); @@ -870,13 +974,6 @@ describe('coverageStatement.vue', () => { }); test('If No Comp and selected Safelite, navigate forward with CLICKED_FORWARD scenario', () => { // Arrange - const footer = { - render: () => {}, - methods: { - updateButtonText: jest.fn() - } - } - const mountOptions = { router: { navigate: jest.fn() @@ -884,8 +981,6 @@ describe('coverageStatement.vue', () => { mixins: [mockMixin] }; - const sellingPrice = getRandomInt(100, 500); - const deductible = sellingPrice - 1; const mainInitialState = { order: { damage: { @@ -893,6 +988,7 @@ describe('coverageStatement.vue', () => { }, policy: { noCoverage: true, + policyLookupSuccessful: true } } }; @@ -908,6 +1004,7 @@ describe('coverageStatement.vue', () => { recalModal: true, contentGroupModal: true, alert: true, + 'loadingModal': loadingModal }, mocks: { $router: { @@ -926,50 +1023,196 @@ describe('coverageStatement.vue', () => { wrapper.vm.forwardButtonAction(); // Assert - //expect(wrapper.vm.verifiedNoComp).toBeTruthy(); expect(wrapper.vm.$router.navigate) .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, undefined); }); }); - // describe("claim registration api call", () => { - // it.only("claim registration not required => method not called", async () => { - // // Arrange - // const wrapper = setupMocks({}); + describe('ADAS', () => { + const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } + } + test("if Replace and parts require recalibration, isADAS should return true", () => { + // Arrange + const mountOptions = { + mixins: [mockMixin] + }; - // const store = useMainStore(); - // store.isClaimRegistrationRequired = false; + const mainInitialState = { + order: { + damage: { + isRepair: false + }, + lineItems: { + glassParts: [ + { + requiresRecalibration: true + } + ] + } + } + }; + + mountOptions.global = { + plugins: [createTestingPinia({ + initialState: { + main: mainInitialState + } + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, + } - // const to = { - // query: { issPage: getRandomString(4,10) } - // }; - // const next = jest.fn(); + // Act + const wrapper = mount(coverageStatement, mountOptions); - // // SUT - // coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next) + // Assert + expect(wrapper.vm.isADAS).toBeTruthy(); + }); + test("if Replace and parts do not require recalibration, isADAS should return false", () => { + // Arrange + const mountOptions = { + mixins: [mockMixin] + }; - // // Assert - // expect(store.registerClaim).not.toHaveBeenCalled(); - // }); + const mainInitialState = { + order: { + damage: { + isRepair: false + }, + lineItems: { + glassParts: [ + { + requiresRecalibration: false + } + ] + } + } + }; + + mountOptions.global = { + plugins: [createTestingPinia({ + initialState: { + main: mainInitialState + } + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, + } - // it("claim registration required => register claim method called", async () => { - // // Arrange - // const wrapper = setupMocks({}); + // Act + const wrapper = mount(coverageStatement, mountOptions); - // const store = useMainStore(); - // store.isClaimRegistrationRequired = true; + // Assert + expect(wrapper.vm.isADAS).toBeFalsy(); + }); + test("if Repair, isADAS should return true", () => { + // Arrange + const mountOptions = { + mixins: [mockMixin] + }; - // const to = { - // query: { issPage: getRandomString(4,10) } - // }; - // const next = jest.fn(); + const mainInitialState = { + order: { + damage: { + isRepair: true + }, + } + }; + + mountOptions.global = { + plugins: [createTestingPinia({ + initialState: { + main: mainInitialState + } + })], + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, + } - // // SUT - // coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next) + // Act + const wrapper = mount(coverageStatement, mountOptions); - // // Assert - // expect(store.registerClaim).toHaveBeenCalled(); - // }); - // }) + // Assert + expect(wrapper.vm.isADAS).toBeFalsy(); + }); + }) + describe("claim registration api call", () => { + it("claim registration not required => method not called", async () => { + // Arrange + const wrapper = setupMocks({}); + + const store = useMainStore(); + store.isClaimRegistrationRequired = false; + + const to = { + query: { issPage: getRandomString(4,10) } + }; + const next = jest.fn(); + + // SUT + coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next) + + // Assert + expect(store.registerClaim).not.toHaveBeenCalled(); + }); + + it("claim registration required => register claim method called", async () => { + // Arrange + const sellingPrice = getRandomInt(50,100); + const deductible = sellingPrice - 1; + const { wrapper } = setupMocks({ + }); + + await wrapper.setData({ + availableLineItems: [ + { + sellingPrice: sellingPrice, + kitPrice: 0, + laborAmount: 0, + } + ] + }) + + const store = useMainStore(); + store.order.policy.policyLookupSuccessful = true; + store.isClaimRegistrationRequired = true; + store.order.policy.noCoverage = false; + store.order.damage.isRepair = true; + store.order.policy.deductible.repair = deductible; + + const to = { + query: { issPage: getRandomString(4,10) } + }; + const next = jest.fn(); + + // SUT + coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next); + // Assert + expect(store.registerClaim).toHaveBeenCalled(); + }); + }) }) @@ -979,6 +1222,20 @@ const mockMixin = { setCmsContent: jest.fn(), }, }; +const footer = { + render: () => {}, + methods: { + updateButtonText: jest.fn() + } +} + +const loadingModal = { + render: () => {}, + methods: { + showModal: jest.fn(), + hideModal: jest.fn() + } +} function setupMocks() { @@ -986,170 +1243,40 @@ function setupMocks() router: { navigate: jest.fn() }, - - - // global: { - // plugins: [createTestingPinia()] - // } }); + mountOptions.global = { + stubs: { + 'siteFooter': footer, + siteHeader: true, + recalModal: true, + contentGroupModal: true, + alert: true, + 'loadingModal': loadingModal + }, + } + mountOptions.mixins = [mockMixin]; - // settleAllPromises.mockImplementation(() => apiResponses); - // fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); + const apiResponses = { + supportingItems: [], + }; + const apiPromise = Promise.resolve(apiResponses); + settleAllPromises.mockImplementation(() => apiPromise); + fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); - const wrapper = shallowMount(coverageStatement, mountOptions); + const wrapper = mount(coverageStatement, mountOptions); wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn(); - + wrapper.vm.$refs.loadingModal.showModal = jest.fn(); return { wrapper }; } -// describe ('test', () => { -// test ('dummy test', () => { -// // Arrange -// let test = "test"; - -// // Act -// test = "test2" - -// // Assert -// expect(test.length).toBe(5); -// }) -// }) - -// *Testing to be completed on SSR-603 - -// // Components -// import coverageStatement from "@/layouts/coverage-statement/coverage-statement.vue"; - -// // Supporting files -// import { shallowMount } from "@vue/test-utils"; -// import { getMountOptions } from "@/helpers/unit-test-helper.js"; -// import { useMainStore } from "@/store"; -// import baseMixin from "@/mixins/base-mixin"; -// import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; -// import { applicationConfig } from "@/constants/application-config"; -// import { fetchCmsContentForPage, setupModalLinks } from "@/helpers/cms-content-helper"; -// import { settleAllPromises } from "@/helpers/layout-helper.js"; -// import { createTestingPinia } from '@pinia/testing'; -// import { getRandomString } from '@/helpers/data-generation.js'; - -// jest.mock("@/helpers/damage-helper", () => ({ -// getDamageString: jest.fn(), -// })); - -// // Mock our module for promises. -// jest.mock("@/helpers/layout-helper.js", () => ({ -// settleAllPromises: jest.fn(), -// })); - -// // Mock fetchCmsContentForPage, setupModalLinks -// jest.mock("@/helpers/cms-content-helper", () => ({ -// fetchCmsContentForPage: jest.fn(), -// setupModalLinks: jest.fn(), -// })); - // describe("coverage-statement.vue...", () => { -// describe("navigation", () => { -// test("forwardButtonAction should trigger navigateForward", async () => { -// // Arrange -// const { wrapper } = setupMocks({}); - -// wrapper.vm.navigateForward = jest.fn(); - -// // Act -// await wrapper.vm.forwardButtonAction(); - -// //Assert -// expect(wrapper.vm.navigateForward).toHaveBeenCalled(); -// }); -// }); // describe("display correct coverage statement", () => { -// test("If damage is Repair, display NonADASRepair coverage statement", async () => { -// // Arrange -// const wrapper = shallowMount(coverageStatement, { -// mixins: [mockMixin], -// }); - -// useMainStore().order.damage.isRepair = true; - -// // Assert -// expect(wrapper.vm.bodyText).toEqual("NonADASRepairTestReturn"); -// }) - -// test("If damage is NonADAS Replace, display NonADASReplace coverage statement", async () => { -// // Arrange -// const wrapper = shallowMount(coverageStatement, { -// mixins: [mockMixin], -// }); - -// useMainStore().lineItems.glassParts = -// [ -// { -// requiresRecalibration: false, -// } -// ]; -// useMainStore().order.damage.isRepair = false; - -// // Assert -// expect(wrapper.vm.bodyText).toEqual("NonADASReplaceTestReturn"); -// }) - -// test("If damage is ADAS Replace, display ADASReplace coverage statement", async () => { -// // Arrange -// const wrapper = shallowMount(coverageStatement, { -// mixins: [mockMixin], -// }); -// useMainStore().lineItems.glassParts = [ -// { -// requiresRecalibration: true, -// } -// ]; -// useMainStore().order.damage.isRepair = false; - -// // Assert -// expect(wrapper.vm.bodyText).toEqual("ADASReplaceTestReturn"); -// }) +// // }); -// describe("claim registration api call", () => { -// it("claim registration not required => method not called", async () => { -// // Arrange -// const wrapper = setupMocks({}); - -// const store = useMainStore(); -// store.isClaimRegistrationRequired = false; - -// const to = { -// query: { issPage: getRandomString(4,10) } -// }; -// const next = jest.fn(); - -// // SUT -// coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next) - -// // Assert -// expect(store.registerClaim).not.toHaveBeenCalled(); -// }); - -// it("claim registration required => register claim method called", async () => { -// // Arrange -// const wrapper = setupMocks({}); - -// const store = useMainStore(); -// store.isClaimRegistrationRequired = true; - -// const to = { -// query: { issPage: getRandomString(4,10) } -// }; -// const next = jest.fn(); - -// // SUT -// coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next) - -// // Assert -// expect(store.registerClaim).toHaveBeenCalled(); -// }); +// // }) // });