1283 lines
48 KiB
JavaScript
1283 lines
48 KiB
JavaScript
// Components
|
|
import coverageStatement from '@/layouts/coverage-statement/coverage-statement.vue';
|
|
|
|
// Supporting Files
|
|
import { nextTick } from 'vue';
|
|
import { shallowMount } from '@vue/test-utils';
|
|
import { getMountOptions } from '@/helpers/unit-test-helper.js';
|
|
import { createTestingPinia } from '@pinia/testing';
|
|
import navigationScenarios from '@/router/router-constants/navigation-scenarios.js';
|
|
import { getRandomString, getRandomInt } from '@/helpers/data-generation.js';
|
|
import settleAllPromises from '@/helpers/layout-helper.js';
|
|
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
|
|
import { useMainStore, getDefaultState } from '@/store';
|
|
import getPriceOfLineItems from '@/helpers/price-calculator.js';
|
|
|
|
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
|
jest.mock('@/helpers/price-calculator.js', () => jest.fn());
|
|
|
|
jest.mock('@/helpers/cms-content-helper', () => ({
|
|
fetchCmsContentForPage: jest.fn(),
|
|
setupModalLinks: jest.fn(),
|
|
processIfStatements: jest.fn()
|
|
}));
|
|
|
|
const SAFELITE_PROVIDER = 'Safelite';
|
|
|
|
const mockMixin = {
|
|
methods: {
|
|
getCmsContent: jest.fn().mockImplementation(() => ''),
|
|
setCmsContent: jest.fn(),
|
|
onSubmit: jest.fn(),
|
|
onInvalidSubmit: jest.fn(),
|
|
navigateBackByVehicleQuestions: jest.fn()
|
|
}
|
|
};
|
|
|
|
const footerStub = {
|
|
render: () => {},
|
|
methods: {
|
|
updateButtonText: jest.fn()
|
|
}
|
|
};
|
|
|
|
const loadingModalStub = {
|
|
render: () => {},
|
|
methods: {
|
|
showModal: jest.fn(),
|
|
hideModal: jest.fn()
|
|
}
|
|
};
|
|
|
|
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) {
|
|
const mountOptions = getMountOptions({
|
|
router: {
|
|
navigate: jest.fn()
|
|
}
|
|
});
|
|
|
|
mountOptions.global.stubs = {
|
|
...mountOptions.global.stubs,
|
|
siteFooter: footerStub,
|
|
siteHeader: true,
|
|
recalModal: true,
|
|
contentGroupModal: true,
|
|
alert: true,
|
|
loadingModal: loadingModalStub
|
|
};
|
|
const testingPinia = createTestingPinia({
|
|
initialState: {
|
|
main: mainInitialState
|
|
}
|
|
});
|
|
useMainStore(testingPinia);
|
|
methodToRun();
|
|
|
|
mountOptions.global.plugins = [testingPinia];
|
|
mountOptions.mixins = [mockMixin];
|
|
mountOptions.data = () => (
|
|
initialData
|
|
);
|
|
|
|
const apiResponses = {
|
|
supportingItems: []
|
|
};
|
|
const apiPromise = Promise.resolve(apiResponses);
|
|
settleAllPromises.mockImplementation(() => apiPromise);
|
|
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
|
|
|
const wrapper = shallowMount(coverageStatement, mountOptions);
|
|
return { wrapper };
|
|
}
|
|
|
|
beforeEach(() => {
|
|
const store = useMainStore();
|
|
const defaultState = getDefaultState();
|
|
Object.keys(defaultState).forEach((key) => {
|
|
store[key] = defaultState[key];
|
|
});
|
|
});
|
|
|
|
describe('coverageStatement.vue-working', () => {
|
|
test('returns the initial data', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$data).toMatchSnapshot();
|
|
});
|
|
describe('Rendering', () => {
|
|
test('Should render site header', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent({});
|
|
|
|
// Act
|
|
const siteHeader = wrapper.findComponent({ ref: 'siteHeader' });
|
|
|
|
// Assert
|
|
expect(siteHeader.exists()).toBe(true);
|
|
});
|
|
test('Should render site subheader', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent({});
|
|
|
|
// Act
|
|
const subheader = wrapper.find({ ref: 'siteSubHeader' });
|
|
|
|
// Assert
|
|
expect(subheader.exists()).toBe(true);
|
|
});
|
|
|
|
test('Should render explanatory text', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent({});
|
|
|
|
// Act
|
|
const explanatoryText = wrapper.find({ ref: 'explanatoryText' });
|
|
|
|
// Assert
|
|
expect(explanatoryText.exists()).toBe(true);
|
|
});
|
|
test('Should render secondary text', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent({});
|
|
|
|
// Act
|
|
const secondaryText = wrapper.find({ ref: 'secondaryText' });
|
|
|
|
// Assert
|
|
expect(secondaryText.exists()).toBe(true);
|
|
});
|
|
test('Should render site footer', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent({});
|
|
|
|
// Act
|
|
const footer = wrapper.findComponent({ ref: 'siteFooter' });
|
|
|
|
// Assert
|
|
expect(footer.exists()).toBe(true);
|
|
});
|
|
});
|
|
describe('Computed', () => {
|
|
describe('verifiedNoComp', () => {
|
|
describe('isNoCompQuoteVisible true', () => {
|
|
const enableNoCompQuote = true;
|
|
test.each([true, false])('returns false when policyLookupSuccessful false', (isNoComp) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: isNoComp,
|
|
policyLookupSuccessful: false
|
|
}
|
|
},
|
|
issConfig: { enableNoCompQuote }
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isNoCompQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test.each([true, false])('returns false when isNoComp false', (policyLookupSuccessful) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful
|
|
}
|
|
},
|
|
issConfig: { enableNoCompQuote }
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isNoCompQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when policyLookupSuccessful true, noCoverage true, and enableNoCompQuote true', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: true,
|
|
policyLookupSuccessful: true
|
|
}
|
|
},
|
|
issConfig: { enableNoCompQuote }
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isNoCompQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
test('returns false when policyLookupSuccessful true, noCoverage true and enableNoCompQuote false', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: true,
|
|
policyLookupSuccessful: true
|
|
}
|
|
},
|
|
issConfig: {
|
|
enableNoCompQuote: false
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isNoCompQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
});
|
|
describe('isITACQuoteVisible', () => {
|
|
const priceOfLineItems = 213;
|
|
test.each([true, false])('returns false when policyLookupSuccessful false', (isNoComp) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: isNoComp,
|
|
policyLookupSuccessful: false
|
|
},
|
|
currentDeductible: priceOfLineItems + 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isITACQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test.each([true, false])('returns false when isNoComp true', (policyLookupSuccessful) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: true,
|
|
policyLookupSuccessful
|
|
},
|
|
currentDeductible: priceOfLineItems + 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isITACQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test.each([
|
|
[true, false],
|
|
[true, true],
|
|
[false, false],
|
|
[false, true]
|
|
])('returns false when deductibleValue equals totalServicePrice', (noCoverage, policyLookupSuccessful) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage,
|
|
policyLookupSuccessful
|
|
},
|
|
currentDeductible: priceOfLineItems
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isITACQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test.each([
|
|
[true, false],
|
|
[true, true],
|
|
[false, false],
|
|
[false, true]
|
|
])(
|
|
'returns false when deductibleValue less than totalServicePrice when noCoverage is %p and policyLookupSuccessful is %p',
|
|
(noCoverage, policyLookupSuccessful) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage,
|
|
policyLookupSuccessful
|
|
},
|
|
currentDeductible: priceOfLineItems - 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isITACQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
}
|
|
);
|
|
test('returns true when deductibleValue more than totalServicePrice, noComp is false, and policyLookupSuccessful true', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: priceOfLineItems + 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isITACQuoteVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
describe('isDeductibleVisible', () => {
|
|
const servicePrice = 123;
|
|
describe('claim registration required', () => {
|
|
const issConfig = { isClaimRegistrationRequired: true };
|
|
let verifiedDeductibleStoreState;
|
|
beforeEach(() => {
|
|
verifiedDeductibleStoreState = {
|
|
issConfig,
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: true
|
|
}
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: servicePrice - 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementation(() => servicePrice);
|
|
});
|
|
test('returns false when deductible is null', () => {
|
|
// Arrange
|
|
const mainInitialState = verifiedDeductibleStoreState;
|
|
mainInitialState.order.currentDeductible = null;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when register claim not successful', () => {
|
|
// Arrange
|
|
const mainInitialState = verifiedDeductibleStoreState;
|
|
mainInitialState.order.payment.insuranceCoverage.isVerified = false;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when register claim successful, isNoComp false, and service price over deductible', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent(verifiedDeductibleStoreState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
describe('claim registration not required', () => {
|
|
const issConfig = { isClaimRegistrationRequired: false };
|
|
let verifiedDeductibleStoreState;
|
|
beforeEach(() => {
|
|
verifiedDeductibleStoreState = {
|
|
issConfig,
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: false
|
|
}
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: servicePrice - 1
|
|
}
|
|
};
|
|
});
|
|
test('returns false when policy lookup not successful', () => {
|
|
// Arrange
|
|
const mainInitialState = verifiedDeductibleStoreState;
|
|
mainInitialState.order.policy.policyLookupSuccessful = false;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when policyLookupSuccessful, isNoComp false, and deductible over service price', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent(verifiedDeductibleStoreState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
test('returns false when isNoComp true', () => {
|
|
// Arrange
|
|
const isNoComp = true;
|
|
const storeState = {
|
|
issConfig: {
|
|
isClaimRegistrationRequired: false
|
|
},
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: true
|
|
}
|
|
},
|
|
policy: {
|
|
noCoverage: isNoComp,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: servicePrice - 1
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(storeState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when service price below deductible', () => {
|
|
// Arrange
|
|
const storeState = {
|
|
issConfig: {
|
|
isClaimRegistrationRequired: false
|
|
},
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: true
|
|
}
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: servicePrice + 1
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(storeState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isDeductibleVisible;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
});
|
|
describe('isADAS', () => {
|
|
test('returns false when glassParts null', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: null
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isADAS;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when glassParts empty', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: []
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isADAS;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when no parts in glassParts require recalibration', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: [
|
|
{
|
|
partNumber: 123,
|
|
requiresRecalibration: false
|
|
},
|
|
{
|
|
partNumber: 111,
|
|
requiresRecalibration: false
|
|
}
|
|
]
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isADAS;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when a part in glassParts require recalibration', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: [
|
|
{
|
|
partNumber: 123,
|
|
requiresRecalibration: true
|
|
},
|
|
{
|
|
partNumber: 111,
|
|
requiresRecalibration: false
|
|
}
|
|
]
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isADAS;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
describe('isQuoteDisplayed', () => {
|
|
test('returns false when policy lookup not successful', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: false
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
describe('not no comp', () => {
|
|
const priceOfLineItems = 341;
|
|
test('returns false when deductible equal to service price', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false
|
|
},
|
|
currentDeductible: priceOfLineItems
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when deductible less than service price', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false
|
|
},
|
|
currentDeductible: priceOfLineItems - 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when policy lookup successful and deductible over service price', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false
|
|
},
|
|
currentDeductible: priceOfLineItems + 1
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
describe('not itac', () => {
|
|
const priceOfLineItems = 23;
|
|
test('returns false when isNoComp false', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false
|
|
},
|
|
currentDeductible: priceOfLineItems
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when isNoComp true and enableNoCompQuote false', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: true
|
|
},
|
|
currentDeductible: priceOfLineItems
|
|
},
|
|
issConfig: {
|
|
enableNoCompQuote: false
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns true when isNoComp true and enableNoCompQuote true', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: true
|
|
},
|
|
currentDeductible: priceOfLineItems
|
|
},
|
|
issConfig: {
|
|
enableNoCompQuote: true
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementationOnce(() => priceOfLineItems);
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.isQuoteDisplayed;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
});
|
|
describe.each([[0], [12]])('shouldRegisterClaim', (policyVehicleId) => {
|
|
const servicePrice = 90;
|
|
let shouldRegisterClaimStoreStateItac;
|
|
beforeEach(() => {
|
|
shouldRegisterClaimStoreStateItac = {
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
claimNumber: null,
|
|
isVerified: true // Added
|
|
}
|
|
},
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false
|
|
},
|
|
vehicle: {
|
|
policyVehicleId
|
|
},
|
|
currentDeductible: servicePrice - 1
|
|
},
|
|
issConfig: {
|
|
isClaimRegistrationRequired: true,
|
|
enableNoCompQuote: true
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementation(() => servicePrice);
|
|
});
|
|
test('returns false when policy lookup not successful', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.order.policy.policyLookupSuccessful = false;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when policy vehicle id is less than 0', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.order.vehicle.policyVehicleId = -3;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when policy vehicle id is null', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.order.vehicle.policyVehicleId = null;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when claim registration is not required', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.issConfig.isClaimRegistrationRequired = false;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when claim already registered', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.order.payment.insuranceCoverage.claimNumber = 13;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when no comp', () => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.order.policy.noCoverage = true;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false when insuranceCoverage not verified', () => {});
|
|
describe('returns true when policy lookup success, vehicleId set to %p, claim reg req, claim not yet reg', () => {
|
|
test('and itac', () => {
|
|
// Arrange
|
|
const { wrapper } = getMountedComponent(shouldRegisterClaimStoreStateItac);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
test.each([
|
|
[servicePrice],
|
|
[servicePrice + 1]
|
|
])('and deductible case', (deductibleValue) => {
|
|
// Arrange
|
|
const mainInitialState = shouldRegisterClaimStoreStateItac;
|
|
mainInitialState.currentDeductible = deductibleValue;
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.shouldRegisterClaim;
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('methods', () => {
|
|
describe('arePagePrerequisitesValid', () => {
|
|
test('returns false if car id not set', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
vehicle: {
|
|
carId: null
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test('returns false if car id set to 0', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
vehicle: {
|
|
carId: 0
|
|
}
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
// Assert
|
|
expect(result).toBeFalsy();
|
|
});
|
|
test.each([[-1], [1], [123]])('returns true if car id set to %p', (carId) => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
vehicle: { carId }
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
// Assert
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
describe('navigateForward', () => {
|
|
const servicePrice = 82;
|
|
beforeEach(() => {
|
|
getPriceOfLineItems.mockImplementation(() => servicePrice);
|
|
});
|
|
test('If Unverified, navigate forward with CLICKED_FORWARD scenario', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
policyLookupSuccessful: false
|
|
},
|
|
currentDeductible: null
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD,
|
|
undefined
|
|
);
|
|
});
|
|
test('If Verified Deductible, navigate forward with CLICKED_FORWARD scenario', () => {
|
|
// Arrange
|
|
const deductible = servicePrice - 1;
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: deductible
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD,
|
|
undefined
|
|
);
|
|
});
|
|
test('If Verified ITAC and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => {
|
|
// Arrange
|
|
const deductible = servicePrice + 1;
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: deductible
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
wrapper.setData({
|
|
selectedProvider: SAFELITE_PROVIDER
|
|
});
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
|
|
undefined
|
|
);
|
|
});
|
|
test('If Verified ITAC, selected other shop, navigate forward w/ CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP', () => {
|
|
// Arrange
|
|
const deductible = servicePrice + 1;
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
currentDeductible: deductible
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
wrapper.setData({
|
|
selectedProvider: 'Other'
|
|
});
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
|
|
undefined
|
|
);
|
|
});
|
|
test('If No Comp and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: true,
|
|
policyLookupSuccessful: true
|
|
}
|
|
},
|
|
issConfig: {
|
|
enableNoCompQuote: true
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
wrapper.setData({
|
|
selectedProvider: SAFELITE_PROVIDER
|
|
});
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE,
|
|
undefined
|
|
);
|
|
});
|
|
test('If No comp and selected other shop, navigate forward with CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP ', () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
damage: {
|
|
isRepair: true
|
|
},
|
|
policy: {
|
|
noCoverage: true,
|
|
policyLookupSuccessful: true
|
|
}
|
|
},
|
|
issConfig: {
|
|
enableNoCompQuote: true
|
|
}
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState);
|
|
wrapper.setData({
|
|
selectedProvider: 'other'
|
|
});
|
|
|
|
// Act
|
|
wrapper.vm.navigateForward();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate)
|
|
.toHaveBeenCalledWith(
|
|
navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
|
|
undefined
|
|
);
|
|
});
|
|
});
|
|
});
|
|
describe('ITAC flag', () => {
|
|
test('ITAC flag updated once component is initialized', async () => {
|
|
// Arrange
|
|
const mainInitialState = {
|
|
order: {
|
|
policy: {
|
|
isITAC: null
|
|
}
|
|
}
|
|
};
|
|
const mockStoreActions = () => {
|
|
useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve([]));
|
|
};
|
|
const { wrapper } = getMountedComponent(mainInitialState, {}, mockStoreActions);
|
|
|
|
// Act
|
|
wrapper.vm.initializeComponent();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mainStore.updatePolicyITACFlag)
|
|
.toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('Loaded duplicate with previously registered claim => claim registration is not called', async () => {
|
|
// Arrange
|
|
const sellingPrice = getRandomInt(50, 100);
|
|
const deductible = sellingPrice - 1;
|
|
const initialStore = {
|
|
order: {
|
|
policy: {
|
|
policyLookupSuccessful: true,
|
|
noCoverage: false,
|
|
deductible: {
|
|
repair: deductible
|
|
}
|
|
},
|
|
damage: {
|
|
isRepair: false
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {
|
|
claimNumber: getRandomString(10, 10)
|
|
}
|
|
}
|
|
},
|
|
issConfig: {
|
|
isClaimRegistrationRequired: true
|
|
}
|
|
};
|
|
const mockStoreActions = () => {
|
|
useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve([
|
|
{
|
|
sellingPrice,
|
|
kitPrice: 0,
|
|
laborAmount: 0
|
|
}
|
|
]));
|
|
};
|
|
const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);
|
|
const next = (method) => { method(wrapper.vm); };
|
|
|
|
// Act
|
|
coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next);
|
|
for (let i = 0; i < 7; i++) {
|
|
// eslint-disable-next-line no-await-in-loop
|
|
await nextTick();
|
|
}
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mainStore.registerClaim).toHaveBeenCalledTimes(0);
|
|
});
|
|
});
|
|
describe('claim registration api call', () => {
|
|
it('claim registration not required => method not called', async () => {
|
|
// Arrange
|
|
const mockStoreActions = () => {
|
|
useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve());
|
|
};
|
|
const { wrapper } = getMountedComponent({
|
|
issConfig: {
|
|
isClaimRegistrationRequired: false
|
|
}
|
|
}, {}, mockStoreActions);
|
|
const next = (method) => { method(wrapper.vm); };
|
|
|
|
// Act
|
|
coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next);
|
|
for (let i = 0; i < 7; i++) {
|
|
// eslint-disable-next-line no-await-in-loop
|
|
await nextTick();
|
|
}
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mainStore.registerClaim).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('claim registration required => register claim method called', async () => {
|
|
// Arrange
|
|
const servicePrice = 7283;
|
|
const deductible = servicePrice - 1;
|
|
const initialStore = {
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {
|
|
claimNumber: null,
|
|
isVerified: true
|
|
}
|
|
},
|
|
policy: {
|
|
noCoverage: false,
|
|
isITAC: false,
|
|
policyLookupSuccessful: true
|
|
},
|
|
vehicle: {
|
|
policyVehicleId: 1
|
|
},
|
|
currentDeductible: deductible
|
|
},
|
|
issConfig: {
|
|
isClaimRegistrationRequired: true
|
|
}
|
|
};
|
|
getPriceOfLineItems.mockImplementation(() => servicePrice);
|
|
const mockStoreActions = () => {
|
|
useMainStore().getWipers = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getRainDefense = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getSupportingItems = jest.fn().mockImplementation(() => Promise.resolve());
|
|
useMainStore().getPriceOrderItems = jest.fn().mockImplementation(() => Promise.resolve());
|
|
};
|
|
const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);
|
|
const next = (method) => { method(wrapper.vm); };
|
|
|
|
console.log(wrapper.vm.pageVariation);
|
|
|
|
// Act
|
|
coverageStatement.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next);
|
|
for (let i = 0; i < 7; i++) {
|
|
// eslint-disable-next-line no-await-in-loop
|
|
await nextTick();
|
|
}
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mainStore.registerClaim).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|