INSR-8455: Add some tests, fix others
This commit is contained in:
parent
916f56a50e
commit
d3f0598bc5
3 changed files with 128 additions and 13 deletions
|
|
@ -5,6 +5,7 @@ import routerParams from '@/router/router-constants/router-params';
|
||||||
import { useMainStore } from '@/store';
|
import { useMainStore } from '@/store';
|
||||||
import vehicleCategories from '@/constants/vehicle-categories';
|
import vehicleCategories from '@/constants/vehicle-categories';
|
||||||
import VehicleDamageComponent from '@/layouts/vehicle-damage/vehicle-damage.vue';
|
import VehicleDamageComponent from '@/layouts/vehicle-damage/vehicle-damage.vue';
|
||||||
|
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
|
||||||
|
|
||||||
const mockRoute = {
|
const mockRoute = {
|
||||||
params: {}
|
params: {}
|
||||||
|
|
@ -12,6 +13,16 @@ const mockRoute = {
|
||||||
const mockRouter = {
|
const mockRouter = {
|
||||||
navigate: jest.fn()
|
navigate: jest.fn()
|
||||||
};
|
};
|
||||||
|
jest.mock('@/mixins/vehicle-questions-mixin', () => ({
|
||||||
|
methods: {
|
||||||
|
navigateForward: jest.fn(),
|
||||||
|
getPartsOrQuestions: jest.fn(() => Promise.resolve({
|
||||||
|
data: {
|
||||||
|
partsOrQuestions: []
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}));
|
||||||
const mountOptions = {
|
const mountOptions = {
|
||||||
global: {
|
global: {
|
||||||
mixins: [
|
mixins: [
|
||||||
|
|
@ -91,6 +102,43 @@ describe('vehicle-damage.vue', () => {
|
||||||
expect(mockRouter.navigate)
|
expect(mockRouter.navigate)
|
||||||
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_REPAIR, mockRoute);
|
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_REPAIR, mockRoute);
|
||||||
});
|
});
|
||||||
|
test('When damage selected is a replace but not windshield, navigate forward from vehicle-questions-mixin', async () => {
|
||||||
|
mountOptions.global.plugins = [createTestingPinia({
|
||||||
|
initialState: {
|
||||||
|
main: {
|
||||||
|
order: {
|
||||||
|
damage: {
|
||||||
|
isRepair: false,
|
||||||
|
glassToReplace: [{ glassLocation: 'Rear', glassName: 'Stationary' }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})];
|
||||||
|
const wrapper = mount(VehicleDamageComponent, mountOptions);
|
||||||
|
const siteFooterWrapper = wrapper.getComponent({ ref: 'siteFooter' });
|
||||||
|
|
||||||
|
useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
|
data: { data: [
|
||||||
|
{
|
||||||
|
description: null,
|
||||||
|
partNumber: 'SUPPLIES-REPAIR',
|
||||||
|
partType: 'REPAIR FEE'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: null,
|
||||||
|
partNumber: 'WSREPAIR',
|
||||||
|
partType: 'REPAIR FEE'
|
||||||
|
}
|
||||||
|
] }
|
||||||
|
}));
|
||||||
|
|
||||||
|
siteFooterWrapper.vm.$emit('forwardClicked');
|
||||||
|
|
||||||
|
await flushPromises();
|
||||||
|
expect(vehicleQuestionsMixin.methods.getPartsOrQuestions).toHaveBeenCalledTimes(1);
|
||||||
|
expect(vehicleQuestionsMixin.methods.navigateForward).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
test('Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', async () => {
|
test('Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', async () => {
|
||||||
mountOptions.global.plugins = [createTestingPinia({
|
mountOptions.global.plugins = [createTestingPinia({
|
||||||
initialState: {
|
initialState: {
|
||||||
|
|
@ -115,7 +163,7 @@ describe('vehicle-damage.vue', () => {
|
||||||
const partsQuestionsErrorResponse = {
|
const partsQuestionsErrorResponse = {
|
||||||
error: 'Error getting parts'
|
error: 'Error getting parts'
|
||||||
};
|
};
|
||||||
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => (
|
vehicleQuestionsMixin.methods.getPartsOrQuestions.mockImplementation(() => (
|
||||||
partsQuestionsErrorResponse
|
partsQuestionsErrorResponse
|
||||||
));
|
));
|
||||||
siteFooterWrapper.vm.$emit('forwardClicked');
|
siteFooterWrapper.vm.$emit('forwardClicked');
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,7 @@ describe('vehicle-parts.vue', () => {
|
||||||
|
|
||||||
test('User had part questions > navigateBack triggers a router.navigateWithoutSaving change with correct scenario', async () => {
|
test('User had part questions > navigateBack triggers a router.navigateWithoutSaving change with correct scenario', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
useMainStore().damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }, { glassLocation: 'Windshield', glassName: 'Single' }];
|
||||||
const { wrapper } = setupMocks({
|
const { wrapper } = setupMocks({
|
||||||
mountOptionsMockData: {
|
mountOptionsMockData: {
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -244,6 +245,7 @@ describe('vehicle-parts.vue', () => {
|
||||||
|
|
||||||
test('User did not have part questions > navigateBack triggers a router.navigate change with correct scenario', async () => {
|
test('User did not have part questions > navigateBack triggers a router.navigate change with correct scenario', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
useMainStore().damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }, { glassLocation: 'Windshield', glassName: 'Single' }];
|
||||||
const { wrapper } = setupMocks({
|
const { wrapper } = setupMocks({
|
||||||
mountOptionsMockData: {
|
mountOptionsMockData: {
|
||||||
router: {
|
router: {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils';
|
||||||
import { setupMocksForJsFiles, getMountOptions } from '@/helpers/unit-test-helper.js';
|
import { setupMocksForJsFiles, getMountOptions } from '@/helpers/unit-test-helper.js';
|
||||||
import issPageValues from '@/router/router-constants/issPage-values';
|
import issPageValues from '@/router/router-constants/issPage-values';
|
||||||
import navigationScenarios from '@/router/router-constants/navigation-scenarios';
|
import navigationScenarios from '@/router/router-constants/navigation-scenarios';
|
||||||
import { useMainStore } from '@/store';
|
import { useMainStore, getDefaultState } from '@/store';
|
||||||
|
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
function setupMocks({ issPage = issPageValues.VIN_LOOKUP }) {
|
function setupMocks({ issPage = issPageValues.VIN_LOOKUP }) {
|
||||||
|
|
@ -53,6 +53,7 @@ function setupMocks({ issPage = issPageValues.VIN_LOOKUP }) {
|
||||||
describe('vehicle-questions-mixin', () => {
|
describe('vehicle-questions-mixin', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
useMainStore().order = getDefaultState().order;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hasPartQuestions', () => {
|
describe('hasPartQuestions', () => {
|
||||||
|
|
@ -2181,19 +2182,83 @@ describe('vehicle-questions-mixin', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('navigateBackByVehicleQuestions', () => {
|
describe('navigateBackByVehicleQuestions', () => {
|
||||||
test('current page is coverage-statement and damage is repair => go to vehicle-damage', () => {
|
describe('current page is coverage-statement', () => {
|
||||||
// Arrange
|
test('damage is repair => go to vehicle-damage', () => {
|
||||||
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
// Arrange
|
||||||
useMainStore().order.damage.isRepair = true;
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
||||||
|
useMainStore().order.damage.isRepair = true;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.navigateBackByVehicleQuestions();
|
wrapper.vm.navigateBackByVehicleQuestions();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
||||||
navigationScenarios.CLICKED_BACK_WITH_REPAIR,
|
navigationScenarios.CLICKED_BACK_WITH_REPAIR,
|
||||||
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
test('damage is replace but not windshield => go to vehicle-damage', () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
||||||
|
useMainStore().order.damage.isRepair = false;
|
||||||
|
useMainStore().order.damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateBackByVehicleQuestions();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_BACK_WITH_SKIP_VIN_AND_NO_MORE_QUESTIONS,
|
||||||
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('damage is replace and includes windshield, we have vin => go to vehicle-damage', () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
||||||
|
useMainStore().order.damage.isRepair = false;
|
||||||
|
useMainStore().order.damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }, { glassLocation: 'Windshield', glassName: 'Single' }];
|
||||||
|
useMainStore().order.vehicle.vin = '5NMS3CADXLH233004';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateBackByVehicleQuestions();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_BACK_WITH_VIN_AND_NO_MORE_QUESTIONS,
|
||||||
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('damage is replace and includes windshield => go to vehicle-lookup', () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
||||||
|
useMainStore().order.damage.isRepair = false;
|
||||||
|
useMainStore().order.damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }, { glassLocation: 'Windshield', glassName: 'Single' }];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateBackByVehicleQuestions();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_BACK_WITH_NO_VIN_NOR_QUESTIONS,
|
||||||
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('damage is replace and includes windshield but there are parts to choose => go to vehicle-parts', () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
||||||
|
useMainStore().order.damage.isRepair = false;
|
||||||
|
useMainStore().order.damage.glassToReplace = [{ glassLocation: 'Rear', glassName: 'Stationary' }, { glassLocation: 'Windshield', glassName: 'Single' }];
|
||||||
|
wrapper.vm.hasGlassLocationWithMultipleParts = jest.fn().mockReturnValue(true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateBackByVehicleQuestions();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_BACK_WITH_MULTIPLE_PARTS_TO_CHOOSE,
|
||||||
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } }
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue