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,35 +7,35 @@ 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 = {
glassParts: [], glassParts: [],
supportingItems: [], supportingItems: [],
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,
}, },
}); });
@ -51,8 +51,11 @@ describe("cart.vue", () => {
expect(wrapper.vm.frontWipersCartItem).not.toBeNull(); expect(wrapper.vm.frontWipersCartItem).not.toBeNull();
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);
}); });
@ -62,28 +65,29 @@ describe("cart.vue", () => {
glassParts: [], glassParts: [],
supportingItems: [], supportingItems: [],
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,
}, },
}); });
@ -99,8 +103,11 @@ describe("cart.vue", () => {
expect(wrapper.vm.rearWipersCartItem).not.toBeNull(); expect(wrapper.vm.rearWipersCartItem).not.toBeNull();
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);
}); });
@ -110,19 +117,20 @@ describe("cart.vue", () => {
glassParts: [], glassParts: [],
supportingItems: [], supportingItems: [],
vaps: [ vaps: [
{ {
cartItemType: "RAIN DEFENSE", cartItemType: "RAIN DEFENSE",
description: null, description: null,
kitPrice: 0, kitPrice: 0,
laborAmount: 0, laborAmount: 0,
listPrice: "44.99", listPrice: "44.99",
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,
}, },
}); });
@ -138,26 +146,30 @@ describe("cart.vue", () => {
expect(wrapper.vm.rainDefenseCartItem).not.toBeNull(); expect(wrapper.vm.rainDefenseCartItem).not.toBeNull();
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);
}); });
test("if there are glass parts on the order, a glass part cart item should be added to the cart but should not be displayed", () => { test("if there are glass parts on the order, a glass part cart item should be added to the cart but should not be displayed", () => {
// Arrange // Arrange
const windshieldWithChildParts = { const windshieldWithChildParts = {
canSafeliteRecalibrate: true, canSafeliteRecalibrate: true,
childParts: [ childParts: [
{ {
kitPrice: 0, kitPrice: 0,
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,
}, },
}); });
@ -192,29 +204,34 @@ describe("cart.vue", () => {
expect(wrapper.vm.glassPartsCartItem.subTotal).toEqual(875.01); expect(wrapper.vm.glassPartsCartItem.subTotal).toEqual(875.01);
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);
}); });
// Recycle Fee Cart Item // Recycle Fee Cart Item
test("if there is recycling fee on the order, a recycle fee cart item should be added to the cart", () => { test("if there is recycling fee on the order, a recycle fee cart item should be added to the cart", () => {
// Arrange // Arrange
const lineItems = { const lineItems = {
glassParts: [], glassParts: [],
supportingItems: [{ supportingItems: [
description: null, {
id: "9ff98501-03a4-432b-884e-e4e28f884a2f", description: null,
kitPrice: 0, id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
laborAmount: 34.98, kitPrice: 0,
partNumber: "RECYCLE FEE", laborAmount: 34.98,
partType: "REPLACE FEE", partNumber: "RECYCLE FEE",
salesTax: 2.62, partType: "REPLACE FEE",
sellingPrice: 0 salesTax: 2.62,
}], 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,
}, },
}); });
@ -230,29 +247,34 @@ describe("cart.vue", () => {
expect(wrapper.vm.recycleFeeCartItem).not.toBeNull(); expect(wrapper.vm.recycleFeeCartItem).not.toBeNull();
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);
}); });
// Mobile Fee Cart Item // Mobile Fee Cart Item
test("if there is mobile fee on the order, a mobile fee cart item should be added to the cart", () => { test("if there is mobile fee on the order, a mobile fee cart item should be added to the cart", () => {
// Arrange // Arrange
const lineItems = { const lineItems = {
glassParts: [], glassParts: [],
supportingItems: [{ supportingItems: [
description: null, {
id: "9ff98501-03a4-432b-884e-e4e28f884a2f", description: null,
kitPrice: 0, id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
laborAmount: 34.98, kitPrice: 0,
partNumber: "MOBILE FEE", laborAmount: 34.98,
partType: "REPLACE FEE", partNumber: "MOBILE FEE",
salesTax: 2.62, partType: "REPLACE FEE",
sellingPrice: 0 salesTax: 2.62,
}], 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,
}, },
}); });
@ -268,15 +290,18 @@ describe("cart.vue", () => {
expect(wrapper.vm.mobileFeeCartItem).not.toBeNull(); expect(wrapper.vm.mobileFeeCartItem).not.toBeNull();
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);
}); });
// Other Supporting Items Cart Item // Other Supporting Items Cart Item
test("if there are other supporting items on the order, an other supporting items cart item should be added to the cart but should not be displayed", () => { test("if there are other supporting items on the order, an other supporting items cart item should be added to the cart but should not be displayed", () => {
// Arrange // Arrange
const recalibrationLineItem = { const recalibrationLineItem = {
cartItemType: "SUPPORTING ITEMS", cartItemType: "SUPPORTING ITEMS",
description: null, description: null,
id: "8ab6ef9b-8620-430a-8a92-29f7d4bb8b00", id: "8ab6ef9b-8620-430a-8a92-29f7d4bb8b00",
@ -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,
}, },
}); });
@ -310,19 +335,17 @@ describe("cart.vue", () => {
expect(wrapper.vm.otherSupportingItemsCartItem.subTotal).toEqual(450); expect(wrapper.vm.otherSupportingItemsCartItem.subTotal).toEqual(450);
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,
}); });
@ -342,4 +365,4 @@ function setupMocks({
const wrapper = shallowMount(cart, mountOptions); const wrapper = shallowMount(cart, mountOptions);
return { wrapper }; return { wrapper };
} }

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) {