Unit tests
This commit is contained in:
parent
768191ea1a
commit
5e0e631180
3 changed files with 169 additions and 40 deletions
|
|
@ -14,7 +14,6 @@ module.exports = {
|
|||
"!src/layouts/component-test/component-test.vue",
|
||||
"!src/layouts/form-test/form-test.vue",
|
||||
"!src/layouts/vin-lookup/vin-lookup.vue",
|
||||
"!src/layouts/license-plate-lookup/license-plate-lookup.vue",
|
||||
"!src/layouts/vehicle-damage/windshield-damage-type-question/windshield-damage-type-question.vue",
|
||||
"!src/layouts/vehicle-damage/windshield-options/windshield-options.vue",
|
||||
"!src/layouts/part-questions/**/*.vue",
|
||||
|
|
|
|||
|
|
@ -1,47 +1,100 @@
|
|||
import {getDamageString, isGlassAvailableForCarId} from "./damage-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
|
||||
jest.mock("@/store", () => ({
|
||||
getters: {damage: {
|
||||
glassToReplace: [{location: "Windshield", name: "windshield"}]
|
||||
}
|
||||
}
|
||||
}));
|
||||
import store from "@/store";
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return damage getter info", () => {
|
||||
it("Should return match when multiple selected damage options are in the store", () => {
|
||||
|
||||
// Arrange / Act
|
||||
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}, {location: "Passenger", name: "sideWindow"}];
|
||||
|
||||
const damage = getDamageString();
|
||||
expect(damage).toEqual("windshield")
|
||||
|
||||
// Assert
|
||||
expect(damage).toEqual("match");
|
||||
});
|
||||
});
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return windshield when Windshield is the only selected damage option in the store", () => {
|
||||
|
||||
// Arrange / Act
|
||||
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}];
|
||||
|
||||
const damage = getDamageString();
|
||||
|
||||
// Assert
|
||||
expect(damage).toEqual("windshield");
|
||||
});
|
||||
});
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return side window when Driver or Passenger is the only selected damage option in the store", () => {
|
||||
|
||||
// Arrange / Act
|
||||
store.getters.damage.glassToReplace = [{location: "Passenger", name: "sideWindow"}];
|
||||
|
||||
const damage = getDamageString();
|
||||
|
||||
// Assert
|
||||
expect(damage).toEqual("side window");
|
||||
});
|
||||
});
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return rear window when Rear is the only selected damage option in the store", () => {
|
||||
|
||||
// Arrange / Act
|
||||
store.getters.damage.glassToReplace = [{location: "Rear", name: "rear"}];
|
||||
|
||||
const damage = getDamageString();
|
||||
|
||||
// Assert
|
||||
expect(damage).toEqual("rear window");
|
||||
});
|
||||
});
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return true if no mismatches between each array exist", async () => {
|
||||
// Arrange
|
||||
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}];
|
||||
|
||||
const updatedOptions = {
|
||||
data: {
|
||||
windshieldOptions: {availableReplacementOptions: ["windshield"]}
|
||||
}
|
||||
}
|
||||
|
||||
// Act
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn().mockImplementation(()=> {
|
||||
return updatedOptions;
|
||||
});
|
||||
const misMatch = await isGlassAvailableForCarId();
|
||||
expect(misMatch).toEqual(true);
|
||||
const isGlassAvailable = await isGlassAvailableForCarId();
|
||||
|
||||
// Assert
|
||||
expect(isGlassAvailable).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("damage-helper.js", () => {
|
||||
it("Should return false if any mismatches between each array exist", async () => {
|
||||
// Arrange
|
||||
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}];
|
||||
|
||||
const updatedOptions = {
|
||||
data: {
|
||||
windshieldOptions: {availableReplacementOptions: ["Crack"]}
|
||||
}
|
||||
}
|
||||
|
||||
// Act
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn().mockImplementation(()=> {
|
||||
return updatedOptions;
|
||||
});
|
||||
const misMatch = await isGlassAvailableForCarId();
|
||||
expect(misMatch).toEqual(false);
|
||||
const isGlassAvailable = await isGlassAvailableForCarId();
|
||||
|
||||
// Assert
|
||||
expect(isGlassAvailable).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Components
|
||||
import vehicleDamage from "@/layouts/license-plate-lookup/license-plate-lookup.vue";
|
||||
import licensePlateLookup from "@/layouts/license-plate-lookup/license-plate-lookup.vue";
|
||||
|
||||
// Supporting Files
|
||||
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||
|
|
@ -29,25 +29,15 @@ jest.mock("@/store", () => ({
|
|||
dispatch: jest.fn(),
|
||||
getters: {
|
||||
order: {
|
||||
customer: {
|
||||
emailAddress: "test@test.com"
|
||||
},
|
||||
serviceLocation: {
|
||||
zip: "43443"
|
||||
}
|
||||
customer: { emailAddress: "test@test.com"},
|
||||
serviceLocation: {zip: "11111"},
|
||||
},
|
||||
vehicle: {
|
||||
carId: "C00000000",
|
||||
image: "test.jpg",
|
||||
payment: {
|
||||
insuranceCoverage: {
|
||||
isVerified: false
|
||||
}
|
||||
},
|
||||
registration: {
|
||||
licensePlate: "HWV4445",
|
||||
zipCode: "43224"
|
||||
}
|
||||
licensePlate: "TESTPLATE",
|
||||
zipCode: "12345",
|
||||
carId: "TESTID"
|
||||
},
|
||||
},
|
||||
eventBusItem: jest.fn(),
|
||||
damage: {
|
||||
|
|
@ -62,7 +52,7 @@ describe("license-plate-lookup.vue", () => {
|
|||
const { wrapper } = setupMocks({});
|
||||
|
||||
//Act
|
||||
vehicleDamage.beforeRouteEnter.call(
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
|
|
@ -84,7 +74,7 @@ describe("license-plate-lookup.vue", () => {
|
|||
const { wrapper } = setupMocks({});
|
||||
|
||||
//Act
|
||||
vehicleDamage.beforeRouteEnter.call(
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
|
|
@ -99,6 +89,99 @@ describe("license-plate-lookup.vue", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("getLicensePlateFromStore returns store license plate", async () => {
|
||||
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// ACT
|
||||
const licensePlate = wrapper.vm.getLicensePlateFromStore();
|
||||
|
||||
// Assert
|
||||
expect(licensePlate).toEqual("TESTPLATE");
|
||||
});
|
||||
});
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("getRegistrationZipFromStore returns store registration zip", async () => {
|
||||
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// ACT
|
||||
const registrationZip = wrapper.vm.getRegistrationZipFromStore();
|
||||
|
||||
// Assert
|
||||
expect(registrationZip).toEqual("12345");
|
||||
});
|
||||
});
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("getEmailFromStore returns store customer email", async () => {
|
||||
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// ACT
|
||||
const customerEmail = wrapper.vm.getEmailFromStore();
|
||||
|
||||
// Assert
|
||||
expect(customerEmail).toEqual("test@test.com");
|
||||
});
|
||||
});
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("getServiceZipFromStore returns store service zip", async () => {
|
||||
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// ACT
|
||||
const serviceZip = wrapper.vm.getServiceZipFromStore();
|
||||
|
||||
// Assert
|
||||
expect(serviceZip).toEqual("11111");
|
||||
});
|
||||
});
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("Navigate forward should be called when data entered matches store data", async () => {
|
||||
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({
|
||||
pageHeaderWidgetHeaderText: "",
|
||||
mountOptionsMockData: {
|
||||
router: { navigateAfterSave: jest.fn(), },
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.vm.licensePlate = "TESTPLATE";
|
||||
wrapper.vm.registrationZip = "12345";
|
||||
wrapper.vm.validateZip = jest.fn().mockImplementation(() => {
|
||||
return {data: {isServiceable: true}};
|
||||
});
|
||||
wrapper.vm.lookupVin = jest.fn().mockImplementation(() => {
|
||||
return {data: {vehicle: {carId: 'TESTID'}}, catch: () => "test"};
|
||||
});
|
||||
|
||||
//Act
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalled();
|
||||
expect(wrapper.vm.isCarIdDifferent).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
function setupMocks({
|
||||
pageHeaderWidgetHeaderText = {},
|
||||
|
|
@ -106,12 +189,6 @@ function setupMocks({
|
|||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
store: {
|
||||
getters: {
|
||||
vehicle: {},
|
||||
payment: { insuranceCoverage: { isVerified: false } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}) {
|
||||
//Mock api responses
|
||||
|
|
@ -139,7 +216,7 @@ function setupMocks({
|
|||
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||
mountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
||||
|
||||
const wrapper = shallowMount(vehicleDamage, mountOptions);
|
||||
const wrapper = shallowMount(licensePlateLookup, mountOptions);
|
||||
|
||||
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue