navigation unit tests

This commit is contained in:
Katie Kroell 2023-07-26 15:48:22 -04:00
parent 187cf5243c
commit 022a879adb

View file

@ -7,11 +7,7 @@ import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { createTestingPinia } from '@pinia/testing';
import { navigationScenarios } from '@/router/router-constants/navigation-scenarios.js';
import { useMainStore } from '@/store/index.js';
import { settleAllPromises } from '@/helpers/layout-helper';
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
import { render } from '@testing-library/vue';
import { getRandomString, getRandomInt, getRandomBoolean } from '@/helpers/data-generation.js';
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
import { getRandomString, getRandomInt } from '@/helpers/data-generation.js';
// Mock fetchCmsContentForPage
// jest.mock('@/helpers/cms-content-helper', () => ({
@ -62,6 +58,36 @@ describe('coverageStatement.vue', () => {
// Assert
expect(siteHeader.exists()).toBe(true);
}),
test('Should render site subheader', () => {
// Arrange
const { wrapper } = setupMocks({});
// Act
const subheader = wrapper.find({ ref: 'siteSubHeader' });
// Assert
expect(subheader.exists()).toBe(true);
});
test('Should render explanatory text', () => {
// Arrange
const { wrapper } = setupMocks({});
// Act
const explanatoryText = wrapper.find({ ref: 'explanatoryText' });
// Assert
expect(explanatoryText.exists()).toBe(true);
});
test('Should render secondary text', () => {
// Arrange
const { wrapper } = setupMocks({});
// Act
const secondaryText = wrapper.find({ ref: 'secondaryText' });
// Assert
expect(secondaryText.exists()).toBe(true);
});
test('Should render site footer', () => {
// Arrange
const { wrapper } = setupMocks({});
@ -76,7 +102,12 @@ describe('coverageStatement.vue', () => {
describe('Verified ITAC scenario', () => {
test('If coverage verified, not No Comp, and deductible > service price, verifiedITAC returns true', () => {
// Arrange
const mountOptions = getMountOptions();
const mountOptions = getMountOptions({
methods: {
getCmsContent: jest.fn().mockImplementation(() => ''),
setCmsContent: jest.fn(),
},
});
const sellingPrice = getRandomInt(100, 500);
const deductible = sellingPrice + 1;
const mainInitialState = {
@ -480,37 +511,212 @@ describe('coverageStatement.vue', () => {
});
});
describe('Navigation', () => {
test('Back button clicked triggers navigation', () => {
test('If Unverified, navigate forward with CLICKED_FORWARD scenario', () => {
// Arrange
const mountOptions = getMountOptions();
const mainInitialState = {
order: {
damage: {
isRepair: true
},
}
};
mountOptions.global = {
plugins: [createTestingPinia({
initialState: {
main: mainInitialState
}
})]
}
// Act
const wrapper = shallowMount(coverageStatement, getMountOptions({
router: {
navigate: jest.fn()
},
route: {
query: {
issPage: 'coverage-statement'
}
}
}));
wrapper.setData({
isVerified: false,
})
// Act
wrapper.vm.navigateBack();
wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
//expect(wrapper.vm.$router.navigate)
//.toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK, undefined);
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD, undefined);
});
test('If Verified Deductible, navigate forward with CLICKED_FORWARD scenario', () => {
// Arrange
const mountOptions = getMountOptions();
const sellingPrice = getRandomInt(100, 500);
const deductible = sellingPrice - 1;
const mainInitialState = {
order: {
damage: {
isRepair: true
},
policy: {
noCoverage: false,
deductible: {
repair: deductible,
}
}
}
};
mountOptions.global = {
plugins: [createTestingPinia({
initialState: {
main: mainInitialState
}
})]
}
const wrapper = shallowMount(coverageStatement, getMountOptions({
router: {
navigate: jest.fn()
},
}));
wrapper.setData({
isVerified: true,
availableLineItems: [
{
sellingPrice: sellingPrice,
kitPrice: 0,
laborAmount: 0,
}
]
});
// Act
wrapper.vm.forwardButtonAction();
// Assert
//expect(wrapper.vm.verifiedDeductible).toBeTruthy();
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD, undefined);
});
test.only('If Verified ITAC and selected Safelite, navigate forward with CLICKED_FORWARD_WITH_SAFELITE scenario', () => {
// Arrange
const mountOptions = getMountOptions();
const sellingPrice = getRandomInt(100, 500);
const deductible = sellingPrice + 1;
const mainInitialState = {
order: {
damage: {
isRepair: true
},
policy: {
noCoverage: false,
deductible: {
repair: deductible,
}
}
},
};
mountOptions.global = {
plugins: [createTestingPinia({
initialState: {
main: mainInitialState
}
})]
}
const wrapper = shallowMount(coverageStatement, getMountOptions({
router: {
navigate: jest.fn()
},
}));
wrapper.setData({
isVerified: true,
availableLineItems: [
{
sellingPrice: sellingPrice,
kitPrice: 0,
laborAmount: 0,
}
],
selectedProvider: 'Safelite'
});
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
useMainStore().order.policy.noCoverage = false;
// Act
wrapper.vm.forwardButtonAction();
// Assert
console.log(wrapper.vm.coverageVerified);
console.log(wrapper.vm.verifiedNoComp);
console.log(wrapper.vm.vehicleDeductible);
console.log(sellingPrice);
console.log(wrapper.vm.verifiedITAC);
//expect(wrapper.vm.verifiedITAC).toBeTruthy();
// expect(wrapper.vm.$router.navigate)
// .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, undefined);
});
test('If Verified ITAC, selected other shop, and TPA enabled, navigate forward with CLICKED_FORWARD_WITH_TPA_ENABLED scenario', () => {
// Arrange
const mountOptions = getMountOptions();
const sellingPrice = getRandomInt(100, 500);
const deductible = sellingPrice + 100;
const mainInitialState = {
order: {
damage: {
isRepair: true
},
policy: {
noCoverage: false,
deductible: {
repair: deductible,
}
}
},
issConfig: {
enableTPAFlow: true
}
};
mountOptions.global = {
plugins: [createTestingPinia({
initialState: {
main: mainInitialState
}
})]
}
const wrapper = shallowMount(coverageStatement, getMountOptions({
router: {
navigate: jest.fn()
},
}));
wrapper.setData({
isVerified: true,
availableLineItems: [
{
sellingPrice: sellingPrice,
kitPrice: 0,
laborAmount: 0,
}
],
selectedProvider: 'Other'
});
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
// Act
wrapper.vm.forwardButtonAction();
// Assert
//expect(wrapper.vm.verifiedITAC).toBeTruthy();
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE, undefined);
});
//test('If Unverified scenario, forwardButtonAction triggers ')
});
})
//const testWidget = getRandomString(50, 100);
const mockMixin = {
methods: {
getCmsContent: jest.fn().mockImplementation(() => ''),
setCmsContent: jest.fn(),
navigateBack: jest.fn()
},
};