Got unit tests working again

This commit is contained in:
Leah Schumann 2023-03-09 13:38:20 -05:00
parent 4b6be3fa5c
commit 0c6d2cb6e8
8 changed files with 64 additions and 44 deletions

View file

@ -22,6 +22,7 @@
aria-live="polite"> aria-live="polite">
<div class="col"> <div class="col">
<textboxQuestion <textboxQuestion
customInputId="apartmentNumberOrBusinessName"
cmsWidgetName="ApartmentNumberOrBusinessNameQuestionWidget" cmsWidgetName="ApartmentNumberOrBusinessNameQuestionWidget"
v-model="addressModel.apartmentNumberOrBusinessName" v-model="addressModel.apartmentNumberOrBusinessName"
ref="apartmentNumberOrBusinessName" /> ref="apartmentNumberOrBusinessName" />
@ -32,6 +33,7 @@
<div class="row mb-4" v-show="showAddressFields" aria-live="polite"> <div class="row mb-4" v-show="showAddressFields" aria-live="polite">
<div class="col"> <div class="col">
<textboxQuestion <textboxQuestion
customInputId="city"
cmsWidgetName="CityQuestionWidget" cmsWidgetName="CityQuestionWidget"
v-model="addressModel.city" v-model="addressModel.city"
ref="city" ref="city"
@ -43,14 +45,17 @@
<div class="row mb-4" v-show="showAddressFields" aria-live="polite"> <div class="row mb-4" v-show="showAddressFields" aria-live="polite">
<div class="col"> <div class="col">
<dropdownQuestion <dropdownQuestion
customInputId="state"
cmsWidgetName="StateQuestionWidget" cmsWidgetName="StateQuestionWidget"
v-model="addressModel.state" v-model="addressModel.state"
ref="state" ref="state"
:options="stateOptions" :options="stateOptions"
initialValue="FL"
validationRules="state-required" /> validationRules="state-required" />
</div> </div>
<div class="col"> <div class="col">
<textboxQuestion <textboxQuestion
customInputId="zipCode"
cmsWidgetName="ZipQuestionWidget" cmsWidgetName="ZipQuestionWidget"
v-model="addressModel.zipCode" v-model="addressModel.zipCode"
ref="zipCode" ref="zipCode"

View file

@ -1,8 +1,8 @@
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 getPricedMobileFeePart(serviceZipCode) { export async function getPricedMobileFeePart(serviceZipCode, serviceType, parentAccountNumber, billToAccountNumber) {
if (!serviceZipCode) { if (!serviceZipCode || !serviceType || !parentAccountNumber) {
return Promise.resolve(null); return Promise.resolve(null);
} }
@ -11,7 +11,11 @@ export async function getPricedMobileFeePart(serviceZipCode) {
// Get the Mobile Fee Part // Get the Mobile Fee Part
const mobileFeePart = await baseMixin.methods.dispatchStoreAction( const mobileFeePart = await baseMixin.methods.dispatchStoreAction(
storeActions.GET_MOBILE_FEE_PART, storeActions.GET_MOBILE_FEE_PART,
null, {
serviceType: serviceType,
parentAccountNumber: parentAccountNumber,
billToAccountNumber: billToAccountNumber
},
false false
); );

View file

@ -58,8 +58,7 @@ import addressQuestions from "@/layouts/address-lookup/customer-questions/addres
import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question"; import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question";
// Helpers // Helpers
import { deepClone } from "@/helpers/object-cloning-helper"; import { deepClone } from "@/layouts/service-location/helpers/object-cloning-helper/object-cloning-helper";
import { object } from "yup/lib/locale";
export default { export default {
name: "mobile-location-modal-questions", name: "mobile-location-modal-questions",
@ -152,23 +151,19 @@ export default {
closeModal() { closeModal() {
this.$refs[this.modalName].closeModal(); this.$refs[this.modalName].closeModal();
}, },
resetComponent() { resetComponent(updatedServiceZipCodeInfo) {
this.resetModel(); // Reset the validation form, setting the initial values
// for the state and zipCode to those that were entered
// Reset the validation form // on the service-zip-modal-question component
this.$refs[this.modalName].form.resetForm(); this.$refs[this.modalName].form.resetForm({
values: {
// Reinitialize the Address Auto Complete state: updatedServiceZipCodeInfo.state,
this.$refs.addressQuestions.setupAddressLookup(); zipCode: updatedServiceZipCodeInfo.zipCode,
},
});
}, },
resetModel() { onAddressUpdated(updatedServiceZipCodeInfo) {
// Address this.resetComponent(updatedServiceZipCodeInfo);
this.internalModel.addressQuestions.streetAddress = "";
this.internalModel.addressQuestions.apartmentNumberOrBusinessName = "";
this.internalModel.addressQuestions.city = "";
// Is Vehicle Protected
this.internalModel.isVehicleProtected = null;
}, },
async setMobileLocation() { async setMobileLocation() {
// Validate the Zip Code // Validate the Zip Code
@ -189,6 +184,11 @@ export default {
modelValue: { modelValue: {
handler(newValue) { handler(newValue) {
this.internalModel = deepClone(newValue); this.internalModel = deepClone(newValue);
this.resetComponent({
state: newValue.state,
zipCode: newValue.zipCode
})
}, },
deep: true, deep: true,
}, },

View file

@ -32,7 +32,7 @@ const mockGetPricedMobileFeePart = (mockServiceZipCode) => {
return Promise.resolve(mobileFeePart); return Promise.resolve(mobileFeePart);
}; };
jest.mock("@/helpers/service-location-helper", () => ({ jest.mock("@/layouts/service-location/helpers/service-location-helper/service-location-helper", () => ({
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => { getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
return mockGetPricedMobileFeePart(mockServiceZipCode); return mockGetPricedMobileFeePart(mockServiceZipCode);
}), }),
@ -107,6 +107,9 @@ const mockMixin = {
getTotalLineItemPrice: jest.fn((lineItem) => { getTotalLineItemPrice: jest.fn((lineItem) => {
return 49.99; return 49.99;
}), }),
onSubmit: jest.fn(),
onInvalidSubmit: jest.fn(),
}, },
}; };
@ -130,6 +133,9 @@ beforeEach(() => {
state: "OH", state: "OH",
}, },
}, },
damage: {
isRepair: false
},
payment: { payment: {
isInsurance: false, isInsurance: false,
}, },
@ -168,7 +174,7 @@ describe("service-location.vue", () => {
); );
// Assert // Assert
expect(wrapper.vm.mobileLocationQuestions.mobileFeePart).toStrictEqual(mobileFeePart); expect(wrapper.vm.mobileFeePart).toStrictEqual(mobileFeePart);
}); });
}); });
@ -217,7 +223,9 @@ describe("service-location.vue", () => {
describe("updating service zip", () => { describe("updating service zip", () => {
test("updates the page model after providing the service zip code", () => { test("updates the page model after providing the service zip code", () => {
// Arrange // Arrange
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({
mixins: [mockMixin]
});
wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn();
const newServiceZipCodeQuestion = { const newServiceZipCodeQuestion = {
@ -256,7 +264,6 @@ describe("service-location.vue", () => {
zipCode: "43054", zipCode: "43054",
}, },
isVehicleProtected: true, isVehicleProtected: true,
mobileFeePart: null,
}; };
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions; wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
@ -269,7 +276,6 @@ describe("service-location.vue", () => {
zipCode: "61606", zipCode: "61606",
}, },
isVehicleProtected: null, isVehicleProtected: null,
mobileFeePart: null,
}; };
const serviceZipCodeComponent = wrapper.findComponent({ const serviceZipCodeComponent = wrapper.findComponent({
@ -299,7 +305,6 @@ describe("service-location.vue", () => {
zipCode: "", zipCode: "",
}, },
isVehicleProtected: null, isVehicleProtected: null,
mobileFeePart: null,
}; };
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions; wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
@ -312,7 +317,6 @@ describe("service-location.vue", () => {
zipCode: "43054", zipCode: "43054",
}, },
isVehicleProtected: true, isVehicleProtected: true,
mobileFeePart: null,
}; };
const mobileLocationComponent = wrapper.findComponent({ const mobileLocationComponent = wrapper.findComponent({

View file

@ -37,7 +37,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 { getPricedMobileFeePart } from "@/helpers/service-location-helper"; import { getPricedMobileFeePart } from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
import store from "@/store"; import store from "@/store";
export default { export default {
@ -49,6 +49,7 @@ export default {
city: this.getServiceCityFromStore(), city: this.getServiceCityFromStore(),
state: this.getServiceStateFromStore(), state: this.getServiceStateFromStore(),
zipCode: this.getServiceZipCodeFromStore(), zipCode: this.getServiceZipCodeFromStore(),
isVehicleProtected: null,
isZipServiceableMobile: null, isZipServiceableMobile: null,
isZipServiceableInShop: null, isZipServiceableInShop: null,
mobileFeePart: null, mobileFeePart: null,
@ -59,7 +60,11 @@ 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 mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode); const serviceType = store.getters.damage.isRepair ? "Repair" : "Replace";
const parentAccountNumber = store.getters.payment.parentAccountNumber;
const billToAccountNumber = 0;
const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode, serviceType, parentAccountNumber, billToAccountNumber);
// Settle promises and get results // Settle promises and get results
const promiseResultMap = [ const promiseResultMap = [
@ -91,7 +96,7 @@ export default {
}, },
set: function (newValue) { set: function (newValue) {
if (newValue.zipCode !== this.zipCode) { if (newValue.zipCode !== this.zipCode) {
this.resetMobileLocation(newValue.zipCode); this.resetMobileLocation(newValue);
} }
this.state = newValue.state; this.state = newValue.state;
@ -124,12 +129,11 @@ export default {
}, },
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return true; return (
// return ( store.getters.lineItems.supportingItems !== null &&
// store.getters.lineItems.supportingItems !== null && store.getters.order.serviceLocation.zipCode !== null &&
// store.getters.order.serviceLocation.zipCode !== null && store.getters.payment.isInsurance !== null
// store.getters.payment.isInsurance !== null );
// );
}, },
setData(mobileFeePart) { setData(mobileFeePart) {
if (mobileFeePart) { if (mobileFeePart) {
@ -149,19 +153,22 @@ export default {
return store.getters.order.serviceLocation.zipCode; return store.getters.order.serviceLocation.zipCode;
}, },
resetMobileFeePart(serviceZipCode) { resetMobileFeePart(serviceZipCode) {
getPricedMobileFeePart(serviceZipCode).then((pricedMobileFeePart) => { const serviceType = store.getters.damage.isRepair ? "Repair" : "Replace";
const parentAccountNumber = store.getters.payment.parentAccountNumber;
const billToAccountNumber = 0;
getPricedMobileFeePart(serviceZipCode, serviceType, parentAccountNumber, billToAccountNumber).then((pricedMobileFeePart) => {
this.mobileFeePart = pricedMobileFeePart; this.mobileFeePart = pricedMobileFeePart;
}); });
}, },
resetMobileLocation(updatedServiceZipCode) { resetMobileLocation(updatedServiceZipCodeInfo) {
this.streetAddress = ""; this.streetAddress = "";
this.apartmentNumberOrBusinessName = ""; this.apartmentNumberOrBusinessName = "";
this.city = ""; this.city = "";
this.isVehicleProtected = null; this.isVehicleProtected = null;
this.$refs.mobileLocationModalQuestions.resetComponent(); this.resetMobileFeePart(updatedServiceZipCodeInfo.zipCode);
this.resetMobileFeePart(updatedServiceZipCode);
}, },
backButtonAction() { backButtonAction() {
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);