Add to dup check test

This commit is contained in:
brydon1 2023-09-18 14:09:25 -04:00
parent 44e429a66d
commit cf15cb8b59
2 changed files with 58 additions and 4 deletions

View file

@ -10,6 +10,8 @@ import applicationConfig from '@/constants/application-config';
import { useMainStore } from '@/store';
import navigationScenarios from '@/router/router-constants/navigation-scenarios';
import routerParams from '@/router/router-constants/router-params';
import { getRandomString } from '@/helpers/data-generation.js';
import { createTestingPinia } from '@pinia/testing';
// Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
@ -89,6 +91,40 @@ function setupMocks({
return { wrapper, apiPromise };
}
function getMountedComponent(mainInitialState = {}, initialData = {}) {
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
}
});
mountOptions.global.stubs = {
siteHeader: true,
recalModal: true,
contentGroupModal: true,
alert: true
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
//mountOptions.mixins = [mockMixin];
mountOptions.data = () => (
initialData
);
const apiResponses = {
supportingItems: []
};
const apiPromise = Promise.resolve(apiResponses);
settleAllPromises.mockImplementation(() => apiPromise);
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
const wrapper = shallowMount(welcomePage, mountOptions);
return { wrapper };
}
describe('welcome-page.vue', () => {
test('Should render welcomePage sub-components (policyNumber, policyZipCode, dateOfLoss, damageCause etc.)', async () => {
// Arrange
@ -143,11 +179,24 @@ describe('welcome-page.vue', () => {
describe('navigation', () => {
test('if duplicates found, navigate to duplicate check page', async () => {
// Arrange
const { wrapper } = setupMocks({});
const accountNumber = getRandomString(5, 5);
const policyNumber = getRandomString(5, 5);
const dateOfLoss = getRandomString(5, 5);
const { wrapper } = getMountedComponent({
order: {
policy: {
policyNumber: policyNumber,
dateOfLoss: dateOfLoss
}
},
issConfig: {
accountNumber: accountNumber
}
});
const duplicatesExist = {
policyLookupResponse: {},
duplicateCheckResponse: [{ test2: 'b'}]
duplicateCheckResponse: [{ test: 'a'}]
};
settleAllPromises.mockImplementation(() => Promise.resolve(duplicatesExist));
@ -156,6 +205,12 @@ describe('navigation', () => {
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.mainStore.getDuplicates).toHaveBeenCalledWith(
{
accountNumber: accountNumber,
policyNumber: policyNumber,
dateOfLoss: dateOfLoss
});
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
navigationScenarios.CLICKED_FORWARD_WITH_DUPLICATES,
undefined,

View file

@ -298,9 +298,8 @@ export default {
methods: {
async forwardButtonAction() {
this.mainStore.updatePolicyData(this.welcomePageModel);
const duplicateCheckResponse = useMainStore().getDuplicates({
accountNumber: this.mainStore.order.accountNumber.toString(),
accountNumber: this.mainStore.issConfig.accountNumber.toString(),
policyNumber: this.mainStore.order.policy.policyNumber,
dateOfLoss: this.mainStore.order.policy.dateOfLoss
});