diff --git a/src/layouts/policy-holder-details/policy-holder-details.spec.js b/src/layouts/policy-holder-details/policy-holder-details.spec.js index 2f0c9faa..539e2900 100644 --- a/src/layouts/policy-holder-details/policy-holder-details.spec.js +++ b/src/layouts/policy-holder-details/policy-holder-details.spec.js @@ -127,7 +127,7 @@ describe('navigation', () => { expect(wrapper.vm.navigateForward).toHaveBeenCalled(); }); - test('if the coverage policy verified navigate forward to policy-vehicle page', async () => { + test('if the coverage policy verified navigate forward to vehicle damage page', async () => { // Arrange const mockRegistrationAddress = { streetAddress: '1234 Main St', @@ -135,14 +135,6 @@ describe('navigation', () => { state: 'OH', zipCode: '43215' }; - const mockvehicles = [ - { - vin: 'TEST_VIN' - }, - { - vin: 'TEST_VIN2' - } - ]; const { wrapper } = setupMocks(); @@ -152,13 +144,12 @@ describe('navigation', () => { customerQuestions: { addressQuestions: mockRegistrationAddress }, - isCoverageEnabled: true, - vehiclesCount: 2, - vehiclesFound: mockvehicles + isCoverageEnabled: true }); useMainStore().order.policy.policyNumber = 'p_0001'; useMainStore().order.policy.dateOfLoss = '2022-01-28'; + useMainStore().order.vehicle.policyVehicleId = 0; // Act @@ -167,10 +158,111 @@ describe('navigation', () => { // Assert expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED, - undefined, - {}, - {}, - mockvehicles + undefined + ); + }); + + test('if the coverage policy unverified navigate forward to vehicle damage page', async () => { + // Arrange + const mockRegistrationAddress = { + streetAddress: '1234 Main St', + city: 'Columbus', + state: 'OH', + zipCode: '43215' + }; + + const { wrapper } = setupMocks(); + + await wrapper.setData({ + firstName: 'KK', + lastName: 'KK', + customerQuestions: { + addressQuestions: mockRegistrationAddress + }, + isCoverageEnabled: true + }); + + useMainStore().order.policy.policyNumber = 'p_0001'; + useMainStore().order.policy.dateOfLoss = '2022-01-28'; + useMainStore().order.vehicle.policyVehicleId = null; + + // Act + + await wrapper.vm.forwardButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, + undefined + ); + }); + + test('if the coverage policy verified navigate back to welcome page', async () => { + // Arrange + const mockRegistrationAddress = { + streetAddress: '1234 Main St', + city: 'Columbus', + state: 'OH', + zipCode: '43215' + }; + + const { wrapper } = setupMocks(); + + await wrapper.setData({ + firstName: 'KK', + lastName: 'KK', + customerQuestions: { + addressQuestions: mockRegistrationAddress + }, + isCoverageEnabled: true + }); + + useMainStore().order.policy.policyNumber = 'p_0001'; + useMainStore().order.policy.dateOfLoss = '2022-01-28'; + useMainStore().order.vehicle.policyVehicleId = 0; + + // Act + + await wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( + navigationScenarios.CLICKED_BACK_POLICY_VERIFIED, + undefined + ); + }); + test('if the coverage policy unverified navigate back to vehicle-selection page', async () => { + // Arrange + const mockRegistrationAddress = { + streetAddress: '1234 Main St', + city: 'Columbus', + state: 'OH', + zipCode: '43215' + }; + + const { wrapper } = setupMocks(); + + await wrapper.setData({ + firstName: 'KK', + lastName: 'KK', + customerQuestions: { + addressQuestions: mockRegistrationAddress + }, + isCoverageEnabled: true + }); + + useMainStore().order.policy.policyNumber = 'p_0001'; + useMainStore().order.policy.dateOfLoss = '2022-01-28'; + useMainStore().order.vehicle.policyVehicleId = null; + + // Act + + await wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( + navigationScenarios.CLICKED_BACK_POLICY_UNVERIFIED, + undefined ); }); }); diff --git a/src/layouts/policy-holder-details/policy-holder-details.vue b/src/layouts/policy-holder-details/policy-holder-details.vue index ceb07902..08ef0dc7 100644 --- a/src/layouts/policy-holder-details/policy-holder-details.vue +++ b/src/layouts/policy-holder-details/policy-holder-details.vue @@ -78,7 +78,7 @@ cmsWidgetName="SiteFooterWidget" :isForwardActionDisabled="!meta.valid" @ForwardClicked="forwardButtonAction" - @backClicked="navigateBack" /> + @backClicked="backButtonAction" /> @@ -138,7 +138,6 @@ export default { data() { return { customerQuestions: this.getPolicyHolderDetailsFromStore(), - vehiclesFound: [], rules: { firstName: globalRules.POLICYHOLDER_FIRST_NAME_REQUIRED, lastName: globalRules.POLICYHOLDER_LAST_NAME_REQUIRED, @@ -152,8 +151,8 @@ export default { isCoverageEnabled() { return this.mainStore.issConfig.isCoverageEnabled; }, - vehiclesCount() { - return this.vehiclesFound.length; + isPolicyVehicleSelected() { + return (this.mainStore.order.vehicle.policyVehicleId != null && this.mainStore.order.vehicle.policyVehicleId >= 0); } }, methods: { @@ -163,13 +162,10 @@ export default { }, navigateForward() { - if (this.vehiclesCount > 0) { + if (this.isPolicyVehicleSelected) { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED, - this.$route, - {}, - {}, - this.vehiclesFound + this.$route ); } else { this.$router.navigate( @@ -179,6 +175,20 @@ export default { } }, + backButtonAction() { + if (this.isPolicyVehicleSelected) { + this.$router.navigate( + this.navigationScenarios.CLICKED_BACK_POLICY_VERIFIED, + this.$route + ); + } else { + this.$router.navigate( + this.navigationScenarios.CLICKED_BACK_POLICY_UNVERIFIED, + this.$route + ); + } + }, + getPolicyHolderDetailsFromStore() { return { addressQuestions: { diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 4d6cde2a..9e86b8cf 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -27,6 +27,8 @@ const navigationScenarios = Object.freeze({ // Policy Holder Details CLICKED_FORWARD_POLICY_VERIFIED: 'CLICKED_FORWARD_POLICY_VERIFIED', + CLICKED_BACK_POLICY_UNVERIFIED: 'CLICKED_BACK_POLICY_UNVERIFIED', + CLICKED_BACK_POLICY_VERIFIED: 'CLICKED_BACK_POLICY_VERIFIED', // Policy Vehicle CLICKED_FORWARD_LISTED_VEHICLE: 'CLICKED_FORWARD_LISTED_VEHICLE', diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index c2a385ae..c526dc47 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -451,7 +451,11 @@ const routingTable = () => [ issPageValue: issPageValues.POLICY_HOLDER_DETAILS, maps: [ { - scenario: navigationScenarios.CLICKED_BACK, + scenario: navigationScenarios.CLICKED_BACK_POLICY_UNVERIFIED, + destinationIssPageValue: issPageValues.VEHICLE_SELECTION + }, + { + scenario: navigationScenarios.CLICKED_BACK_POLICY_VERIFIED, destinationIssPageValue: issPageValues.WELCOME_PAGE }, {