Fix for multiple glass parts

This commit is contained in:
Leah Schumann 2023-11-02 11:18:05 -04:00
parent 32d7ce105f
commit 5b9c47111b
3 changed files with 191 additions and 129 deletions

View file

@ -7,7 +7,6 @@ import { getMountOptions } from "@/helpers/unit-test-helper.js";
describe("cart.vue", () => { describe("cart.vue", () => {
describe("cartItem computeds", () => { describe("cartItem computeds", () => {
test("if there are one or more front wipers on the order, a front wiper cart item should be added to the cart", () => { test("if there are one or more front wipers on the order, a front wiper cart item should be added to the cart", () => {
// Arrange // Arrange
const lineItems = { const lineItems = {
@ -16,26 +15,27 @@ describe("cart.vue", () => {
vaps: [ vaps: [
{ {
cartItemType: "FRONT WIPERS", cartItemType: "FRONT WIPERS",
description: "WIPER BLADE STANDARD 18\"", description: 'WIPER BLADE STANDARD 18"',
kitPrice: 0, kitPrice: 0,
laborAmount: 0, laborAmount: 0,
partNumber: "WB18", partNumber: "WB18",
partType: "FRONT WIPER", partType: "FRONT WIPER",
salesTax: 2.44, salesTax: 2.44,
sellingPrice: 32.49 sellingPrice: 32.49,
}, },
{ {
cartItemType: "FRONT WIPERS", cartItemType: "FRONT WIPERS",
description: "WIPER BLADE STANDARD 26\"", description: 'WIPER BLADE STANDARD 26"',
kitPrice: 0, kitPrice: 0,
laborAmount: 0, laborAmount: 0,
partNumber: "WB26", partNumber: "WB26",
partType: "FRONT WIPER", partType: "FRONT WIPER",
salesTax: 2.44, salesTax: 2.44,
sellingPrice: 32.49 sellingPrice: 32.49,
}], },
],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -43,7 +43,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -52,7 +52,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.frontWipersCartItem.subTotal).toEqual(64.98); expect(wrapper.vm.frontWipersCartItem.subTotal).toEqual(64.98);
expect(wrapper.vm.frontWipersCartItem.salesTax).toEqual(4.88); expect(wrapper.vm.frontWipersCartItem.salesTax).toEqual(4.88);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.frontWipersCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.frontWipersCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -64,26 +67,27 @@ describe("cart.vue", () => {
vaps: [ vaps: [
{ {
cartItemType: "REAR WIPERS", cartItemType: "REAR WIPERS",
description: "REAR WIPER BLADE STANDARD 18\"", description: 'REAR WIPER BLADE STANDARD 18"',
kitPrice: 0, kitPrice: 0,
laborAmount: 0, laborAmount: 0,
partNumber: "EWB18", partNumber: "EWB18",
partType: "REAR WIPER", partType: "REAR WIPER",
salesTax: 2.44, salesTax: 2.44,
sellingPrice: 32.49 sellingPrice: 32.49,
}, },
{ {
cartItemType: "REAR WIPERS", cartItemType: "REAR WIPERS",
description: "REAR WIPER BLADE STANDARD 26\"", description: 'REAR WIPER BLADE STANDARD 26"',
kitPrice: 0, kitPrice: 0,
laborAmount: 0, laborAmount: 0,
partNumber: "RWB26", partNumber: "RWB26",
partType: "REAR WIPER", partType: "REAR WIPER",
salesTax: 2.44, salesTax: 2.44,
sellingPrice: 32.49 sellingPrice: 32.49,
}], },
],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -91,7 +95,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -100,7 +104,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.rearWipersCartItem.subTotal).toEqual(64.98); expect(wrapper.vm.rearWipersCartItem.subTotal).toEqual(64.98);
expect(wrapper.vm.rearWipersCartItem.salesTax).toEqual(4.88); expect(wrapper.vm.rearWipersCartItem.salesTax).toEqual(4.88);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.rearWipersCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.rearWipersCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -119,10 +126,11 @@ describe("cart.vue", () => {
partNumber: "RAIN DEFENSE", partNumber: "RAIN DEFENSE",
partType: "RAIN DEFENSE", partType: "RAIN DEFENSE",
salesTax: 3.37, salesTax: 3.37,
sellingPrice: 44.99 sellingPrice: 44.99,
}], },
],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -130,7 +138,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -139,7 +147,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.rainDefenseCartItem.subTotal).toEqual(44.99); expect(wrapper.vm.rainDefenseCartItem.subTotal).toEqual(44.99);
expect(wrapper.vm.rainDefenseCartItem.salesTax).toEqual(3.37); expect(wrapper.vm.rainDefenseCartItem.salesTax).toEqual(3.37);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.rainDefenseCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.rainDefenseCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -153,11 +164,12 @@ describe("cart.vue", () => {
laborAmount: 23.55, laborAmount: 23.55,
partNumber: "GGG FW4896", partNumber: "GGG FW4896",
salesTax: 1.77, salesTax: 1.77,
sellingPrice: 0 sellingPrice: 0,
} },
], ],
color: "Green Tint", color: "Green Tint",
description: "solar, soundproofing, lane keep assist, lane departure warning system, w/adaptive cruise control", description:
"solar, soundproofing, lane keep assist, lane departure warning system, w/adaptive cruise control",
id: "db22fd44-10dd-456f-979b-ff88cf68cca6", id: "db22fd44-10dd-456f-979b-ff88cf68cca6",
kitPrice: 0, kitPrice: 0,
laborAmount: 60, laborAmount: 60,
@ -167,15 +179,15 @@ describe("cart.vue", () => {
requiresCapabilityQuestions: false, requiresCapabilityQuestions: false,
requiresRecalibration: true, requiresRecalibration: true,
salesTax: 63.86, salesTax: 63.86,
sellingPrice: 791.46 sellingPrice: 791.46,
} };
const lineItems = { const lineItems = {
glassParts: [windshieldWithChildParts], glassParts: [windshieldWithChildParts],
supportingItems: [], supportingItems: [],
vaps: [], vaps: [],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -183,7 +195,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -193,7 +205,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.glassPartsCartItem.salesTax).toEqual(65.63); expect(wrapper.vm.glassPartsCartItem.salesTax).toEqual(65.63);
expect(wrapper.vm.glassPartsCartItem.isDisplayed).toEqual(false); expect(wrapper.vm.glassPartsCartItem.isDisplayed).toEqual(false);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.glassPartsCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.glassPartsCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -202,7 +217,8 @@ describe("cart.vue", () => {
// Arrange // Arrange
const lineItems = { const lineItems = {
glassParts: [], glassParts: [],
supportingItems: [{ supportingItems: [
{
description: null, description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f", id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0, kitPrice: 0,
@ -210,11 +226,12 @@ describe("cart.vue", () => {
partNumber: "RECYCLE FEE", partNumber: "RECYCLE FEE",
partType: "REPLACE FEE", partType: "REPLACE FEE",
salesTax: 2.62, salesTax: 2.62,
sellingPrice: 0 sellingPrice: 0,
}], },
],
vaps: [], vaps: [],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -222,7 +239,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -231,7 +248,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.recycleFeeCartItem.subTotal).toEqual(34.98); expect(wrapper.vm.recycleFeeCartItem.subTotal).toEqual(34.98);
expect(wrapper.vm.recycleFeeCartItem.salesTax).toEqual(2.62); expect(wrapper.vm.recycleFeeCartItem.salesTax).toEqual(2.62);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.recycleFeeCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.recycleFeeCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -240,7 +260,8 @@ describe("cart.vue", () => {
// Arrange // Arrange
const lineItems = { const lineItems = {
glassParts: [], glassParts: [],
supportingItems: [{ supportingItems: [
{
description: null, description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f", id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0, kitPrice: 0,
@ -248,11 +269,12 @@ describe("cart.vue", () => {
partNumber: "MOBILE FEE", partNumber: "MOBILE FEE",
partType: "REPLACE FEE", partType: "REPLACE FEE",
salesTax: 2.62, salesTax: 2.62,
sellingPrice: 0 sellingPrice: 0,
}], },
],
vaps: [], vaps: [],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -260,7 +282,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -269,7 +291,10 @@ describe("cart.vue", () => {
expect(wrapper.vm.mobileFeeCartItem.subTotal).toEqual(34.98); expect(wrapper.vm.mobileFeeCartItem.subTotal).toEqual(34.98);
expect(wrapper.vm.mobileFeeCartItem.salesTax).toEqual(2.62); expect(wrapper.vm.mobileFeeCartItem.salesTax).toEqual(2.62);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.mobileFeeCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.mobileFeeCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
@ -285,15 +310,15 @@ describe("cart.vue", () => {
partNumber: "RECAL STATIC", partNumber: "RECAL STATIC",
partType: "RECALIBRATION", partType: "RECALIBRATION",
salesTax: 33.75, salesTax: 33.75,
sellingPrice: 0 sellingPrice: 0,
} };
const lineItems = { const lineItems = {
glassParts: [], glassParts: [],
supportingItems: [recalibrationLineItem], supportingItems: [recalibrationLineItem],
vaps: [], vaps: [],
promos: [], promos: [],
} };
const availableLineItems = []; const availableLineItems = [];
@ -301,7 +326,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({ const { wrapper } = setupMocks({
props: { props: {
modelValue: lineItems, modelValue: lineItems,
availableLineItems: availableLineItems availableLineItems: availableLineItems,
}, },
}); });
@ -311,18 +336,16 @@ describe("cart.vue", () => {
expect(wrapper.vm.otherSupportingItemsCartItem.salesTax).toEqual(33.75); expect(wrapper.vm.otherSupportingItemsCartItem.salesTax).toEqual(33.75);
expect(wrapper.vm.otherSupportingItemsCartItem.isDisplayed).toEqual(false); expect(wrapper.vm.otherSupportingItemsCartItem.isDisplayed).toEqual(false);
const found = wrapper.vm.cartItems.findIndex(cartItem => cartItem == wrapper.vm.otherSupportingItemsCartItem) >= 0; const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.otherSupportingItemsCartItem
) >= 0;
expect(found).toBe(true); expect(found).toBe(true);
}); });
});
}); });
}) function setupMocks({ options, props }) {
function setupMocks({
options,
props,
}) {
const mountOptions = getMountOptions({ const mountOptions = getMountOptions({
...options, ...options,
}); });

View file

@ -179,10 +179,42 @@ export default {
cartItems.push(this.rainDefenseCartItem); cartItems.push(this.rainDefenseCartItem);
} }
if (this.glassPartsCartItem) { let glassPartsCartItem;
cartItems.push(this.glassPartsCartItem); if (this.lineItems?.glassParts?.length > 0) {
this.lineItems?.glassParts?.forEach((lineItem) => {
glassPartsCartItem = {
name: null,
category: cartItemCategories.GLASS_PARTS,
cartItemType: cartItemTypes.GLASS_PARTS,
isDisplayed: false,
subTotal:
(lineItem.kitPrice ?? 0) +
(lineItem.laborAmount ?? 0) +
(lineItem.sellingPrice ?? 0),
salesTax: lineItem.salesTax ?? 0,
lineItems: [],
};
if (lineItem.childParts?.length > 0) {
lineItem.childParts.forEach((childPartLineItem) => {
glassPartsCartItem.subTotal +=
(childPartLineItem.kitPrice ?? 0) +
(childPartLineItem.laborAmount ?? 0) +
(childPartLineItem.sellingPrice ?? 0);
glassPartsCartItem.salesTax += childPartLineItem.salesTax;
});
} }
cartItems.push(glassPartsCartItem);
});
}
// if (this.glassPartsCartItem) {
// cartItems.push(this.glassPartsCartItem);
// }
if (this.otherSupportingItemsCartItem) { if (this.otherSupportingItemsCartItem) {
cartItems.push(this.otherSupportingItemsCartItem); cartItems.push(this.otherSupportingItemsCartItem);
} }
@ -250,6 +282,12 @@ export default {
baseMixin.methods.filterOutFees(this.availableLineItems) baseMixin.methods.filterOutFees(this.availableLineItems)
); );
console.log(this.availableLineItems)
const feesFilteredOut = baseMixin.methods.filterOutFees(this.availableLineItems);
const tierOnePackagePrice = baseMixin.methods.getTierOnePackagePrice(feesFilteredOut);
console.log(feesFilteredOut)
console.log(tierOnePackagePrice)
packagePrice += this.getVapsPrice(this.packageLevel); packagePrice += this.getVapsPrice(this.packageLevel);
return packagePrice; return packagePrice;

View file

@ -102,6 +102,7 @@ export default {
return filteredLineItems; return filteredLineItems;
}, },
getTotalPriceOfAllLineItemsAndChildParts(lineItems) { getTotalPriceOfAllLineItemsAndChildParts(lineItems) {
console.log(lineItems)
let totalPrice = 0; let totalPrice = 0;
lineItems.forEach((lineItem) => { lineItems.forEach((lineItem) => {
totalPrice += this.getTotalLineItemPrice(lineItem); totalPrice += this.getTotalLineItemPrice(lineItem);
@ -115,7 +116,7 @@ export default {
}, },
getTotalLineItemPrice(lineItem) { getTotalLineItemPrice(lineItem) {
return ( return (
lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice + lineItem.salesTax lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice
); );
}, },
getDisplayAmountDue(lineItems) { getDisplayAmountDue(lineItems) {