EOD commit - updates to unit tests
This commit is contained in:
parent
4ddb9b6047
commit
78fa90a6cf
2 changed files with 171 additions and 1 deletions
|
|
@ -58,7 +58,6 @@ const mockMixin = {
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
modelValueProp = "TESTCAR",
|
modelValueProp = "TESTCAR",
|
||||||
cmsQuestionText = "CMS text goes here",
|
cmsQuestionText = "CMS text goes here",
|
||||||
dataFromStoreApi = [],
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const mountOptions = getMountOptions();
|
const mountOptions = getMountOptions();
|
||||||
|
|
|
||||||
171
src/layouts/address-vehicles/address-vehicles.spec.js
Normal file
171
src/layouts/address-vehicles/address-vehicles.spec.js
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
import addressVehicles from "@/layouts/address-vehicles/address-vehicles";
|
||||||
|
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import { useMainStore } from "@/store";
|
||||||
|
|
||||||
|
jest.mock("@/helpers/damage-helper", () => ({
|
||||||
|
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
||||||
|
getDamageString: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock our module for promises.
|
||||||
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
|
settleAllPromises: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock fetchCmsContentForPage
|
||||||
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||||
|
fetchCmsContentForPage: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("addressVehicles.vue", () => {
|
||||||
|
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.$router.navigate = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.setData({
|
||||||
|
selectedVehicleVin: "5NMS3CADXLH233004",
|
||||||
|
});
|
||||||
|
wrapper.vm.backButtonAction();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toBeCalled();
|
||||||
|
|
||||||
|
wrapper.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// test("Should return true for valid page requisites if carId / zipCode / emailAddress / pageData exists", async () => {
|
||||||
|
// // Arrange
|
||||||
|
// const { wrapper } = setupMocks({});
|
||||||
|
// useMainStore().order.vehicle.carId = "CR00000395";
|
||||||
|
// useMainStore().order.serviceLocation.zipCode = "43210";
|
||||||
|
// useMainStore().order.customer.emailAddress = "testemail@email.com";
|
||||||
|
|
||||||
|
// // Act
|
||||||
|
// addressVehicles.beforeRouteEnter.call(
|
||||||
|
// wrapper.vm,
|
||||||
|
// { query: { issPage: "address-vehicles" } },
|
||||||
|
// undefined,
|
||||||
|
// (c) => c(wrapper.vm)
|
||||||
|
// );
|
||||||
|
|
||||||
|
// let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||||
|
|
||||||
|
// // Assert
|
||||||
|
// expect(arePagePrerequisitesValid).toBe(true);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// test("Should return false for valid page requisites if carId is missing", async () => {
|
||||||
|
// // Arrange
|
||||||
|
// const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// // Act
|
||||||
|
// store.commit(storeMutations.UPDATE_CAR_ID, null);
|
||||||
|
// const result = wrapper.vm.arePagePrerequisitesValid();
|
||||||
|
|
||||||
|
// //Assert
|
||||||
|
// expect(result).toBe(false);
|
||||||
|
|
||||||
|
// wrapper.unmount();
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
|
||||||
|
function setupMocks({
|
||||||
|
// isZipValid = true,
|
||||||
|
// isZipServiceable = true,
|
||||||
|
// lookupVinByPlateResponse,
|
||||||
|
// partsOrQuestions = [],
|
||||||
|
vehicle = {},
|
||||||
|
vin = null,
|
||||||
|
// carId = "C0000",
|
||||||
|
vinLookupResponseError = null,
|
||||||
|
route = null,
|
||||||
|
carId = "C0000",
|
||||||
|
zipCode = "12345",
|
||||||
|
emailAddress = "test@test.com"
|
||||||
|
}) {
|
||||||
|
// useMainStore().validateZip = jest.fn().mockImplementation(() => {
|
||||||
|
// return Promise.resolve({
|
||||||
|
// data: {
|
||||||
|
// isValid: isZipValid,
|
||||||
|
// isServiceable: isZipServiceable,
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// });
|
||||||
|
|
||||||
|
// useMainStore().lookupVinByPlate = jest.fn().mockImplementation(() => {
|
||||||
|
// return Promise.resolve({
|
||||||
|
// data: lookupVinByPlateResponse
|
||||||
|
// ? lookupVinByPlateResponse : {
|
||||||
|
// vin: "TEST_VIN",
|
||||||
|
// vehicle: {
|
||||||
|
// carId: "CARID"
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// });
|
||||||
|
|
||||||
|
// useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
|
||||||
|
// return Promise.resolve({
|
||||||
|
// data: {
|
||||||
|
// partsOrQuestions: partsOrQuestions,
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// });
|
||||||
|
|
||||||
|
const wrapper = shallowMount(
|
||||||
|
addressVehicles,
|
||||||
|
getMountOptions({
|
||||||
|
route: route ? route : undefined,
|
||||||
|
router: {
|
||||||
|
navigate: jest.fn(),
|
||||||
|
},
|
||||||
|
mainStore: {
|
||||||
|
order: {
|
||||||
|
vehicle: {
|
||||||
|
carId: carId,
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
zipCode: zipCode,
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
emailAddress: emailAddress,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
applicationUser: {
|
||||||
|
pageData: "address-vehicles",
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const apiResponses = {
|
||||||
|
// serviceZipValidationResponse: {
|
||||||
|
// isValid: isZipValid,
|
||||||
|
// isServiceable: isZipServiceable,
|
||||||
|
// },
|
||||||
|
vinLookupResponse: {
|
||||||
|
vin: vin,
|
||||||
|
vehicle: vehicle,
|
||||||
|
error: vinLookupResponseError,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
settleAllPromises.mockImplementation(() => apiResponses);
|
||||||
|
|
||||||
|
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||||
|
wrapper.vm.setCmsContent = jest.fn();
|
||||||
|
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||||
|
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||||
|
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue