393 lines
12 KiB
JavaScript
393 lines
12 KiB
JavaScript
// Components
|
|
import serviceLocation from "@/layouts/service-location/service-location.vue";
|
|
|
|
// Supporting files
|
|
import { shallowMount } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper";
|
|
|
|
import store from "@/store";
|
|
import baseMixin from "@/mixins/base-mixin";
|
|
|
|
// Define Mocks
|
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
fetchCmsContentForPage: jest.fn(() => {
|
|
return Promise.resolve("content");
|
|
}),
|
|
}));
|
|
|
|
const mockGetPricedMobileFeePart = (mockServiceZipCode) => {
|
|
let mobileFeePart = {};
|
|
|
|
if (mockServiceZipCode === "43235") {
|
|
mobileFeePart = {
|
|
partNumber: "MOBILE FEE",
|
|
description: "MOBILE FEE",
|
|
partType: "FEE",
|
|
laborAmount: 49.99,
|
|
sellingPrice: 0,
|
|
kitPrice: 0,
|
|
};
|
|
}
|
|
|
|
return Promise.resolve(mobileFeePart);
|
|
};
|
|
|
|
jest.mock("@/helpers/service-location-helper", () => ({
|
|
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
|
|
return mockGetPricedMobileFeePart(mockServiceZipCode);
|
|
}),
|
|
}));
|
|
|
|
jest.mock("@/store", () => ({
|
|
commit: jest.fn(),
|
|
dispatch: jest.fn(),
|
|
}));
|
|
|
|
const mockMixin = {
|
|
methods: {
|
|
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
|
|
if (widgetName === linkWidgetName) {
|
|
return mockLinkCmsContent[cmsFieldName];
|
|
}
|
|
|
|
if (widgetName === modalWidgetName) {
|
|
return mockModalCmsContent[cmsFieldName];
|
|
}
|
|
|
|
if (widgetName === mobileFeeDisclaimerWidgetName) {
|
|
return mockMobileFeeDisclaimerContent[cmsFieldName];
|
|
}
|
|
|
|
return null;
|
|
}),
|
|
|
|
getZipCodeData: jest.fn((zip) => {
|
|
if (zip === "43235" || zip === "55555") {
|
|
return Promise.resolve({
|
|
containsMilitaryBase: false,
|
|
isValid: true,
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
});
|
|
}
|
|
|
|
return Promise.resolve({
|
|
containsMilitaryBase: false,
|
|
isValid: false,
|
|
state: null,
|
|
zipCodeCtu: null,
|
|
});
|
|
}),
|
|
|
|
dispatchStoreAction: jest.fn((actionName) => {
|
|
if (actionName === storeActions.GET_MOBILE_FEE_PART) {
|
|
return Promise.resolve({
|
|
data: {
|
|
partNumber: "MOBILE FEE",
|
|
description: "MOBILE FEE",
|
|
partType: "FEE",
|
|
},
|
|
});
|
|
}
|
|
|
|
if (actionName === storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA) {
|
|
return Promise.resolve([
|
|
{
|
|
partNumber: "MOBILE FEE",
|
|
description: "MOBILE FEE",
|
|
partType: "FEE",
|
|
laborAmount: 49.99,
|
|
sellingPrice: 0,
|
|
kitPrice: 0,
|
|
},
|
|
]);
|
|
}
|
|
}),
|
|
|
|
getTotalLineItemPrice: jest.fn((lineItem) => {
|
|
return 49.99;
|
|
}),
|
|
},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
store.getters = {
|
|
lineItems: {
|
|
supportingItems: [
|
|
{
|
|
description: null,
|
|
kitPrice: 0,
|
|
laborAmount: 0,
|
|
partNumber: "SUPPLIES-REPAIR",
|
|
partType: "REPAIR FEE",
|
|
sellingPrice: 7.99,
|
|
},
|
|
],
|
|
},
|
|
order: {
|
|
serviceLocation: {
|
|
zipCode: "43235",
|
|
state: "OH",
|
|
},
|
|
},
|
|
payment: {
|
|
isInsurance: false,
|
|
},
|
|
vehicle: {
|
|
registration: {
|
|
address: "5555 Sulgrave Dr",
|
|
city: "New Albany",
|
|
state: "OH",
|
|
zipCode: "43054",
|
|
},
|
|
},
|
|
};
|
|
});
|
|
|
|
describe("service-location.vue", () => {
|
|
describe("beforeRouteEnter", () => {
|
|
test("on load sets the mobile fee part when an service zip code has already been provided", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
const mobileFeePart = {
|
|
partNumber: "MOBILE FEE",
|
|
description: "MOBILE FEE",
|
|
partType: "FEE",
|
|
laborAmount: 49.99,
|
|
sellingPrice: 0,
|
|
kitPrice: 0,
|
|
};
|
|
|
|
// Act
|
|
await serviceLocation.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "serviceLocation" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mobileLocationQuestions.mobileFeePart).toStrictEqual(mobileFeePart);
|
|
});
|
|
});
|
|
|
|
describe("arePagePrerequisitesValid", () => {
|
|
test("No prerequisites set: Should return false.", () => {
|
|
const { wrapper } = setupMocks({});
|
|
|
|
store.getters = {
|
|
lineItems: {
|
|
supportingItems: null,
|
|
},
|
|
order: {
|
|
serviceLocation: {
|
|
zipCode: null,
|
|
},
|
|
},
|
|
payment: {
|
|
isInsurance: null,
|
|
},
|
|
};
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(false);
|
|
});
|
|
|
|
test("All prerequisites set: Should return true.", () => {
|
|
const { wrapper } = setupMocks({});
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(true);
|
|
});
|
|
|
|
test("Some prerequisites set: Should return false.", () => {
|
|
const { wrapper } = setupMocks({});
|
|
|
|
store.getters.order.serviceLocation.zipCode = null;
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("updating service zip", () => {
|
|
test("updates the page model after providing the service zip code", () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn();
|
|
|
|
const newServiceZipCodeQuestion = {
|
|
zipCode: "61606",
|
|
state: "IL",
|
|
};
|
|
|
|
const serviceZipCodeComponent = wrapper.findComponent({
|
|
ref: "serviceZipCodeQuestion",
|
|
});
|
|
|
|
// Act
|
|
serviceZipCodeComponent.vm.$emit("update:modelValue", newServiceZipCodeQuestion);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.serviceZipCodeQuestion).toStrictEqual(newServiceZipCodeQuestion);
|
|
});
|
|
|
|
test("resets mobile location when service zip code is updated", () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn();
|
|
wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn();
|
|
|
|
const newServiceZipCodeQuestion = {
|
|
zipCode: "61606",
|
|
state: "IL",
|
|
};
|
|
|
|
const mobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "5555 Sulgrave Dr",
|
|
apartmentNumberOrBusinessName: "Apt 1",
|
|
city: "New Albany",
|
|
state: "OH",
|
|
zipCode: "43054",
|
|
},
|
|
isVehicleProtected: true,
|
|
mobileFeePart: null,
|
|
};
|
|
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
|
|
|
|
const newMobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "",
|
|
apartmentNumberOrBusinessName: "",
|
|
city: "",
|
|
state: "IL",
|
|
zipCode: "61606",
|
|
},
|
|
isVehicleProtected: null,
|
|
mobileFeePart: null,
|
|
};
|
|
|
|
const serviceZipCodeComponent = wrapper.findComponent({
|
|
ref: "serviceZipCodeQuestion",
|
|
});
|
|
|
|
// Act
|
|
serviceZipCodeComponent.vm.$emit("update:modelValue", newServiceZipCodeQuestion);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mobileLocationQuestions).toStrictEqual(newMobileLocationQuestions);
|
|
});
|
|
});
|
|
|
|
describe("updating mobile location", () => {
|
|
test("updates the page model after providing the mobile location", () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn();
|
|
|
|
const mobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "",
|
|
apartmentNumberOrBusinessName: "",
|
|
city: "",
|
|
state: "",
|
|
zipCode: "",
|
|
},
|
|
isVehicleProtected: null,
|
|
mobileFeePart: null,
|
|
};
|
|
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
|
|
|
|
const newMobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "5555 Sulgrave Dr",
|
|
apartmentNumberOrBusinessName: "Apt 1",
|
|
city: "New Albany",
|
|
state: "OH",
|
|
zipCode: "43054",
|
|
},
|
|
isVehicleProtected: true,
|
|
mobileFeePart: null,
|
|
};
|
|
|
|
const mobileLocationComponent = wrapper.findComponent({
|
|
ref: "mobileLocationModalQuestions",
|
|
});
|
|
|
|
// Act
|
|
mobileLocationComponent.vm.$emit("update:modelValue", newMobileLocationQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.mobileLocationQuestions).toStrictEqual(newMobileLocationQuestions);
|
|
});
|
|
|
|
test("resets service zip code when mobile location is updated", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn();
|
|
wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn();
|
|
|
|
const mobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "",
|
|
apartmentNumberOrBusinessName: "",
|
|
city: "",
|
|
state: "",
|
|
zipCode: "",
|
|
},
|
|
isVehicleProtected: null,
|
|
mobileFeePart: null,
|
|
};
|
|
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
|
|
|
|
const newMobileLocationQuestions = {
|
|
addressQuestions: {
|
|
streetAddress: "5555 Rustic Dr",
|
|
apartmentNumberOrBusinessName: "Apt 1",
|
|
city: "Westerville",
|
|
state: "OH",
|
|
zipCode: "43081",
|
|
},
|
|
isVehicleProtected: true,
|
|
mobileFeePart: null,
|
|
};
|
|
|
|
const mobileLocationComponent = wrapper.findComponent({
|
|
ref: "mobileLocationModalQuestions",
|
|
});
|
|
|
|
wrapper.vm.serviceZipCodeQuestion = {
|
|
zipCode: "61606",
|
|
state: "IL",
|
|
};
|
|
|
|
const newServiceZipCodeInfo = {
|
|
state: "OH",
|
|
zipCode: "43081",
|
|
};
|
|
|
|
// Act
|
|
mobileLocationComponent.vm.$emit("update:modelValue", newMobileLocationQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.serviceZipCodeQuestion).toStrictEqual(newServiceZipCodeInfo);
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupMocks({ mountOptionsMockData = {} }) {
|
|
const apiResponses = {};
|
|
|
|
const apiPromise = Promise.resolve(apiResponses);
|
|
|
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
|
const wrapper = shallowMount(serviceLocation, mountOptions);
|
|
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
|
|
|
return { wrapper, apiPromise };
|
|
}
|