This commit is contained in:
Sneha 2023-11-24 11:35:44 +05:30
parent af512667f0
commit 1945bb02d9
2 changed files with 66 additions and 23 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,7 +22,7 @@
<alert
ref="alertInvalidPromo"
v-if="displayInvalidPromoAlert"
v-html="InvalidPromoText"
v-html="errorMessage"
class="my-4 alert"
cmsWidgetName="AlertInvalidPromoWidget"
alertClass="alert-danger"
@ -35,11 +35,19 @@
alertClass="alert-danger"
v-bind:isDismissible="false" />
<alert
ref="alertInvalidPromoOnOrder"
v-if="displayInvalidOnOrderPromoAlert"
v-html="InvalidPromoOnOrderText"
ref="alertInvalidStackingPromo"
v-if="displayStackingPromoAlert"
v-html="errorMessage"
class="my-4 alert"
cmsWidgetName="AlertInvalidPromoOnOrderWidget"
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">
@ -78,9 +86,11 @@ export default {
return {
promoCode: "",
promoTextInputId: "",
errorMessage: "",
displayInvalidPromoAlert: false,
displaySimilarPromoAlert: false,
displayInvalidOnOrderPromoAlert: false,
displayStackingPromoAlert: false,
displayInShopPromoAlert: false,
lineItems: deepClone(this.modelValue),
};
},
@ -105,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");
@ -126,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();
@ -138,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;
@ -194,10 +209,35 @@ export default {
switch (error) {
case promoErrorCodes.PROMO_STACKING_NOT_ALLOWED:
case promoErrorCodes.SIMILAR_PROMO_ALREADY_ON_ORDER:
if (additionalInfo[0] === this.promoCode.toUpperCase())
if (
additionalInfo.length === 1 &&
additionalInfo[0] === this.promoCode.toUpperCase()
) {
return (this.displaySimilarPromoAlert = true);
return (this.displayInvalidOnOrderPromoAlert = true);
} else {
this.errorMessage = this.StackPromoText?.replaceAll(
"{custom:NEWPROMOCODE}",
this.promoCode.toUpperCase()
).replaceAll(
"{custom:OLDPROMOCODE}",
this.getConflictingPromoCode(additionalInfo)
);
return (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);
}
},
@ -257,8 +297,9 @@ export default {
watch: {
promoCode() {
this.displayInvalidPromoAlert = false;
this.displayInvalidOnOrderPromoAlert = false;
this.displayStackingPromoAlert = false;
this.displaySimilarPromoAlert = false;
this.displayInShopPromoAlert = false;
},
modelValue: {
handler(newValue) {