Merge pull request #546 from Safelite/feature/vin-lookup-tests
Vin lookup unit tests
This commit is contained in:
commit
a5088eb73f
2 changed files with 120 additions and 25 deletions
|
|
@ -46,7 +46,6 @@ describe("vin-lookup.vue", () => {
|
||||||
it("Should update the funnel-footer forward button when VIN is changed", (done) => {
|
it("Should update the funnel-footer forward button when VIN is changed", (done) => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({ });
|
||||||
wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn();
|
|
||||||
//Act
|
//Act
|
||||||
wrapper.setData({vin: "newValue"});
|
wrapper.setData({vin: "newValue"});
|
||||||
//Assert
|
//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 () => {
|
it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
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();
|
wrapper.vm.navigateForward = jest.fn();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -87,12 +67,98 @@ describe("vin-lookup.vue", () => {
|
||||||
//Assert
|
//Assert
|
||||||
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
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 }) {
|
function setupMocks({ customMountOptions }) {
|
||||||
|
|
||||||
|
|
||||||
const mountOptions = getMountOptions({});
|
const mountOptions = getMountOptions({});
|
||||||
|
|
||||||
const finalMountOptions = Object.assign(mountOptions, customMountOptions);
|
const finalMountOptions = Object.assign(mountOptions, customMountOptions);
|
||||||
|
|
@ -102,8 +168,34 @@ function setupMocks({ customMountOptions }) {
|
||||||
finalMountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
finalMountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
||||||
|
|
||||||
const wrapper = shallowMount(vinLookup, finalMountOptions);
|
const wrapper = shallowMount(vinLookup, finalMountOptions);
|
||||||
|
mockOutPromises(wrapper);
|
||||||
|
mockOutStubFunctions(wrapper);
|
||||||
return { 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 = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
||||||
|
|
@ -292,8 +292,11 @@ export default {
|
||||||
this.vinNotFound = true;
|
this.vinNotFound = true;
|
||||||
this.$refs.funnelFooter.removeLoader();
|
this.$refs.funnelFooter.removeLoader();
|
||||||
this.noServiceZip = false;
|
this.noServiceZip = false;
|
||||||
return;
|
return false;
|
||||||
});
|
});
|
||||||
|
if (!vehicleLookupResponse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!zipValidationResponse.data.isServiceable) {
|
if (!zipValidationResponse.data.isServiceable) {
|
||||||
this.customAlertData.zip = this.zip;
|
this.customAlertData.zip = this.zip;
|
||||||
this.$refs.funnelFooter.removeLoader();
|
this.$refs.funnelFooter.removeLoader();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue