Merge pull request #2305 from Safelite/Feature/Digital/CASH-170
CASH-170
This commit is contained in:
commit
5831ad9803
4 changed files with 31 additions and 64 deletions
|
|
@ -203,7 +203,7 @@ describe("mobile-location-modal-questions.vue", () => {
|
|||
expect(wrapper.vm.$refs.MobileLocationModalWidget.openModal).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Should emit updated-mobile-location-questions on setMobileLocation for a valid address and vehicle protection answer", async () => {
|
||||
it("Should emit setMobileLocationAndProceed on setMobileLocation for a valid address and vehicle protection answer", async () => {
|
||||
// Arrange
|
||||
const mobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
|
|
@ -240,26 +240,19 @@ describe("mobile-location-modal-questions.vue", () => {
|
|||
});
|
||||
wrapper.vm.$refs.MobileLocationModalWidget.closeModal = jest.fn();
|
||||
|
||||
// Mock the emitEvent function
|
||||
wrapper.vm.emitEvent = jest.fn(async (eventName, payload) => {
|
||||
return new Promise((resolve) => {
|
||||
wrapper.vm.$emit(eventName, newMobileLocationQuestions, resolve);
|
||||
resolve(newMobileLocationQuestions);
|
||||
});
|
||||
});
|
||||
// Act
|
||||
wrapper.vm.internalModel = newMobileLocationQuestions;
|
||||
|
||||
await wrapper.vm.setMobileLocation();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted()["updated-mobile-location-questions"]).toBeTruthy();
|
||||
expect(wrapper.emitted()["updated-mobile-location-questions"][0][0]).toBe(
|
||||
expect(wrapper.emitted()["setMobileLocationAndProceed"]).toBeTruthy();
|
||||
expect(wrapper.emitted()["setMobileLocationAndProceed"][0][0]).toStrictEqual(
|
||||
newMobileLocationQuestions
|
||||
);
|
||||
});
|
||||
|
||||
it("Should not emit updated-mobile-location-questions on setMobileLocation for an invalid address zip code", async () => {
|
||||
it("Should not emit setMobileLocationAndProceed on setMobileLocation for an invalid address zip code", async () => {
|
||||
// Arrange
|
||||
const mobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
|
|
@ -302,7 +295,7 @@ describe("mobile-location-modal-questions.vue", () => {
|
|||
await wrapper.vm.setMobileLocation();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted("updated-mobile-location-questions")).not.toBeTruthy();
|
||||
expect(wrapper.emitted("setMobileLocationAndProceed")).not.toBeTruthy();
|
||||
});
|
||||
|
||||
it("Should display invalid zip alert for invalid address zip inputs", async () => {
|
||||
|
|
|
|||
|
|
@ -97,8 +97,7 @@ export default {
|
|||
"updated-mobile-fee-part",
|
||||
"updated-contains-military-base",
|
||||
"updated-bill-to-account-number",
|
||||
"mobileLocationSelected",
|
||||
"updated-mobile-location-questions",
|
||||
"setMobileLocationAndProceed",
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
|
|
@ -287,15 +286,7 @@ export default {
|
|||
this.$emit("updated-bill-to-account-number", billToAccountNumber);
|
||||
}
|
||||
// update the page level model
|
||||
await this.emitEvent("updated-mobile-location-questions", this.internalModel);
|
||||
|
||||
this.$emit("mobileLocationSelected");
|
||||
},
|
||||
//creating emitEvent function to raise events with resolve callback to handle events sequencing
|
||||
async emitEvent(eventName, payload) {
|
||||
return new Promise((resolve) => {
|
||||
this.$emit(eventName, payload, resolve);
|
||||
});
|
||||
this.$emit("setMobileLocationAndProceed", this.internalModel);
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
|
|
|
|||
|
|
@ -435,6 +435,7 @@ describe("service-location.vue", () => {
|
|||
ref: "serviceZipCodeQuestion",
|
||||
});
|
||||
serviceZipCodeComponent.resetMobileFeePart = jest.fn();
|
||||
wrapper.vm.forwardButtonAction = jest.fn();
|
||||
|
||||
const mobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
|
|
@ -447,7 +448,6 @@ describe("service-location.vue", () => {
|
|||
isVehicleProtected: null,
|
||||
};
|
||||
wrapper.vm.mobileLocationQuestions = mobileLocationQuestions;
|
||||
|
||||
const newMobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
streetAddress: "5555 Sulgrave Dr",
|
||||
|
|
@ -461,21 +461,13 @@ describe("service-location.vue", () => {
|
|||
|
||||
// Act
|
||||
|
||||
// Mock the emitEvent function
|
||||
mobileLocationQuestionsComponent.vm.emitEvent = jest.fn(async (eventName, payload) => {
|
||||
return new Promise((resolve) => {
|
||||
mobileLocationQuestionsComponent.vm.$emit(eventName, payload, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
// Trigger the event
|
||||
await mobileLocationQuestionsComponent.vm.emitEvent(
|
||||
"updated-mobile-location-questions",
|
||||
await mobileLocationQuestionsComponent.vm.$emit(
|
||||
"setMobileLocationAndProceed",
|
||||
newMobileLocationQuestions
|
||||
);
|
||||
|
||||
await wrapper.vm.$nextTick(); // Wait for DOM updates
|
||||
await new Promise((resolve) => setTimeout(resolve, 0)); // Wait for promise to resolve
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.mobileLocationQuestions).toStrictEqual(newMobileLocationQuestions);
|
||||
|
|
@ -502,7 +494,7 @@ describe("service-location.vue", () => {
|
|||
ref: "serviceZipCodeQuestion",
|
||||
});
|
||||
serviceZipCodeComponent.resetMobileFeePart = jest.fn();
|
||||
|
||||
wrapper.vm.forwardButtonAction = jest.fn();
|
||||
const mobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
streetAddress: "",
|
||||
|
|
@ -542,21 +534,13 @@ describe("service-location.vue", () => {
|
|||
|
||||
// Act
|
||||
|
||||
// Mock the emitEvent function
|
||||
mobileLocationQuestionsComponent.vm.emitEvent = jest.fn(async (eventName, payload) => {
|
||||
return new Promise((resolve) => {
|
||||
mobileLocationQuestionsComponent.vm.$emit(eventName, payload, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
// Trigger the event
|
||||
await mobileLocationQuestionsComponent.vm.emitEvent(
|
||||
"updated-mobile-location-questions",
|
||||
await mobileLocationQuestionsComponent.vm.$emit(
|
||||
"setMobileLocationAndProceed",
|
||||
newMobileLocationQuestions
|
||||
);
|
||||
|
||||
await wrapper.vm.$nextTick(); // Wait for DOM updates
|
||||
await new Promise((resolve) => setTimeout(resolve, 0)); // Wait for promise to resolve
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.serviceZipCodeQuestion).toStrictEqual(newServiceZipCodeInfo);
|
||||
|
|
@ -578,6 +562,7 @@ describe("service-location.vue", () => {
|
|||
ref: "mobileLocationQuestions",
|
||||
});
|
||||
mobileLocationQuestionsComponent.resetComponent = jest.fn();
|
||||
wrapper.vm.forwardButtonAction = jest.fn();
|
||||
|
||||
const serviceZipCodeComponent = wrapper.findComponent({
|
||||
ref: "serviceZipCodeQuestion",
|
||||
|
|
@ -596,7 +581,10 @@ describe("service-location.vue", () => {
|
|||
};
|
||||
|
||||
// Act
|
||||
mobileLocationQuestionsComponent.vm.$emit("update:modelValue", mobileLocationQuestions);
|
||||
mobileLocationQuestionsComponent.vm.$emit(
|
||||
"setMobileLocationAndProceed",
|
||||
mobileLocationQuestions
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.selectedAppointmentType).toStrictEqual("Mobile");
|
||||
|
|
@ -1429,6 +1417,5 @@ function setupMocks({ mountOptionsMockData = {} }) {
|
|||
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||
const wrapper = shallowMount(serviceLocation, mountOptions);
|
||||
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||
|
||||
return { wrapper, apiPromise };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,12 +93,11 @@
|
|||
@updated-serviceability="setServiceabilityDetails"
|
||||
@updated-contains-military-base="setContainsMilitaryBase"
|
||||
@updated-mobile-ctu="setCtuForMobile"
|
||||
@updated-mobile-location-questions="setMobileLocationQuestions"
|
||||
validationRules="mobile-location-required"
|
||||
ref="mobileLocationQuestions"
|
||||
linkWidgetName="MobileLocationLinkWidget"
|
||||
modalWidgetName="MobileLocationModalWidget"
|
||||
@mobileLocationSelected="forwardButtonAction" />
|
||||
@setMobileLocationAndProceed="setMobileLocationQuestions" />
|
||||
|
||||
<shopQuestion
|
||||
ref="shopQuestion"
|
||||
|
|
@ -295,19 +294,6 @@ export default {
|
|||
isVehicleProtected: this.isVehicleProtected,
|
||||
};
|
||||
},
|
||||
async set(newValue) {
|
||||
if (newValue.addressQuestions.zipCode !== this.zipCode) {
|
||||
await getShopProviderData(newValue.addressQuestions.zipCode).then((result) => {
|
||||
this.shopProviderData = result.data;
|
||||
this.selectedProvider = new Provider(
|
||||
this.shopProviderData.mobileProviderNumber
|
||||
);
|
||||
});
|
||||
}
|
||||
this.setMobileLocation(newValue);
|
||||
//handle promise
|
||||
newValue.resolve?.();
|
||||
},
|
||||
},
|
||||
isServiceableMobile() {
|
||||
if (this.isRecalibrationServiceableMobile !== null) {
|
||||
|
|
@ -488,8 +474,18 @@ export default {
|
|||
this.mobileFeePart = mobileFeePart;
|
||||
},
|
||||
//creating async function as the computed property can not directly handle asynchronous operations or promises.
|
||||
async setMobileLocationQuestions(newValue, resolve) {
|
||||
this.mobileLocationQuestions = { ...newValue, resolve };
|
||||
async setMobileLocationQuestions(newValue) {
|
||||
if (newValue.addressQuestions.zipCode !== this.zipCode) {
|
||||
await getShopProviderData(newValue.addressQuestions.zipCode).then((result) => {
|
||||
this.shopProviderData = result.data;
|
||||
this.selectedProvider = new Provider(
|
||||
this.shopProviderData.mobileProviderNumber
|
||||
);
|
||||
});
|
||||
}
|
||||
this.setMobileLocation(newValue);
|
||||
//proceed to next page
|
||||
this.forwardButtonAction();
|
||||
},
|
||||
getServiceAddressFromStore() {
|
||||
return store.getters.order.serviceLocation.address;
|
||||
|
|
|
|||
Loading…
Reference in a new issue