Merge pull request #1567 from Safelite/feature/CSR-1827

error message
This commit is contained in:
AMSNEHA 2023-11-24 14:49:40 +05:30 committed by GitHub
commit b28349057b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 28 deletions

View file

@ -49,7 +49,9 @@ describe("promo-modal-question.vue", () => {
// Assert
expect(wrapper.vm.displayInvalidPromoAlert).toBe(false);
expect(wrapper.vm.displayInvalidOnOrderPromoAlert).toBe(false);
expect(wrapper.vm.displayStackingPromoAlert).toBe(false);
expect(wrapper.vm.displayInShopPromoAlert).toBe(false);
expect(wrapper.vm.displaySimilarPromoAlert).toBe(false);
});
it("Should emit update:modelValue on Modal closed", async () => {
// Arrange

View file

@ -22,19 +22,34 @@
<alert
ref="alertInvalidPromo"
v-if="displayInvalidPromoAlert"
v-html="InvalidPromoText"
v-html="errorMessage"
class="my-4 alert"
cmsWidgetName="AlertInvalidPromoWidget"
alertClass="alert-danger"
v-bind:isDismissible="true" />
v-bind:isDismissible="false" />
<alert
ref="alertInvalidPromoOnOrder"
v-if="displayInvalidOnOrderPromoAlert"
v-html="InvalidPromoOnOrderText"
ref="AlertSimilarPromo"
v-if="displaySimilarPromoAlert"
class="my-4 alert"
cmsWidgetName="AlertInvalidPromoOnOrderWidget"
cmsWidgetName="AlertSimilarPromoWidget"
alertClass="alert-danger"
v-bind:isDismissible="true" />
v-bind:isDismissible="false" />
<alert
ref="alertInvalidStackingPromo"
v-if="displayStackingPromoAlert"
v-html="errorMessage"
class="my-4 alert"
cmsWidgetName="AlertStackingPromoWidget"
alertClass="alert-danger"
v-bind:isDismissible="false" />
<alert
ref="AlertInShopPromo"
v-if="displayInShopPromoAlert"
v-html="errorMessage"
class="my-4 alert"
cmsWidgetName="AlertInshopPromoWidget"
alertClass="alert-danger"
v-bind:isDismissible="false" />
<div v-for="(promoCode, i) in this.getPromoCodeList()" :key="i">
<span class="applied-promo">Promo code "{{ promoCode }}" applied </span>
<textLink
@ -71,8 +86,11 @@ export default {
return {
promoCode: "",
promoTextInputId: "",
errorMessage: "",
displayInvalidPromoAlert: false,
displayInvalidOnOrderPromoAlert: false,
displaySimilarPromoAlert: false,
displayStackingPromoAlert: false,
displayInShopPromoAlert: false,
lineItems: deepClone(this.modelValue),
};
},
@ -97,20 +115,14 @@ export default {
modal() {
return this.$refs[this.modalName];
},
PromoOnOrderText() {
return this.getCmsContent("AlertInvalidPromoOnOrderWidget", "HeadlineText");
},
InvalidPromoOnOrderText() {
return this.PromoOnOrderText?.replaceAll(
"{custom:NEWPROMOCODE}",
this.promoCode.toUpperCase()
).replaceAll("{custom:OLDPROMOCODE}", this.getPromoCode()?.toUpperCase());
StackPromoText() {
return this.getCmsContent("AlertStackingPromoWidget", "HeadlineText");
},
PromoText() {
return this.getCmsContent("AlertInvalidPromoWidget", "HeadlineText");
},
InvalidPromoText() {
return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode.toUpperCase());
InShopPromoText() {
return this.getCmsContent("AlertInshopPromoWidget", "HeadlineText");
},
removeLinkText() {
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
@ -118,8 +130,11 @@ export default {
},
methods: {
resetAlerts() {
this.displayInvalidOnOrderPromoAlert = false;
this.displayStackingPromoAlert = false;
this.displayInvalidPromoAlert = false;
this.displaySimilarPromoAlert = false;
this.displayInShopPromoAlert = false;
this.errorMessage = "";
},
resetsOnPromoInput() {
this.resetAlerts();
@ -130,8 +145,16 @@ export default {
);
return promosToDisplay;
},
getPromoCode() {
return this.lineItems.promos?.[0]?.promoCode;
getConflictingPromoCode(additionalInfo) {
var conflictingCodes = additionalInfo?.[0];
if (additionalInfo?.length > 1) {
if (additionalInfo?.length > 2) conflictingCodes += ",";
for (let i = 1; i < additionalInfo?.length - 1; i++) {
conflictingCodes += ` "${additionalInfo[i]}",`;
}
conflictingCodes += ` and "${additionalInfo?.slice(-1)[0]}"`;
}
return conflictingCodes;
},
onInputIdAssigned(inputId) {
this.promoTextInputId = inputId;
@ -171,6 +194,7 @@ export default {
isValid: !("errorCode" in promoValidationResponse),
promoCode: promoValidationResponse?.orderPromos,
errorCode: promoValidationResponse?.errorCode,
additionalInfo: promoValidationResponse?.additionalInfo,
};
},
removeItem(promo) {
@ -181,6 +205,38 @@ export default {
getPromoCodeWithoutBundleIdentifier(lineItemsToKeep.promoCode) != promo
);
},
getErrorMessage(error, additionalInfo) {
switch (error) {
case promoErrorCodes.PROMO_STACKING_NOT_ALLOWED:
case promoErrorCodes.SIMILAR_PROMO_ALREADY_ON_ORDER:
return additionalInfo.length === 1 &&
additionalInfo[0] === this.promoCode.toUpperCase()
? (this.displaySimilarPromoAlert = true)
: ((this.errorMessage = this.StackPromoText?.replace(
/\{custom:(NEW|OLD)PROMOCODE\}/g,
(match, group) =>
group === "NEW"
? this.promoCode.toUpperCase()
: this.getConflictingPromoCode(additionalInfo)
)),
(this.displayStackingPromoAlert = true));
case promoErrorCodes.INVALID_PROMO_ON_ORDER:
if (additionalInfo.some((x) => x.toUpperCase() === "APPOINTMENT_TYPE")) {
this.errorMessage = this.InShopPromoText?.replaceAll(
"{custom:INSHOPPROMOCODE}",
this.promoCode.toUpperCase()
);
return (this.displayInShopPromoAlert = true);
}
break;
default:
this.errorMessage = this.PromoText?.replaceAll(
"{custom:PROMOCODE}",
this.promoCode.toUpperCase()
);
return (this.displayInvalidPromoAlert = true);
}
},
async addPromoCode() {
if (this.promoCode) {
this.resetAlerts();
@ -227,11 +283,7 @@ export default {
this.lineItems.vaps?.push(...getVaps);
this.closeModal();
} else {
if (promoCodeData.errorCode == promoErrorCodes.PROMO_STACKING_NOT_ALLOWED) {
this.displayInvalidOnOrderPromoAlert = true;
} else {
this.displayInvalidPromoAlert = true;
}
this.getErrorMessage(promoCodeData.errorCode, promoCodeData.additionalInfo);
this.focusOnPromoInput();
this.resetModalButtonStyle();
}
@ -241,7 +293,9 @@ export default {
watch: {
promoCode() {
this.displayInvalidPromoAlert = false;
this.displayInvalidOnOrderPromoAlert = false;
this.displayStackingPromoAlert = false;
this.displaySimilarPromoAlert = false;
this.displayInShopPromoAlert = false;
},
modelValue: {
handler(newValue) {