diff --git a/src/layouts/duplicate-check/duplicate-check.spec.js b/src/layouts/duplicate-check/duplicate-check.spec.js index 691e9088..49ecd4f3 100644 --- a/src/layouts/duplicate-check/duplicate-check.spec.js +++ b/src/layouts/duplicate-check/duplicate-check.spec.js @@ -4,10 +4,11 @@ import duplicateCheck from '@/layouts/duplicate-check/duplicate-check.vue'; // Supporting Files import { shallowMount } from '@vue/test-utils'; import { getMountOptions } from '@/helpers/unit-test-helper.js'; -import { getRandomString, getRandomInt, getRandomBoolean } from '@/helpers/data-generation.js'; import { createTestingPinia } from '@pinia/testing'; import navigationScenarios from '@/router/router-constants/navigation-scenarios.js'; -import { useMainStore } from '@/store/index.js'; +import { getRandomString } from '@/helpers/data-generation.js'; + +const duplicateOrderText = 'Finish Existing Claim'; describe('duplicateCheck.vue', () => { describe('Rendering', () => { @@ -130,6 +131,205 @@ describe('duplicateCheck.vue', () => { // }); }); + describe('duplicateOrders computed', () => { + test('duplicateOrders in store undefined => returns empty list', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const mainInitialState = { + applicationUser: { + duplicateOrders: undefined + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(0); + }); + test('duplicateOrders in store empty => returns empty list', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const mainInitialState = { + applicationUser: { + duplicateOrders: [] + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(0); + }); + test('duplicateOrder in store with null vehicle year => returns order with only date in subtext', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const date = getRandomString(9, 9); + const referralNumber = getRandomString(6, 6); + const mainInitialState = { + applicationUser: { + duplicateOrders: [ + { + vehicleYear: null, + vehicleMake: getRandomString(5, 5), + vehicleModel: getRandomString(5, 5), + dateOfLoss: date, + referralNumber: referralNumber + } + ] + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(1); + expect(wrapper.vm.duplicateOrders[0]).toStrictEqual({ + Text: duplicateOrderText, + Name: referralNumber, + SubText: date + + }); + }); + test('duplicateOrder in store with null vehicle make => returns order with only date subtext', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const date = getRandomString(9, 9); + const referralNumber = getRandomString(6, 6); + const mainInitialState = { + applicationUser: { + duplicateOrders: [ + { + vehicleYear: getRandomString(6, 6), + vehicleMake: null, + vehicleModel: getRandomString(5, 5), + dateOfLoss: date, + referralNumber: referralNumber + } + ] + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(1); + expect(wrapper.vm.duplicateOrders[0]).toStrictEqual({ + Text: duplicateOrderText, + Name: referralNumber, + SubText: date + }); + }); + test('duplicateOrder in store with null vehicle model => returns order with only date subtext', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const date = getRandomString(9, 9); + const referralNumber = getRandomString(6, 6); + const mainInitialState = { + applicationUser: { + duplicateOrders: [ + { + vehicleYear: getRandomString(6, 6), + vehicleMake: getRandomString(6, 6), + vehicleModel: null, + dateOfLoss: date, + referralNumber: referralNumber + } + ] + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(1); + expect(wrapper.vm.duplicateOrders[0]).toStrictEqual({ + Text: duplicateOrderText, + Name: referralNumber, + SubText: date + }); + }); + test('duplicateOrder in store with all vehicle info => returns order with year, make, model and date in subtext', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const year = getRandomString(6, 6,); + const make = getRandomString(6, 6); + const model = getRandomString(6, 6); + const date = getRandomString(9, 9); + const referralNumber = getRandomString(6, 6); + const mainInitialState = { + applicationUser: { + duplicateOrders: [ + { + vehicleYear: year, + vehicleMake: make, + vehicleModel: model, + dateOfLoss: date, + referralNumber: referralNumber + } + ] + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Assert + expect(wrapper.vm.duplicateOrders.length).toBe(1); + expect(wrapper.vm.duplicateOrders[0]).toStrictEqual({ + Text: duplicateOrderText, + Name: referralNumber, + SubText: `${year} ${make} ${model}, ${date}` + }); + }); + }); + describe('Navigation', () => { test('Back button clicked triggers navigation', () => { // Arrange @@ -148,62 +348,96 @@ describe('duplicateCheck.vue', () => { .toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK, undefined); }); + describe('forwardButtonAction', () => { + test('policyLookupSuccessful true and policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + vehicles: [{test: 'a'}] + } + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; - // TODO finish forward tests - // test('Forward button clicked triggers navigation', () => { - // // Arrange - // const wrapper = shallowMount(contactDetails, getMountOptions({ - // router: { - // navigate: jest.fn() - // } - // })); + const wrapper = shallowMount(duplicateCheck, mountOptions); - // // Act - // wrapper.vm.forwardButtonAction(); + // Act + wrapper.vm.forwardButtonAction(); - // // Assert - // expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); - // expect(wrapper.vm.$router.navigate) - // .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD, undefined); - // }); - // test('Forward button click updates contact info', () => { - // // Arrange - // const mountOptions = getMountOptions({ - // router: { - // navigate: jest.fn() - // }, - // global: { - // plugins: [createTestingPinia()] - // } - // }); - // const wrapper = shallowMount(contactDetails, mountOptions); - // const firstName = getRandomString(4, 15); - // const lastName = getRandomString(4, 15); - // const emailAddress = getRandomString(10, 20); - // const phoneNumber = getRandomInt(1000000000, 9999999999); - // const requestTextUpdates = getRandomBoolean(); - // const notesForTechnician = getRandomString(1, 100); - // wrapper.setData({ - // firstName, - // lastName, - // emailAddress, - // phoneNumber, - // requestTextUpdates, - // notesForTechnician - // }); + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, undefined); + }); + test('policyLookupSuccessful true and no policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: true, + vehicles: [] + } + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; - // // Act - // wrapper.vm.forwardButtonAction(); + const wrapper = shallowMount(duplicateCheck, mountOptions); - // // Assert - // expect(useMainStore().updateContactInfo).toHaveBeenCalledWith({ - // firstName, - // lastName, - // emailAddress, - // phoneNumber, - // requestTextUpdates, - // notesForTechnician - // }); - // }); + // Act + wrapper.vm.forwardButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES, undefined); + }); + test('policyLookupSuccessful false => CLICKED_FORWARD_POLICY_UNVERIFIED', () => { + // Arrange + const mountOptions = getMountOptions({ + router: { navigate: jest.fn() } + }); + + const mainInitialState = { + order: { + policy: { + policyLookupSuccessful: false + } + } + }; + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: mainInitialState + } + })]; + + const wrapper = shallowMount(duplicateCheck, mountOptions); + + // Act + wrapper.vm.forwardButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, undefined); + }); + }); }); }); \ No newline at end of file diff --git a/src/layouts/duplicate-check/duplicate-check.vue b/src/layouts/duplicate-check/duplicate-check.vue index 3ba0f5eb..7f1e0b34 100644 --- a/src/layouts/duplicate-check/duplicate-check.vue +++ b/src/layouts/duplicate-check/duplicate-check.vue @@ -95,7 +95,7 @@ export default { duplicateOrders() { const duplicateOrderText = 'Finish Existing Claim'; const orders = useMainStore().applicationUser.duplicateOrders; - return orders.map(o => { + return orders?.map(o => { const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel ? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}` : null; @@ -108,7 +108,7 @@ export default { Name: o.referralNumber, SubText: subtext }; - }); + }) ?? []; }, answers() { return [...this.duplicateOrders, ...this.answersFromCms]; @@ -118,7 +118,7 @@ export default { /** * @summary Steps to perform when back button clicked. */ - backButtonAction() { + backButtonAction() { this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); }, /** @@ -126,14 +126,11 @@ export default { */ forwardButtonAction() { if (useMainStore().order.policy.policyLookupSuccessful){ - const policyVehicles = useMainStore().order.policy.vehicles; - if (policyVehicles) { + const policyVehicles = useMainStore().order.policy.vehicles ?? []; + if (policyVehicles.length > 0) { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, - this.$route, - {}, - {}, - policyVehicles + this.$route ); } else { this.$router.navigate(