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("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", () => {
// Arrange
const lineItems = {
glassParts: [],
supportingItems: [],
vaps: [
{
cartItemType: "FRONT WIPERS",
description: "WIPER BLADE STANDARD 18\"",
kitPrice: 0,
laborAmount: 0,
partNumber: "WB18",
partType: "FRONT WIPER",
salesTax: 2.44,
sellingPrice: 32.49
},
{
cartItemType: "FRONT WIPERS",
description: "WIPER BLADE STANDARD 26\"",
kitPrice: 0,
laborAmount: 0,
partNumber: "WB26",
partType: "FRONT WIPER",
salesTax: 2.44,
sellingPrice: 32.49
}],
{
cartItemType: "FRONT WIPERS",
description: 'WIPER BLADE STANDARD 18"',
kitPrice: 0,
laborAmount: 0,
partNumber: "WB18",
partType: "FRONT WIPER",
salesTax: 2.44,
sellingPrice: 32.49,
},
{
cartItemType: "FRONT WIPERS",
description: 'WIPER BLADE STANDARD 26"',
kitPrice: 0,
laborAmount: 0,
partNumber: "WB26",
partType: "FRONT WIPER",
salesTax: 2.44,
sellingPrice: 32.49,
},
],
promos: [],
}
};
const availableLineItems = [];
@ -43,7 +43,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -51,8 +51,11 @@ describe("cart.vue", () => {
expect(wrapper.vm.frontWipersCartItem).not.toBeNull();
expect(wrapper.vm.frontWipersCartItem.subTotal).toEqual(64.98);
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);
});
@ -62,28 +65,29 @@ describe("cart.vue", () => {
glassParts: [],
supportingItems: [],
vaps: [
{
cartItemType: "REAR WIPERS",
description: "REAR WIPER BLADE STANDARD 18\"",
kitPrice: 0,
laborAmount: 0,
partNumber: "EWB18",
partType: "REAR WIPER",
salesTax: 2.44,
sellingPrice: 32.49
},
{
cartItemType: "REAR WIPERS",
description: "REAR WIPER BLADE STANDARD 26\"",
kitPrice: 0,
laborAmount: 0,
partNumber: "RWB26",
partType: "REAR WIPER",
salesTax: 2.44,
sellingPrice: 32.49
}],
{
cartItemType: "REAR WIPERS",
description: 'REAR WIPER BLADE STANDARD 18"',
kitPrice: 0,
laborAmount: 0,
partNumber: "EWB18",
partType: "REAR WIPER",
salesTax: 2.44,
sellingPrice: 32.49,
},
{
cartItemType: "REAR WIPERS",
description: 'REAR WIPER BLADE STANDARD 26"',
kitPrice: 0,
laborAmount: 0,
partNumber: "RWB26",
partType: "REAR WIPER",
salesTax: 2.44,
sellingPrice: 32.49,
},
],
promos: [],
}
};
const availableLineItems = [];
@ -91,7 +95,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -99,8 +103,11 @@ describe("cart.vue", () => {
expect(wrapper.vm.rearWipersCartItem).not.toBeNull();
expect(wrapper.vm.rearWipersCartItem.subTotal).toEqual(64.98);
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);
});
@ -110,19 +117,20 @@ describe("cart.vue", () => {
glassParts: [],
supportingItems: [],
vaps: [
{
cartItemType: "RAIN DEFENSE",
description: null,
kitPrice: 0,
laborAmount: 0,
listPrice: "44.99",
partNumber: "RAIN DEFENSE",
partType: "RAIN DEFENSE",
salesTax: 3.37,
sellingPrice: 44.99
}],
{
cartItemType: "RAIN DEFENSE",
description: null,
kitPrice: 0,
laborAmount: 0,
listPrice: "44.99",
partNumber: "RAIN DEFENSE",
partType: "RAIN DEFENSE",
salesTax: 3.37,
sellingPrice: 44.99,
},
],
promos: [],
}
};
const availableLineItems = [];
@ -130,7 +138,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -138,26 +146,30 @@ describe("cart.vue", () => {
expect(wrapper.vm.rainDefenseCartItem).not.toBeNull();
expect(wrapper.vm.rainDefenseCartItem.subTotal).toEqual(44.99);
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);
});
});
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
const windshieldWithChildParts = {
canSafeliteRecalibrate: true,
childParts: [
{
kitPrice: 0,
laborAmount: 23.55,
partNumber: "GGG FW4896",
salesTax: 1.77,
sellingPrice: 0
}
{
kitPrice: 0,
laborAmount: 23.55,
partNumber: "GGG FW4896",
salesTax: 1.77,
sellingPrice: 0,
},
],
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",
kitPrice: 0,
laborAmount: 60,
@ -167,15 +179,15 @@ describe("cart.vue", () => {
requiresCapabilityQuestions: false,
requiresRecalibration: true,
salesTax: 63.86,
sellingPrice: 791.46
}
sellingPrice: 791.46,
};
const lineItems = {
glassParts: [windshieldWithChildParts],
supportingItems: [],
vaps: [],
promos: [],
}
};
const availableLineItems = [];
@ -183,7 +195,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
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.salesTax).toEqual(65.63);
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);
});
});
// Recycle Fee Cart Item
test("if there is recycling fee on the order, a recycle fee cart item should be added to the cart", () => {
// Arrange
const lineItems = {
glassParts: [],
supportingItems: [{
description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0,
laborAmount: 34.98,
partNumber: "RECYCLE FEE",
partType: "REPLACE FEE",
salesTax: 2.62,
sellingPrice: 0
}],
supportingItems: [
{
description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0,
laborAmount: 34.98,
partNumber: "RECYCLE FEE",
partType: "REPLACE FEE",
salesTax: 2.62,
sellingPrice: 0,
},
],
vaps: [],
promos: [],
}
};
const availableLineItems = [];
@ -222,7 +239,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -230,29 +247,34 @@ describe("cart.vue", () => {
expect(wrapper.vm.recycleFeeCartItem).not.toBeNull();
expect(wrapper.vm.recycleFeeCartItem.subTotal).toEqual(34.98);
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);
});
});
// Mobile Fee Cart Item
test("if there is mobile fee on the order, a mobile fee cart item should be added to the cart", () => {
// Arrange
const lineItems = {
glassParts: [],
supportingItems: [{
description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0,
laborAmount: 34.98,
partNumber: "MOBILE FEE",
partType: "REPLACE FEE",
salesTax: 2.62,
sellingPrice: 0
}],
supportingItems: [
{
description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0,
laborAmount: 34.98,
partNumber: "MOBILE FEE",
partType: "REPLACE FEE",
salesTax: 2.62,
sellingPrice: 0,
},
],
vaps: [],
promos: [],
}
};
const availableLineItems = [];
@ -260,7 +282,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -268,15 +290,18 @@ describe("cart.vue", () => {
expect(wrapper.vm.mobileFeeCartItem).not.toBeNull();
expect(wrapper.vm.mobileFeeCartItem.subTotal).toEqual(34.98);
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);
});
});
// 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", () => {
// Arrange
const recalibrationLineItem = {
const recalibrationLineItem = {
cartItemType: "SUPPORTING ITEMS",
description: null,
id: "8ab6ef9b-8620-430a-8a92-29f7d4bb8b00",
@ -285,15 +310,15 @@ describe("cart.vue", () => {
partNumber: "RECAL STATIC",
partType: "RECALIBRATION",
salesTax: 33.75,
sellingPrice: 0
}
sellingPrice: 0,
};
const lineItems = {
glassParts: [],
supportingItems: [recalibrationLineItem],
vaps: [],
promos: [],
}
};
const availableLineItems = [];
@ -301,7 +326,7 @@ describe("cart.vue", () => {
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableLineItems: availableLineItems
availableLineItems: availableLineItems,
},
});
@ -310,19 +335,17 @@ describe("cart.vue", () => {
expect(wrapper.vm.otherSupportingItemsCartItem.subTotal).toEqual(450);
expect(wrapper.vm.otherSupportingItemsCartItem.salesTax).toEqual(33.75);
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);
});
});
});
})
function setupMocks({
options,
props,
}) {
function setupMocks({ options, props }) {
const mountOptions = getMountOptions({
...options,
});
@ -342,4 +365,4 @@ function setupMocks({
const wrapper = shallowMount(cart, mountOptions);
return { wrapper };
}
}

View file

@ -179,10 +179,42 @@ export default {
cartItems.push(this.rainDefenseCartItem);
}
if (this.glassPartsCartItem) {
cartItems.push(this.glassPartsCartItem);
let 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) {
cartItems.push(this.otherSupportingItemsCartItem);
}
@ -250,6 +282,12 @@ export default {
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);
return packagePrice;

View file

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