EOD commit - unit testing
This commit is contained in:
parent
4d9d1623bf
commit
349e006b6b
1 changed files with 89 additions and 97 deletions
|
|
@ -14,28 +14,23 @@ jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
settleAllPromises: jest.fn(),
|
settleAllPromises: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock fetchCmsContentForPage
|
describe("address-vehicles.vue", () => {
|
||||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
||||||
fetchCmsContentForPage: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("addressVehicles.vue", () => {
|
|
||||||
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
const mockSelectedVehicleVin = "TESTVIN";
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
wrapper.vm.$router.navigate = jest.fn();
|
await wrapper.setData({
|
||||||
|
selectedVehicle: {
|
||||||
|
vin: mockSelectedVehicleVin
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await wrapper.setData({
|
await wrapper.vm.backButtonAction();
|
||||||
selectedVehicleVin: "5NMS3CADXLH233004",
|
|
||||||
});
|
|
||||||
wrapper.vm.backButtonAction();
|
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
expect(wrapper.vm.$router.navigate).toBeCalled();
|
expect(wrapper.vm.$router.navigate).toBeCalled();
|
||||||
|
|
||||||
wrapper.unmount();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Should return true for valid page requisites if carId exists", async () => {
|
test("Should return true for valid page requisites if carId exists", async () => {
|
||||||
|
|
@ -72,8 +67,74 @@ describe("addressVehicles.vue", () => {
|
||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
//Mock props
|
function setupMocks({
|
||||||
const mockMixin = {
|
lookupVinResponse,
|
||||||
|
partsOrQuestions = [],
|
||||||
|
carId = "C0000",
|
||||||
|
route = null,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
const mountOptions = getMountOptions({
|
||||||
|
route: route ? route : undefined,
|
||||||
|
router: {
|
||||||
|
navigate: jest.fn(),
|
||||||
|
},
|
||||||
|
mainStore: {
|
||||||
|
order: {
|
||||||
|
vehicle: {
|
||||||
|
carId: carId,
|
||||||
|
category: "SUV",
|
||||||
|
year: 2020,
|
||||||
|
make: "Hyundai",
|
||||||
|
model: "Santa Fe",
|
||||||
|
style: "4 door utility",
|
||||||
|
imageUrl:
|
||||||
|
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||||
|
imageVifNumber: "13769",
|
||||||
|
imageVifColor: "white",
|
||||||
|
},
|
||||||
|
vin: "5NMS3CADXLH233004",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
useMainStore().lookupVehicleByVin = jest.fn().mockImplementation(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: lookupVinResponse
|
||||||
|
? lookupVinResponse
|
||||||
|
: {
|
||||||
|
carId: "CARID",
|
||||||
|
category: "TESTCAR",
|
||||||
|
year: "0000",
|
||||||
|
make: "TestMake",
|
||||||
|
model: "TestModel",
|
||||||
|
style: "TestStyle",
|
||||||
|
imageUrl: "url",
|
||||||
|
imageVifNumber: "00000",
|
||||||
|
imageVifColor: "color"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: {
|
||||||
|
partsOrQuestions: partsOrQuestions,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const apiResponses = {
|
||||||
|
vinLookup: {
|
||||||
|
carId: carId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
settleAllPromises.mockImplementation(() => apiResponses);
|
||||||
|
|
||||||
|
//Mock props
|
||||||
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
getCmsContent: jest.fn((contentName) => {
|
getCmsContent: jest.fn((contentName) => {
|
||||||
if (contentName === "FoundMultipleVehicles") {
|
if (contentName === "FoundMultipleVehicles") {
|
||||||
|
|
@ -90,80 +151,11 @@ const mockMixin = {
|
||||||
return { ROUTER_LINK: "routerLink:" };
|
return { ROUTER_LINK: "routerLink:" };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
function setupMocks({
|
|
||||||
// isZipValid = true,
|
|
||||||
// isZipServiceable = true,
|
|
||||||
// lookupVinByPlateResponse,
|
|
||||||
// partsOrQuestions = [],
|
|
||||||
vehicle = {},
|
|
||||||
vin = null,
|
|
||||||
// carId = "C0000",
|
|
||||||
vinLookupResponseError = null,
|
|
||||||
route = null,
|
|
||||||
carId = "C0000",
|
|
||||||
}) {
|
|
||||||
// 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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mixins: [mockMixin],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const apiResponses = {
|
|
||||||
// serviceZipValidationResponse: {
|
|
||||||
// isValid: isZipValid,
|
|
||||||
// isServiceable: isZipServiceable,
|
|
||||||
// },
|
|
||||||
vinLookupResponse: {
|
|
||||||
vin: vin,
|
|
||||||
vehicle: vehicle,
|
|
||||||
error: vinLookupResponseError,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
settleAllPromises.mockImplementation(() => apiResponses);
|
mountOptions.mixins = [mockMixin];
|
||||||
|
|
||||||
|
const wrapper = shallowMount(addressVehicles, mountOptions);
|
||||||
|
|
||||||
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||||
wrapper.vm.setCmsContent = jest.fn();
|
wrapper.vm.setCmsContent = jest.fn();
|
||||||
|
|
@ -171,4 +163,4 @@ function setupMocks({
|
||||||
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||||
|
|
||||||
return { wrapper };
|
return { wrapper };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue