EOD commit - unit testing

This commit is contained in:
Kroell 2023-02-02 17:00:07 -05:00
parent 4d9d1623bf
commit 349e006b6b

View file

@ -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,6 +67,72 @@ describe("addressVehicles.vue", () => {
// }); // });
}); });
function setupMocks({
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 //Mock props
const mockMixin = { const mockMixin = {
methods: { methods: {
@ -92,78 +153,9 @@ const mockMixin = {
}, },
}; };
function setupMocks({ mountOptions.mixins = [mockMixin];
// 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(() => { const wrapper = shallowMount(addressVehicles, mountOptions);
// 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);
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => ""); wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
wrapper.vm.setCmsContent = jest.fn(); wrapper.vm.setCmsContent = jest.fn();