unit tests for address-vehicles complete
This commit is contained in:
parent
010c4f14e1
commit
c2a70c55a3
1 changed files with 117 additions and 19 deletions
|
|
@ -37,6 +37,96 @@ describe("address-vehicles.vue", () => {
|
||||||
expect(wrapper.vm.$router.navigate).toBeCalled();
|
expect(wrapper.vm.$router.navigate).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("navigateForward should be called if forwardButtonAction is run", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
const lookupVinResponse = {
|
||||||
|
data: {
|
||||||
|
carId: "456"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||||
|
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||||
|
wrapper.vm.lookupVin = jest.fn(() => Promise.resolve(lookupVinResponse));
|
||||||
|
wrapper.vm.$router.navigate = jest.fn();
|
||||||
|
wrapper.vm.saveVin = jest.fn().mockImplementation(() => {});
|
||||||
|
wrapper.vm.navigateForward = jest.fn().mockImplementation(() => {});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.setData({
|
||||||
|
selectedVehicleVin: "5NMS3CADXLH233004",
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should return out of forwardButtonAction is lookupVin returns an error", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
const lookupVinResponse = {
|
||||||
|
error: "there is an error",
|
||||||
|
};
|
||||||
|
|
||||||
|
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||||
|
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||||
|
wrapper.vm.lookupVin = jest.fn(() => Promise.reject(lookupVinResponse));
|
||||||
|
wrapper.vm.$router.navigate = jest.fn();
|
||||||
|
wrapper.vm.saveVin = jest.fn().mockImplementation(() => {});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.setData({
|
||||||
|
selectedVehicleVin: "5NMS3CADXLH233004",
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.forwardButtonAction).toReturn;
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should navigate to CLICKED_FORWARD scenario if carId is different and selected glass not available for vehicle on navigateForward", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||||
|
wrapper.vm.$router.navigate = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.setData({
|
||||||
|
selectedVehicleVin: "5NMS3CADXLH233004",
|
||||||
|
isSelectedGlassAvailableForVehicle: false,
|
||||||
|
isCarIdDifferent: true,
|
||||||
|
});
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("carId is not different on navigateForward (car was found) => Should handle navigating forward with car match", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.setData({
|
||||||
|
isCarIdDifferent: false,
|
||||||
|
});
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test("Should return true for valid page requisites if carId exists", async () => {
|
test("Should return true for valid page requisites if carId exists", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
@ -58,34 +148,44 @@ describe("address-vehicles.vue", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
//partsOrQuestions = [],
|
|
||||||
carId = "C0000",
|
|
||||||
route = null,
|
route = null,
|
||||||
|
lookupVehicleByVinResponse,
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
useMainStore().applicationUser = {
|
useMainStore().applicationUser = {
|
||||||
pageData: {
|
pageData: {
|
||||||
"address-vehicles":
|
"address-vehicles":
|
||||||
[
|
[
|
||||||
{ vehicle: {
|
{
|
||||||
carId: "CARID",
|
vehicle: {
|
||||||
category: "SUV",
|
carId: "CR00069309",
|
||||||
imageUrl:
|
category: "SUV",
|
||||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
imageUrl:
|
||||||
imageVifColor: "white",
|
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||||
imageVifNumber: "13769",
|
imageVifColor: "white",
|
||||||
make: "Hyundai",
|
imageVifNumber: "13769",
|
||||||
model: "Santa Fe",
|
make: "Hyundai",
|
||||||
style: "4 door utility",
|
model: "Santa Fe",
|
||||||
year: 2020,
|
style: "4 door utility",
|
||||||
|
year: 2020,
|
||||||
},
|
},
|
||||||
vin: "TESTVIN123412341234"
|
vin: "5NMS3CADXLH233004",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useMainStore().lookupVehicleByVin = jest.fn().mockImplementation(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: lookupVehicleByVinResponse
|
||||||
|
? lookupVehicleByVinResponse : {
|
||||||
|
vehicle: {
|
||||||
|
carId: "CARID"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
route: route ? route : undefined,
|
route: route ? route : undefined,
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -94,7 +194,7 @@ function setupMocks({
|
||||||
mainStore: {
|
mainStore: {
|
||||||
order: {
|
order: {
|
||||||
vehicle: {
|
vehicle: {
|
||||||
carId: carId,
|
carId: "CR00069309",
|
||||||
category: "SUV",
|
category: "SUV",
|
||||||
imageUrl:
|
imageUrl:
|
||||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||||
|
|
@ -112,9 +212,7 @@ function setupMocks({
|
||||||
);
|
);
|
||||||
|
|
||||||
const apiResponses = {
|
const apiResponses = {
|
||||||
cmsContent: {
|
cmsContent: {},
|
||||||
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
settleAllPromises.mockImplementation(() => apiResponses);
|
settleAllPromises.mockImplementation(() => apiResponses);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue