Preparing for additional unit tests of page and mobile location component
This commit is contained in:
parent
e05a1bf51b
commit
8d8d253bfc
4 changed files with 113 additions and 27 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
|
|
||||||
export async function getMobileFee(serviceZipCode) {
|
export async function getPricedMobileFeePart(serviceZipCode) {
|
||||||
if (!serviceZipCode) {
|
if (!serviceZipCode) {
|
||||||
return 0;
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode);
|
const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode);
|
||||||
|
|
@ -26,5 +26,5 @@ export async function getMobileFee(serviceZipCode) {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
return Promise.resolve(baseMixin.methods.getTotalLineItemPrice(pricingResults[0]));
|
return Promise.resolve(pricingResults[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,78 @@
|
||||||
test.todo("some test to be written in the future");
|
import { getPricedMobileFeePart } from "./service-location-helper";
|
||||||
|
import { storeActions } from "@/constants/store-actions";
|
||||||
|
|
||||||
|
const mockStoreActionGetMobileFeePart = storeActions.GET_MOBILE_FEE_PART;
|
||||||
|
const mockStoreActionPriceOrderItemsAndSaveServerData = storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA;
|
||||||
|
|
||||||
|
jest.mock("@/mixins/base-mixin.js", () => ({
|
||||||
|
methods: {
|
||||||
|
getZipCodeData: jest.fn().mockImplementation(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
containsMilitaryBase: false,
|
||||||
|
isServiceable: true,
|
||||||
|
isValid: true,
|
||||||
|
state: "OH",
|
||||||
|
zipCodeCtu: "01820",
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
dispatchStoreAction: jest.fn().mockImplementation((actionName) => {
|
||||||
|
if (actionName === mockStoreActionGetMobileFeePart) {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: {
|
||||||
|
partNumber: "MOBILE FEE",
|
||||||
|
description: "MOBILE FEE",
|
||||||
|
partType: "FEE",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionName === mockStoreActionPriceOrderItemsAndSaveServerData) {
|
||||||
|
return Promise.resolve([
|
||||||
|
{
|
||||||
|
partNumber: "MOBILE FEE",
|
||||||
|
description: "MOBILE FEE",
|
||||||
|
partType: "FEE",
|
||||||
|
laborAmount: 49.99,
|
||||||
|
sellingPrice: 0,
|
||||||
|
kitPrice: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("service-location-helper.js", () => {
|
||||||
|
it("Should return the null if no service zip code is passed in", async() => {
|
||||||
|
// Arrange / Act
|
||||||
|
const serviceZipCode = null;
|
||||||
|
const expected = null;
|
||||||
|
|
||||||
|
const result = await getPricedMobileFeePart(serviceZipCode);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return the priced mobile fee part", async() => {
|
||||||
|
// Arrange / Act
|
||||||
|
const serviceZipCode = "43235";
|
||||||
|
const expected = {
|
||||||
|
partNumber: "MOBILE FEE",
|
||||||
|
description: "MOBILE FEE",
|
||||||
|
partType: "FEE",
|
||||||
|
laborAmount: 49.99,
|
||||||
|
sellingPrice: 0,
|
||||||
|
kitPrice: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await getPricedMobileFeePart(serviceZipCode);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
//test.todo("some test to be written in the future");
|
||||||
|
|
|
||||||
|
|
@ -109,14 +109,21 @@ export default {
|
||||||
},
|
},
|
||||||
mobileFeeText() {
|
mobileFeeText() {
|
||||||
const cmsContentText = this.getCmsContent("MobileFeeDisclaimerWidget", "Text");
|
const cmsContentText = this.getCmsContent("MobileFeeDisclaimerWidget", "Text");
|
||||||
if (this.modelValue.mobileFee === undefined) {
|
return cmsContentText.replaceAll("{custom:mobileFee}", this.mobileFee);
|
||||||
return cmsContentText.replaceAll("{custom:mobileFee}", 0);
|
|
||||||
}
|
|
||||||
return cmsContentText.replaceAll("{custom:mobileFee}", this.modelValue.mobileFee);
|
|
||||||
},
|
},
|
||||||
modalFooterText() {
|
modalFooterText() {
|
||||||
return this.getCmsContent(this.modalWidgetName, "FooterText");
|
return this.getCmsContent(this.modalWidgetName, "FooterText");
|
||||||
},
|
},
|
||||||
|
mobileFee() {
|
||||||
|
if (!this.modelValue.mobileFeePart) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
this.modelValue.mobileFeePart.laborAmount +
|
||||||
|
this.modelValue.mobileFeePart.sellingPrice +
|
||||||
|
this.modelValue.mobileFeePart.kitPrice
|
||||||
|
);
|
||||||
|
},
|
||||||
addressModel: {
|
addressModel: {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.modelValue.addressQuestions;
|
return this.modelValue.addressQuestions;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<funnelSubHeader cmsWidgetName="FunnelSubHeaderWidget" />
|
<funnelSubHeader cmsWidgetName="FunnelSubHeaderWidget" />
|
||||||
<serviceZipModalQuestion
|
<serviceZipModalQuestion
|
||||||
v-model="serviceZipCodeQuestion"
|
v-model="serviceZipCodeQuestion"
|
||||||
@updated-service-zip-code="recalculateMobileFee"
|
@updated-service-zip-code="resetMobileFeePart"
|
||||||
ref="serviceZipCodeQuestion"
|
ref="serviceZipCodeQuestion"
|
||||||
linkWidgetName="ServiceZipLinkWidget"
|
linkWidgetName="ServiceZipLinkWidget"
|
||||||
modalWidgetName="ServiceZipModalWidget" />
|
modalWidgetName="ServiceZipModalWidget" />
|
||||||
|
|
@ -38,7 +38,7 @@ import { Form } from "vee-validate";
|
||||||
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||||
import { settleAllPromises } from "@/helpers/layout-helper";
|
import { settleAllPromises } from "@/helpers/layout-helper";
|
||||||
import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper";
|
import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper";
|
||||||
import { getMobileFee } from "@/helpers/service-location-helper";
|
import { getPricedMobileFeePart } from "@/helpers/service-location-helper";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -71,7 +71,7 @@ export default {
|
||||||
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
||||||
|
|
||||||
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
||||||
const mobileFeePromise = getMobileFee(serviceZipCode);
|
const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode);
|
||||||
|
|
||||||
// Settle promises and get results
|
// Settle promises and get results
|
||||||
const promiseResultMap = [
|
const promiseResultMap = [
|
||||||
|
|
@ -80,17 +80,19 @@ export default {
|
||||||
promise: cmsContentPromise,
|
promise: cmsContentPromise,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
resultKey: "mobileFee",
|
resultKey: "mobileFeePart",
|
||||||
promise: mobileFeePromise,
|
promise: mobileFeePartPromise,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const resultMap = await settleAllPromises(promiseResultMap);
|
const resultMap = await settleAllPromises(promiseResultMap);
|
||||||
|
console.log(resultMap);
|
||||||
|
console.log(resultMap.cmsContent);
|
||||||
|
console.log(resultMap.mobileFeePart);
|
||||||
// Call the "next" function to complete the transition to this page.
|
// Call the "next" function to complete the transition to this page.
|
||||||
next((vm) => {
|
next((vm) => {
|
||||||
vm.setCmsContent(resultMap.cmsContent);
|
vm.setCmsContent(resultMap.cmsContent);
|
||||||
vm.setData(resultMap.mobileFee);
|
vm.setData(resultMap.mobileFeePart);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -102,9 +104,9 @@ export default {
|
||||||
// store.getters.payment.isInsurance !== null
|
// store.getters.payment.isInsurance !== null
|
||||||
// );
|
// );
|
||||||
},
|
},
|
||||||
setData(mobileFee) {
|
setData(mobileFeePart) {
|
||||||
if (mobileFee) {
|
if (mobileFeePart) {
|
||||||
this.mobileLocationQuestions.mobileFee = mobileFee
|
this.mobileLocationQuestions.mobileFeePart = mobileFeePart;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getRegistrationAddressFromStore() {
|
getRegistrationAddressFromStore() {
|
||||||
|
|
@ -128,9 +130,9 @@ export default {
|
||||||
getIsServiceableFromStore() {
|
getIsServiceableFromStore() {
|
||||||
return store.getters.order.serviceLocation.isServiceable;
|
return store.getters.order.serviceLocation.isServiceable;
|
||||||
},
|
},
|
||||||
recalculateMobileFee(serviceZipCode) {
|
resetMobileFeePart(serviceZipCode) {
|
||||||
getMobileFee(serviceZipCode).then((mobileFee) => {
|
getPricedMobileFeePart(serviceZipCode).then((pricedMobileFeePart) => {
|
||||||
this.mobileLocationQuestions.mobileFee = mobileFee;
|
this.mobileLocationQuestions.mobileFeePart = pricedMobileFeePart;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
resetMobileLocation(updatedServiceZipCode) {
|
resetMobileLocation(updatedServiceZipCode) {
|
||||||
|
|
@ -153,7 +155,7 @@ export default {
|
||||||
this.serviceZipCodeQuestion.zipCode = newValue.zipCode;
|
this.serviceZipCodeQuestion.zipCode = newValue.zipCode;
|
||||||
this.serviceZipCodeQuestion.isServiceable = newValue.isServiceable;
|
this.serviceZipCodeQuestion.isServiceable = newValue.isServiceable;
|
||||||
|
|
||||||
this.recalculateMobileFee(this.serviceZipCodeQuestion.zipCode);
|
this.resetMobileFeePart(this.serviceZipCodeQuestion.zipCode);
|
||||||
},
|
},
|
||||||
backButtonAction() {
|
backButtonAction() {
|
||||||
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
|
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue