Add more tests

This commit is contained in:
Katie 2022-09-13 13:13:07 -04:00
parent f51135b030
commit 8e8f663be3
7 changed files with 178 additions and 47 deletions

View file

@ -25,8 +25,7 @@ module.exports = {
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
coverageThreshold: {
global: {
// TODO after release/2022.09.15, raise this back up!!
statements: 80,
statements: 90,
// Got the go ahead from Mark to temporarily lower this. Taking out initialize component made the year,make,model and style coverage drop a bit. Once unit tests for license plate lookup, vin lookup and address lookup are in the coverage should go back up to 90
},
},

View file

@ -10,6 +10,9 @@ import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions";
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import baseMixin from "@/mixins/base-mixin.js";
import router from "@/router"
import store from "@/store"
import { storeMutations } from "@/constants/store-mutations";
// Mock our module for promises.
jest.mock("@/helpers/layout-helper.js", () => ({
@ -21,25 +24,16 @@ jest.mock("@/helpers/cms-content-helper", () => ({
fetchCmsContentForPage: jest.fn(),
}));
// Mock Store
jest.mock("@/store", () => ({
getters: {
vehicle: {
model: "TL",
},
applicationUser:{
pageData: {
"part-questions": null,
"vehicle-make": {},
"vehicle-model": {},
"vehicle-style": {},
"vehicle-damage": {}
}
}
},
// Mock fetchCmsContentForPage
jest.mock("@/router", () => ({
overrideNavigation: jest.fn(),
}));
describe("vehicle-style.vue", () => {
beforeEach(() => {
jest.clearAllMocks();
})
test("Style question component is initized with api data", async (done) => {
//Arrange
const styleQuestionInitialData = ["2 Door", "4 Door"];
@ -63,9 +57,7 @@ describe("vehicle-style.vue", () => {
done();
});
});
});
describe("vehicle-style.vue", () => {
test("BackButtonAction triggers a router.navigateWithoutSaving change", async (done) => {
//Arrange
const { wrapper, apiPromise } = setupMocks({
@ -95,20 +87,12 @@ describe("vehicle-style.vue", () => {
done();
});
});
});
describe("vehicle-style.vue", () => {
test("selectVehicle triggers a dispatchStoreAction commit", async (done) => {
test("setVehicle triggers a dispatchStoreAction commit", async (done) => {
//Arrange
const { wrapper, apiPromise } = setupMocks({
pageHeaderWidgetHeaderText: "Select a style to get started",
mountOptionsMockData: {
store: {
commit: jest.fn(),
getters: {
vehicle: {},
},
},
actionList: [
{
actionName: storeActions.SET_VEHICLE,
@ -134,9 +118,7 @@ describe("vehicle-style.vue", () => {
done();
});
});
});
describe("vehicle-style.vue", () => {
test("Model set, arePagePrerequisitesValid should be true ", async () => {
//Arrange
const { wrapper } = setupMocks({});
@ -155,7 +137,61 @@ describe("vehicle-style.vue", () => {
//Assert
expect(arePagePrerequisitesValid).toBe(true);
});
test("there is only one vehicle style => autoselect and move to vehicle damage", async () => {
//Arrange
const { wrapper } = setupMocks({
styleQuestionInitialData: ["2 door sedan"],
});
// Act
await vehicleStyle.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "vehicle-style" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_STYLE, "2 door sedan");
expect(router.overrideNavigation).toHaveBeenCalled();
})
test("there is only one vehicle style and vehicle-damage was visited => don't autoselect or move to vehicle damage", async () => {
//Arrange
const { wrapper } = setupMocks({
styleQuestionInitialData: ["2 door sedan"],
mountOptionsMockData: {
store: {
getters: {
applicationUser: {
pageData: {
"part-questions": null,
"vehicle-make": {},
"vehicle-model": {},
"vehicle-style": {},
"vehicle-damage": {}
}
}
}
}
}
});
// Act
await vehicleStyle.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "vehicle-style" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(store.commit).not.toHaveBeenCalledWith(storeMutations.UPDATE_STYLE, "2 door sedan");
expect(router.overrideNavigation).not.toHaveBeenCalled();
})
});
function setupMocks({
vehicleStyleQuestionCmsContent = {},
styleQuestionInitialData = {},
@ -190,7 +226,26 @@ function setupMocks({
initializeComponent: jest.fn(),
};
const mountOptions = getMountOptions(mountOptionsMockData);
store.commit = jest.fn();
store.dispatch = jest.fn();
store.getters = mountOptionsMockData.store?.getters ?? {
vehicle: {
model: "TL",
},
applicationUser: {
pageData: {
"part-questions": null,
"vehicle-make": {},
"vehicle-model": {},
"vehicle-style": {},
}
}
}
const mountOptions = getMountOptions({
...mountOptionsMockData,
store
});
const wrapper = shallowMount(vehicleStyle, mountOptions);
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;

View file

@ -26,6 +26,7 @@
<script>
// Components
import baseMixin from "@/mixins/base-mixin.js";
import styleQuestion from "@/layouts/vehicle-style/style-question/style-question";
import funnelHeader from "@/common-components/funnel-header/funnel-header";
import funnelSubHeader from "@/common-components/funnel-sub-header/funnel-sub-header";
@ -71,15 +72,12 @@ export default {
const resultMap = await settleAllPromises(promiseResultMap);
const visitedVehicleDamage = JSON.stringify(store.getters.applicationUser.pageData).indexOf(fmgPageValues.VEHICLE_DAMAGE) < 0 ? false : true;
// Call the "next" function to complete the transition to this page.
// If we have exactly one style then navigate directly to vehicle-damage
if(resultMap.styleQuestionInitialData.length === 1 && !visitedVehicleDamage) {
// TODO KO
store.commit(storeMutations.UPDATE_STYLE, resultMap.styleQuestionInitialData[0]);
await store.dispatch(storeActions.SET_VEHICLE,
await baseMixin.methods.dispatchStoreAction(storeActions.SET_VEHICLE,
{
year: store.getters.vehicle.year,
make: store.getters.vehicle.make,

View file

@ -65,7 +65,7 @@ describe("vin-lookup.vue", () => {
it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => {
// Arrange
const { wrapper } = setupMocks({});
mockOutPromises();
mockOutPromises({ carId: "C00000" });
wrapper.vm.navigateForward = jest.fn();
// Act
@ -78,7 +78,7 @@ describe("vin-lookup.vue", () => {
it("Should not call navigateForward() if the store carId does not match the vin response carId and forward button is clicked", async () => {
// Arrange
const { wrapper } = setupMocks({});
mockOutPromises('C11111');
mockOutPromises({ carId: 'C11111' });
wrapper.vm.vinTouched = true;
wrapper.vm.vin = "";
@ -95,7 +95,7 @@ describe("vin-lookup.vue", () => {
it("Should call navigateForward() if the store carId does not match the vin response carId but does match previously enterted carId and forward button is clicked", async () => {
// Arrange
const { wrapper } = setupMocks({});
mockOutPromises('C11111');
mockOutPromises({ carId: 'C11111' });
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
wrapper.vm.navigateForward = jest.fn();
@ -203,6 +203,35 @@ describe("vin-lookup.vue", () => {
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toBeCalledTimes(1);
})
})
describe("alerts", () => {
test("Zip is invalid => show AlertInvalidZipWidget", async () => {
// Arrange
const { wrapper } = setupMocks({});
mockOutPromises({ isZipValid: false });
await wrapper.setData({serviceZipCode: "11111"})
// Act
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.displayInvalidZipAlert).toEqual(true);
expect(wrapper.findComponent({ref: "alertInvalidZip"}).exists()).toBe(true);
})
test("Vin not found => show AlertVinNotFoundWidget", async () => {
// Arrange
const { wrapper } = setupMocks({});
mockOutPromises({});
// Act
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.displayVinNotFoundAlert).toEqual(true);
expect(wrapper.findComponent({cmsWidgetName: "AlertVinNotFoundWidget"}).exists()).toBe(true);
})
})
});
@ -217,20 +246,17 @@ function setupMocks({ customMountOptions }) {
mountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
const wrapper = shallowMount(vinLookup, mountOptions);
mockOutPromises(wrapper);
mockOutStubFunctions(wrapper);
return { wrapper };
}
function mockOutPromises(carId = 'C00000') {
function mockOutPromises({carId, isZipValid = true, isZipServiceable = true}) {
const apiResponses = {
serviceZipValidationResponse: {
isValid: true,
isServiceable: true
isValid: isZipValid,
isServiceable: isZipServiceable
},
vehicleLookupResponse: {
carId: carId
}
vehicleLookupResponse: carId ? { carId: carId } : null
};
settleAllPromises.mockImplementation(() => apiResponses);

View file

@ -240,11 +240,17 @@ export default {
// If a Service Zip is entered and it is an invalid zip code (ex. 11111) then show an alert
const isZipValid = resultMap.serviceZipValidationResponse.isValid;
console.log(isZipValid)
console.log(this.serviceZipCode)
if (this.serviceZipCode && !isZipValid) {
console.log("HIII")
this.displayInvalidZipAlert = true;
return this.$refs.funnelFooter.removeLoader();
}
console.log("BOO")
this.displayInvalidZipAlert = false;
// console.log(resultMap.vehicleLookupResponse)
// console.log(resultMap.serviceZipValidationResponse)
// If either lookup fails, remove the loader and stop processing the page.
if (!resultMap.vehicleLookupResponse || !resultMap.serviceZipValidationResponse.isServiceable) {

View file

@ -225,6 +225,8 @@ function navigateToUrl(url, optionalQuery = {}) {
externalUrl.searchParams.append(queryKey, optionalQuery[queryKey]);
}
externalUrl.searchParams.append("experiments", "ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true");
window.location.assign(externalUrl);
}

View file

@ -650,6 +650,51 @@ describe("Actions", () => {
expect(commit).toBeCalledWith(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, { "referralNumber": 123 });
});
it("loadOrder: state doesn't have EON => do not reset state", async () => {
// Arrange
const context = state;
globalMethods.callHttpClient.mockImplementation(() => {
return Promise.resolve({ data: { eon: "123" } });
});
context.commit = jest.fn();
context.state = {
order: {
}
}
// Act
const response = await actions.loadOrder(context, { referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx" });
// Assert
expect(response.data.eon).toEqual("123");
expect(context.commit).not.toBeCalledWith(storeMutations.RESET_STATE);
});
it("loadOrder eon doesn't match eon in state => reset state", async () => {
// Arrange
const context = state;
globalMethods.callHttpClient.mockImplementation(() => {
return Promise.resolve({ data: { eon: "123" } });
});
context.commit = jest.fn();
context.state = {
order: {
eon: "456"
}
}
// Act
const response = await actions.loadOrder(context, { referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx" });
// Assert
expect(response.data.eon).toEqual("123");
expect(context.commit).toBeCalledWith(storeMutations.RESET_STATE);
});
it("updateStoreWithSaveOrderResponse, should call commit six times", () => {
// Arrange
const context = state;