simplifying reduce
This commit is contained in:
parent
628a07b30d
commit
8e97a54fbc
2 changed files with 25 additions and 27 deletions
|
|
@ -1125,7 +1125,7 @@ describe('cart-dropdown component', () => {
|
|||
|
||||
// Assert
|
||||
expect(result).toContainEqual(expect.objectContaining({
|
||||
isRecycle: true
|
||||
partType: partTypeStrings.REPLACE_FEE
|
||||
}));
|
||||
});
|
||||
test('when mobileFee, includes mobile fee', () => {
|
||||
|
|
@ -1355,7 +1355,7 @@ describe('cart-dropdown component', () => {
|
|||
// Assert
|
||||
expect(result.length).toBe(3);
|
||||
expect(result).toContainEqual(expect.objectContaining({
|
||||
isRecycle: true
|
||||
partType: partTypeStrings.REPLACE_FEE
|
||||
}));
|
||||
expect(result).toContainEqual(expect.objectContaining({
|
||||
partType: partTypeStrings.MOBILE_FEE
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@
|
|||
linkType="text"
|
||||
text="Remove"
|
||||
href="javascript:void(0)"
|
||||
@clickEvent="removeItem(item.partType, true)">
|
||||
@clickEvent="removeVap(item.partType)">
|
||||
<template #after-text>
|
||||
<span class="sr-only">{{ item?.name ?? '' }}</span>
|
||||
</template>
|
||||
|
|
@ -81,7 +81,7 @@
|
|||
class="px-5 py-1 non-packaged-cart-item">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span
|
||||
v-if="item.isRecycle"
|
||||
v-if="isRecycle(item.partType)"
|
||||
id="recycle-fee-label">
|
||||
<textLink
|
||||
linkType="text"
|
||||
|
|
@ -93,11 +93,11 @@
|
|||
<span>{{ getDisplayed(item?.subTotal ?? 0, false) }}</span>
|
||||
</div>
|
||||
<textLink
|
||||
v-if="item.isRemovable && (!readOnly || !showAsPaid)"
|
||||
v-if="isVap(item.partType) && (!readOnly || !showAsPaid)"
|
||||
linkType="text"
|
||||
text="Remove"
|
||||
href="javascript:void(0)"
|
||||
@clickEvent="removeItem(item.partType, item.isVap)">
|
||||
@clickEvent="removeVap(item.partType)">
|
||||
<template #after-text>
|
||||
<span class="sr-only">{{ item?.name ?? '' }}</span>
|
||||
</template>
|
||||
|
|
@ -368,10 +368,7 @@ export default {
|
|||
? this.getCartItem(
|
||||
this.getCmsContent(this.widget.recycleFee, widgetFields.TEXT_BLOCK_WIDGET.TEXT),
|
||||
[recycleFeeLineItem],
|
||||
false,
|
||||
partTypeStrings.REPLACE_FEE, // NOTE this is not a mistake
|
||||
false,
|
||||
true
|
||||
partTypeStrings.REPLACE_FEE // NOTE this is not a mistake
|
||||
)
|
||||
: null;
|
||||
},
|
||||
|
|
@ -381,10 +378,7 @@ export default {
|
|||
? this.getCartItem(
|
||||
this.getCmsContent(this.widget.mobileFee, widgetFields.TEXT_BLOCK_WIDGET.TEXT),
|
||||
[mobileFeeLineItem],
|
||||
false,
|
||||
partTypeStrings.MOBILE_FEE,
|
||||
false,
|
||||
false
|
||||
partTypeStrings.MOBILE_FEE
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
|
@ -404,7 +398,7 @@ export default {
|
|||
? VERIFYING_COVERAGE
|
||||
: formatAmountInDollars(amount);
|
||||
},
|
||||
getCartItem(label, lineItems, isRemovable, partType, isVap, isRecycle) {
|
||||
getCartItem(label, lineItems, partType) {
|
||||
let cartItem = null;
|
||||
|
||||
if (lineItems && lineItems.length > 0) {
|
||||
|
|
@ -415,10 +409,7 @@ export default {
|
|||
salesTax: lineItems?.reduce(
|
||||
(accumulator, lineItem) => accumulator + lineItem.salesTax,
|
||||
0
|
||||
) ?? 0,
|
||||
isRemovable,
|
||||
isVap,
|
||||
isRecycle
|
||||
) ?? 0
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -428,15 +419,11 @@ export default {
|
|||
const label = this.getCmsContentForVapsType(partType);
|
||||
const lineItems = useMainStore().lineItems.vaps
|
||||
?.filter((vapsLineItem) => vapsLineItem.partType === partType) ?? [];
|
||||
return this.getCartItem(label, lineItems, true, partType, true, false);
|
||||
return this.getCartItem(label, lineItems, partType);
|
||||
},
|
||||
removeItem(partType, isVap) {
|
||||
if (isVap) {
|
||||
const newVaps = useMainStore().lineItems.vaps?.filter((vap) => vap?.partType !== partType) ?? [];
|
||||
console.log(`new vaps: ${JSON.stringify(newVaps)}`);
|
||||
useMainStore().updateVaps(newVaps);
|
||||
}
|
||||
// NOTE Currently only vaps can be removed
|
||||
removeVap(partType) {
|
||||
const newVaps = useMainStore().lineItems.vaps?.filter((vap) => vap?.partType !== partType) ?? [];
|
||||
useMainStore().updateVaps(newVaps);
|
||||
},
|
||||
getCmsContentForVapsType(vapsType) {
|
||||
const vapsItemDescriptions = this.getCmsContent(
|
||||
|
|
@ -451,6 +438,17 @@ export default {
|
|||
const vapsTypeDescription = vapsItemDescriptions?.find((entry) => entry?.Name === vapsType);
|
||||
return vapsTypeDescription?.Text ?? '';
|
||||
},
|
||||
isVap(partType) {
|
||||
const vapPartTypes = [
|
||||
partTypeStrings.FRONT_WIPER,
|
||||
partTypeStrings.REAR_WIPER,
|
||||
partTypeStrings.RAIN_DEFENSE
|
||||
];
|
||||
return vapPartTypes.includes(partType);
|
||||
},
|
||||
isRecycle(partType) {
|
||||
return partTypeStrings.REPLACE_FEE === partType;
|
||||
},
|
||||
formatAmountInDollars
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue