vin-lookup-tests | Created base setupmock and added two tests
Also added a 'lite' mode for running tests
This commit is contained in:
parent
78f66ddd86
commit
3522ffcef1
2 changed files with 113 additions and 1 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"test:unit": "vue-cli-service test:unit --coverage --ci",
|
"test:unit": "vue-cli-service test:unit --coverage --ci",
|
||||||
|
"test:unit:lite": "vue-cli-service test:unit --ci",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1 +1,112 @@
|
||||||
test.todo("some test to be written in the future");
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import vinLookup from "./vin-lookup.vue";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
|
||||||
|
import store from "@/store";
|
||||||
|
|
||||||
|
jest.mock("@/store", () => ({
|
||||||
|
commit: jest.fn(),
|
||||||
|
dispatch: jest.fn(),
|
||||||
|
getters: {
|
||||||
|
vehicle: {
|
||||||
|
year: 2019,
|
||||||
|
carId: 'initial carId'
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
serviceLocation: {
|
||||||
|
zipCode: "45253"
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
emailAddress: "builddigitaltest@safelite.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
payment: {
|
||||||
|
insuranceCoverage: {
|
||||||
|
isVerified: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
damage: {
|
||||||
|
glassToReplace: "windshield"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { getDamageString, getIsWindshieldOnly,isGlassAvailableForCarId } from "@/helpers/damage-helper";
|
||||||
|
|
||||||
|
jest.mock("@/helpers/damage-helper", () => ({
|
||||||
|
isGlassAvailableForCarId: jest.fn(() => {
|
||||||
|
return Promise.resolve();
|
||||||
|
}),
|
||||||
|
getIsWindshieldOnly: jest.fn(),
|
||||||
|
getDamageString: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toBeCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function setupMocks({ customMountOptions }) {
|
||||||
|
|
||||||
|
|
||||||
|
const mountOptions = getMountOptions({});
|
||||||
|
|
||||||
|
const finalMountOptions = Object.assign(mountOptions, customMountOptions);
|
||||||
|
// Modify/augment default mount options
|
||||||
|
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);
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockMixin = {
|
||||||
|
methods: {
|
||||||
|
getCmsContent: jest.fn(() => "placeholder CMS content"),
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue