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(),
}));
// Mock fetchCmsContentForPage
jest.mock("@/helpers/cms-content-helper", () => ({
fetchCmsContentForPage: jest.fn(),
}));
describe("addressVehicles.vue", () => {
describe("address-vehicles.vue", () => {
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
// Arrange
const mockSelectedVehicleVin = "TESTVIN";
const { wrapper } = setupMocks({});
wrapper.vm.$router.navigate = jest.fn();
// Act
await wrapper.setData({
selectedVehicleVin: "5NMS3CADXLH233004",
selectedVehicle: {
vin: mockSelectedVehicleVin
},
});
wrapper.vm.backButtonAction();
// Act
await wrapper.vm.backButtonAction();
//Assert
expect(wrapper.vm.$router.navigate).toBeCalled();
wrapper.unmount();
});
test("Should return true for valid page requisites if carId exists", async () => {
@ -72,103 +67,100 @@ describe("addressVehicles.vue", () => {
// });
});
//Mock props
const mockMixin = {
methods: {
getCmsContent: jest.fn((contentName) => {
if (contentName === "FoundMultipleVehicles") {
return "FoundMultipleVehiclesTestReturn";
}
if (contentName === "ProvideVinAlert") {
return "ProvideVinAlertTestReturn";
}
return null;
}),
},
computed: {
dynamicStrings() {
return { ROUTER_LINK: "routerLink:" };
},
},
};
function setupMocks({
// isZipValid = true,
// isZipServiceable = true,
// lookupVinByPlateResponse,
// partsOrQuestions = [],
vehicle = {},
vin = null,
// carId = "C0000",
vinLookupResponseError = null,
route = null,
lookupVinResponse,
partsOrQuestions = [],
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 = null,
})
{
const mountOptions = getMountOptions({
route: route ? route : undefined,
router: {
navigate: jest.fn(),
navigate: jest.fn(),
},
mainStore: {
order: {
vehicle: {
carId: carId,
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",
},
},
},
mixins: [mockMixin],
})
);
});
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 = {
// serviceZipValidationResponse: {
// isValid: isZipValid,
// isServiceable: isZipServiceable,
// },
vinLookupResponse: {
vin: vin,
vehicle: vehicle,
error: vinLookupResponseError,
},
vinLookup: {
carId: carId,
},
};
settleAllPromises.mockImplementation(() => apiResponses);
//Mock props
const mockMixin = {
methods: {
getCmsContent: jest.fn((contentName) => {
if (contentName === "FoundMultipleVehicles") {
return "FoundMultipleVehiclesTestReturn";
}
if (contentName === "ProvideVinAlert") {
return "ProvideVinAlertTestReturn";
}
return null;
}),
},
computed: {
dynamicStrings() {
return { ROUTER_LINK: "routerLink:" };
},
},
};
mountOptions.mixins = [mockMixin];
const wrapper = shallowMount(addressVehicles, mountOptions);
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 };
}
}