From 509496b59a672dcfa21bac33fe012a8fe038fcd8 Mon Sep 17 00:00:00 2001 From: brydon1 Date: Fri, 15 Sep 2023 11:12:16 -0400 Subject: [PATCH] Adding some dupe check tests --- .../duplicate-check/duplicate-check.spec.js | 209 ++++++++++++++++++ .../duplicate-check/duplicate-check.vue | 3 +- .../router-constants/navigation-scenarios.js | 1 + src/router/router-constants/routing-table.js | 4 + 4 files changed, 216 insertions(+), 1 deletion(-) diff --git a/src/layouts/duplicate-check/duplicate-check.spec.js b/src/layouts/duplicate-check/duplicate-check.spec.js index e69de29b..691e9088 100644 --- a/src/layouts/duplicate-check/duplicate-check.spec.js +++ b/src/layouts/duplicate-check/duplicate-check.spec.js @@ -0,0 +1,209 @@ +// Components +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'; + +describe('duplicateCheck.vue', () => { + describe('Rendering', () => { + test('Should render site header', () => { + // Arrange + const wrapper = shallowMount(duplicateCheck, getMountOptions()); + + // Act + const siteHeader = wrapper.findComponent({ ref: 'siteHeader' }); + + // Assert + expect(siteHeader.exists()).toBeTruthy(); + }); + test('Should render sub title', () => { + // Arrange + const wrapper = shallowMount(duplicateCheck, getMountOptions()); + + // Act + const siteSubHeader = wrapper.findComponent({ ref: 'siteSubHeader' }); + + // Assert + expect(siteSubHeader.exists()).toBeTruthy(); + }); + test('Should render question subcomponent', () => { + // Arrange + const wrapper = shallowMount(duplicateCheck, getMountOptions()); + + // Act + const question = wrapper.findComponent({ ref: 'buttonQuestion' }); + + // Assert + expect(question.exists()).toBeTruthy(); + }); + test('Should render site footer', () => { + // Arrange + const wrapper = shallowMount(duplicateCheck, getMountOptions()); + + // Act + const footer = wrapper.findComponent({ ref: 'siteFooter' }); + + // Assert + expect(footer.exists()).toBeTruthy(); + }); + + // TODO update or remove + // test('Mocked store with no contact info yields expected data', () => { + // // Arrange + // const mountOptions = getMountOptions(); + + // const firstName = getRandomString(4, 15); + // const lastName = getRandomString(4, 15); + // const emailAddress = getRandomString(10, 20); + // const phoneNumber = getRandomInt(1000000000, 9999999999); + // const mainInitialState = { + // order: { + // customer: { + // firstName, + // lastName, + // emailAddress, + // phoneNumber + // } + // } + // }; + // mountOptions.global = { + // plugins: [createTestingPinia({ + // initialState: { + // main: mainInitialState + // } + // })] + // }; + + // const wrapper = shallowMount(contactDetails, mountOptions); + + // // Assert + // expect(wrapper.vm.firstName).toBe(firstName); + // expect(wrapper.vm.lastName).toBe(lastName); + // expect(wrapper.vm.emailAddress).toBe(emailAddress); + // expect(wrapper.vm.phoneNumber).toBe(phoneNumber); + // }); + // test('Mock store with contact info yields expected data', () => { + // // Arrange + // const customer = { + // firstName: getRandomString(4, 15), + // lastName: getRandomString(4, 15), + // emailAddress: getRandomString(10, 20), + // phoneNumber: getRandomInt(1000000000, 9999999999) + // }; + // const contactInfo = { + // firstName: getRandomString(4, 15), + // lastName: getRandomString(4, 15), + // emailAddress: getRandomString(10, 20), + // phoneNumber: getRandomInt(1000000000, 9999999999), + // requestTextUpdates: getRandomBoolean(), + // notesForTechnician: getRandomString(50, 100) + // }; + // const mainInitialState = { + // order: { + // customer, + // contactInfo + // } + // }; + // const mountOptions = getMountOptions(); + // mountOptions.global = { + // plugins: [createTestingPinia({ + // initialState: { + // main: mainInitialState + // } + // })] + // }; + + // const wrapper = shallowMount(contactDetails, mountOptions); + + // // Assert + // expect(wrapper.vm.firstName).toBe(contactInfo.firstName); + // expect(wrapper.vm.lastName).toBe(contactInfo.lastName); + // expect(wrapper.vm.emailAddress).toBe(contactInfo.emailAddress); + // expect(wrapper.vm.phoneNumber).toBe(contactInfo.phoneNumber); + // expect(wrapper.vm.requestTextUpdates).toBe(contactInfo.requestTextUpdates); + // expect(wrapper.vm.notesForTechnician).toBe(contactInfo.notesForTechnician); + // }); + }); + + describe('Navigation', () => { + test('Back button clicked triggers navigation', () => { + // Arrange + const wrapper = shallowMount(duplicateCheck, getMountOptions({ + router: { + navigate: jest.fn() + } + })); + + // Act + wrapper.vm.backButtonAction(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + expect(wrapper.vm.$router.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK, undefined); + }); + + + // TODO finish forward tests + // test('Forward button clicked triggers navigation', () => { + // // Arrange + // const wrapper = shallowMount(contactDetails, getMountOptions({ + // router: { + // navigate: jest.fn() + // } + // })); + + // // 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 + // }); + + // // Act + // wrapper.vm.forwardButtonAction(); + + // // Assert + // expect(useMainStore().updateContactInfo).toHaveBeenCalledWith({ + // firstName, + // lastName, + // emailAddress, + // phoneNumber, + // requestTextUpdates, + // notesForTechnician + // }); + // }); + }); +}); \ 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 b9f357c3..9046d155 100644 --- a/src/layouts/duplicate-check/duplicate-check.vue +++ b/src/layouts/duplicate-check/duplicate-check.vue @@ -18,6 +18,7 @@ :cmsWidgetName="widget.siteSubHeader" /> [ scenario: navigationScenarios.CLICKED_FORWARD, destinationIssPageValue: issPageValues.POLICY_HOLDER_DETAILS }, + { + scenario: navigationScenarios.CLICKED_FORWARD_WITH_DUPLICATES, + destinationIssPageValue: issPageValues.DUPLICATE_CHECK + }, { scenario: navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, destinationIssPageValue: issPageValues.POLICY_HOLDER_DETAILS