vin-lookup-tests | added some tests
This commit is contained in:
parent
d665894ec8
commit
27dae3e889
1 changed files with 116 additions and 24 deletions
|
|
@ -46,7 +46,6 @@ describe("vin-lookup.vue", () => {
|
|||
it("Should update the funnel-footer forward button when VIN is changed", (done) => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn();
|
||||
//Act
|
||||
wrapper.setData({vin: "newValue"});
|
||||
//Assert
|
||||
|
|
@ -60,25 +59,6 @@ describe("vin-lookup.vue", () => {
|
|||
it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
const zipValidationApiResponse = {
|
||||
data: {
|
||||
isServiceable: true
|
||||
}
|
||||
};
|
||||
const vehicleLookupApiResponse = {
|
||||
data: {
|
||||
carId: 'initial carId'
|
||||
}
|
||||
};
|
||||
|
||||
const zipPromise = Promise.resolve(zipValidationApiResponse);
|
||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||
|
||||
wrapper.vm.validateZip = jest.fn().mockImplementation(() => zipPromise);
|
||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||
|
||||
wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn();
|
||||
wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn();
|
||||
wrapper.vm.navigateForward = jest.fn();
|
||||
|
||||
// Act
|
||||
|
|
@ -87,12 +67,98 @@ describe("vin-lookup.vue", () => {
|
|||
//Assert
|
||||
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Should not call navigateForward() if the store carId does not match the vin response carId and forward button is clicked", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
const vehicleLookupApiResponse = {
|
||||
data: {
|
||||
carId: 'new carId' // does not match the store value
|
||||
}
|
||||
};
|
||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||
|
||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||
|
||||
wrapper.vm.navigateForward = jest.fn();
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.navigateForward).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Should call navigateForward() if the store carId does not match the vin response carId but does match previously enterted carId and forward button is clicked", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
const vehicleLookupApiResponse = {
|
||||
data: {
|
||||
carId: 'new carId' // does not match the store value
|
||||
}
|
||||
};
|
||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||
|
||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||
wrapper.vm.navigateForward = jest.fn();
|
||||
|
||||
wrapper.vm.previouslyEnteredCarId = 'new carId';
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Should not call navigateForward() if zip service returns a non-serviceable flag", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
const zipValidationApiResponse = {
|
||||
data: {
|
||||
isServiceable: false
|
||||
}
|
||||
};
|
||||
|
||||
const zipPromise = Promise.resolve(zipValidationApiResponse);
|
||||
|
||||
wrapper.vm.validateZip = jest.fn().mockImplementation(() => zipPromise);
|
||||
wrapper.vm.navigateForward = jest.fn();
|
||||
|
||||
wrapper.vm.previouslyEnteredCarId = 'new carId';
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.navigateForward).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Should not call navigateForward() when forward button is clicked but lookupVehicle errors out.", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ });
|
||||
const vehicleLookupApiResponse = {
|
||||
data: {
|
||||
carId: 'new carId' // does not match the store value
|
||||
}
|
||||
};
|
||||
const vinPromise = Promise.reject(vehicleLookupApiResponse);
|
||||
|
||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||
wrapper.vm.navigateForward = jest.fn();
|
||||
|
||||
wrapper.vm.previouslyEnteredCarId = 'new carId';
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.navigateForward).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function setupMocks({ customMountOptions }) {
|
||||
|
||||
|
||||
const mountOptions = getMountOptions({});
|
||||
|
||||
const finalMountOptions = Object.assign(mountOptions, customMountOptions);
|
||||
|
|
@ -100,10 +166,36 @@ function setupMocks({ customMountOptions }) {
|
|||
finalMountOptions.global.mocks["$store"] = store;
|
||||
finalMountOptions.global.mixins = [mockMixin];
|
||||
finalMountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
||||
|
||||
|
||||
const wrapper = shallowMount(vinLookup, finalMountOptions);
|
||||
mockOutPromises(wrapper);
|
||||
mockOutStubFunctions(wrapper);
|
||||
return { wrapper };
|
||||
}
|
||||
}
|
||||
|
||||
function mockOutPromises(wrapper) {
|
||||
const zipValidationApiResponse = {
|
||||
data: {
|
||||
isServiceable: true
|
||||
}
|
||||
};
|
||||
const vehicleLookupApiResponse = {
|
||||
data: {
|
||||
carId: 'initial carId'
|
||||
}
|
||||
};
|
||||
|
||||
const zipPromise = Promise.resolve(zipValidationApiResponse);
|
||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||
|
||||
wrapper.vm.validateZip = jest.fn().mockImplementation(() => zipPromise);
|
||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||
}
|
||||
|
||||
function mockOutStubFunctions(wrapper) {
|
||||
wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn();
|
||||
wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn();
|
||||
}
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue