Finishing dupe check tests

This commit is contained in:
brydon1 2023-09-18 14:50:48 -04:00
parent e1e56f618d
commit 71cef90af5
2 changed files with 294 additions and 63 deletions

View file

@ -4,10 +4,11 @@ import duplicateCheck from '@/layouts/duplicate-check/duplicate-check.vue';
// Supporting Files // Supporting Files
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { getMountOptions } from '@/helpers/unit-test-helper.js'; import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { getRandomString, getRandomInt, getRandomBoolean } from '@/helpers/data-generation.js';
import { createTestingPinia } from '@pinia/testing'; import { createTestingPinia } from '@pinia/testing';
import navigationScenarios from '@/router/router-constants/navigation-scenarios.js'; 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('duplicateCheck.vue', () => {
describe('Rendering', () => { 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', () => { describe('Navigation', () => {
test('Back button clicked triggers navigation', () => { test('Back button clicked triggers navigation', () => {
// Arrange // Arrange
@ -148,62 +348,96 @@ describe('duplicateCheck.vue', () => {
.toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK, undefined); .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 const wrapper = shallowMount(duplicateCheck, mountOptions);
// test('Forward button clicked triggers navigation', () => {
// // Arrange
// const wrapper = shallowMount(contactDetails, getMountOptions({
// router: {
// navigate: jest.fn()
// }
// }));
// // Act // Act
// wrapper.vm.forwardButtonAction(); wrapper.vm.forwardButtonAction();
// // Assert // Assert
// expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
// expect(wrapper.vm.$router.navigate) expect(wrapper.vm.$router.navigate)
// .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD, undefined); .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, undefined);
// }); });
// test('Forward button click updates contact info', () => { test('policyLookupSuccessful true and no policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES', () => {
// // Arrange // Arrange
// const mountOptions = getMountOptions({ const mountOptions = getMountOptions({
// router: { router: { navigate: jest.fn() }
// navigate: jest.fn() });
// },
// global: { const mainInitialState = {
// plugins: [createTestingPinia()] order: {
// } policy: {
// }); policyLookupSuccessful: true,
// const wrapper = shallowMount(contactDetails, mountOptions); vehicles: []
// const firstName = getRandomString(4, 15); }
// const lastName = getRandomString(4, 15); }
// const emailAddress = getRandomString(10, 20); };
// const phoneNumber = getRandomInt(1000000000, 9999999999); mountOptions.global.plugins = [createTestingPinia({
// const requestTextUpdates = getRandomBoolean(); initialState: {
// const notesForTechnician = getRandomString(1, 100); main: mainInitialState
// wrapper.setData({ }
// firstName, })];
// lastName,
// emailAddress,
// phoneNumber,
// requestTextUpdates,
// notesForTechnician
// });
// // Act const wrapper = shallowMount(duplicateCheck, mountOptions);
// wrapper.vm.forwardButtonAction();
// // Assert // Act
// expect(useMainStore().updateContactInfo).toHaveBeenCalledWith({ wrapper.vm.forwardButtonAction();
// firstName,
// lastName, // Assert
// emailAddress, expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
// phoneNumber, expect(wrapper.vm.$router.navigate)
// requestTextUpdates, .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES, undefined);
// notesForTechnician });
// }); 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);
});
});
}); });
}); });

View file

@ -95,7 +95,7 @@ export default {
duplicateOrders() { duplicateOrders() {
const duplicateOrderText = 'Finish Existing Claim'; const duplicateOrderText = 'Finish Existing Claim';
const orders = useMainStore().applicationUser.duplicateOrders; const orders = useMainStore().applicationUser.duplicateOrders;
return orders.map(o => { return orders?.map(o => {
const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel
? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}` ? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}`
: null; : null;
@ -108,7 +108,7 @@ export default {
Name: o.referralNumber, Name: o.referralNumber,
SubText: subtext SubText: subtext
}; };
}); }) ?? [];
}, },
answers() { answers() {
return [...this.duplicateOrders, ...this.answersFromCms]; return [...this.duplicateOrders, ...this.answersFromCms];
@ -118,7 +118,7 @@ export default {
/** /**
* @summary Steps to perform when back button clicked. * @summary Steps to perform when back button clicked.
*/ */
backButtonAction() { backButtonAction() {
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
}, },
/** /**
@ -126,14 +126,11 @@ export default {
*/ */
forwardButtonAction() { forwardButtonAction() {
if (useMainStore().order.policy.policyLookupSuccessful){ if (useMainStore().order.policy.policyLookupSuccessful){
const policyVehicles = useMainStore().order.policy.vehicles; const policyVehicles = useMainStore().order.policy.vehicles ?? [];
if (policyVehicles) { if (policyVehicles.length > 0) {
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES,
this.$route, this.$route
{},
{},
policyVehicles
); );
} else { } else {
this.$router.navigate( this.$router.navigate(