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();
|
||||
});
|
||||
|
||||
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 () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
|
@ -58,34 +148,44 @@ describe("address-vehicles.vue", () => {
|
|||
});
|
||||
|
||||
function setupMocks({
|
||||
//partsOrQuestions = [],
|
||||
carId = "C0000",
|
||||
route = null,
|
||||
lookupVehicleByVinResponse,
|
||||
})
|
||||
{
|
||||
useMainStore().applicationUser = {
|
||||
pageData: {
|
||||
"address-vehicles":
|
||||
[
|
||||
{ vehicle: {
|
||||
carId: "CARID",
|
||||
category: "SUV",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifColor: "white",
|
||||
imageVifNumber: "13769",
|
||||
make: "Hyundai",
|
||||
model: "Santa Fe",
|
||||
style: "4 door utility",
|
||||
year: 2020,
|
||||
|
||||
{
|
||||
vehicle: {
|
||||
carId: "CR00069309",
|
||||
category: "SUV",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifColor: "white",
|
||||
imageVifNumber: "13769",
|
||||
make: "Hyundai",
|
||||
model: "Santa Fe",
|
||||
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({
|
||||
route: route ? route : undefined,
|
||||
router: {
|
||||
|
|
@ -94,7 +194,7 @@ function setupMocks({
|
|||
mainStore: {
|
||||
order: {
|
||||
vehicle: {
|
||||
carId: carId,
|
||||
carId: "CR00069309",
|
||||
category: "SUV",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
|
|
@ -112,9 +212,7 @@ function setupMocks({
|
|||
);
|
||||
|
||||
const apiResponses = {
|
||||
cmsContent: {
|
||||
|
||||
},
|
||||
cmsContent: {},
|
||||
};
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiResponses);
|
||||
|
|
|
|||
Loading…
Reference in a new issue