Started working on unit tests
This commit is contained in:
parent
0ae599c35e
commit
5d926de12f
2 changed files with 355 additions and 4 deletions
345
src/fmg-components/cart/cart.spec.js
Normal file
345
src/fmg-components/cart/cart.spec.js
Normal file
|
|
@ -0,0 +1,345 @@
|
||||||
|
// Components
|
||||||
|
import cart from "@/fmg-components/cart/cart.vue";
|
||||||
|
|
||||||
|
// Supporting Files
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
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
|
||||||
|
}],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
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;
|
||||||
|
expect(found).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("if there are one or more rear wipers on the order, a rear wiper cart item should be added to the cart", () => {
|
||||||
|
// Arrange
|
||||||
|
const lineItems = {
|
||||||
|
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
|
||||||
|
}],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
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;
|
||||||
|
expect(found).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("if there is Rain Defense on the order, a rain defense cart item should be added to the cart", () => {
|
||||||
|
// Arrange
|
||||||
|
const lineItems = {
|
||||||
|
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
|
||||||
|
}],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
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;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
],
|
||||||
|
color: "Green Tint",
|
||||||
|
description: "solar, soundproofing, lane keep assist, lane departure warning system, w/adaptive cruise control",
|
||||||
|
id: "db22fd44-10dd-456f-979b-ff88cf68cca6",
|
||||||
|
kitPrice: 0,
|
||||||
|
laborAmount: 60,
|
||||||
|
partNumber: "FW04896GTYN",
|
||||||
|
partType: "WINDSHIELD",
|
||||||
|
recalibrationType: "STATIC",
|
||||||
|
requiresCapabilityQuestions: false,
|
||||||
|
requiresRecalibration: true,
|
||||||
|
salesTax: 63.86,
|
||||||
|
sellingPrice: 791.46
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineItems = {
|
||||||
|
glassParts: [windshieldWithChildParts],
|
||||||
|
supportingItems: [],
|
||||||
|
vaps: [],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.glassPartsCartItem).not.toBeNull();
|
||||||
|
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;
|
||||||
|
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
|
||||||
|
}],
|
||||||
|
vaps: [],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
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;
|
||||||
|
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
|
||||||
|
}],
|
||||||
|
vaps: [],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
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;
|
||||||
|
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 = {
|
||||||
|
cartItemType: "SUPPORTING ITEMS",
|
||||||
|
description: null,
|
||||||
|
id: "8ab6ef9b-8620-430a-8a92-29f7d4bb8b00",
|
||||||
|
kitPrice: 0,
|
||||||
|
laborAmount: 450,
|
||||||
|
partNumber: "RECAL STATIC",
|
||||||
|
partType: "RECALIBRATION",
|
||||||
|
salesTax: 33.75,
|
||||||
|
sellingPrice: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineItems = {
|
||||||
|
glassParts: [],
|
||||||
|
supportingItems: [recalibrationLineItem],
|
||||||
|
vaps: [],
|
||||||
|
promos: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableLineItems = [];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: lineItems,
|
||||||
|
availableLineItems: availableLineItems
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.otherSupportingItemsCartItem).not.toBeNull();
|
||||||
|
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;
|
||||||
|
expect(found).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
function setupMocks({
|
||||||
|
options,
|
||||||
|
props,
|
||||||
|
}) {
|
||||||
|
const mountOptions = getMountOptions({
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockBaseMixin = {
|
||||||
|
methods: {
|
||||||
|
getTierOnePackagePrice: jest.fn(),
|
||||||
|
filterOutFees: jest.fn(),
|
||||||
|
getCmsContent: jest.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (props) mountOptions.propsData = props;
|
||||||
|
|
||||||
|
mountOptions.global.mixins = [mockBaseMixin];
|
||||||
|
|
||||||
|
const wrapper = shallowMount(cart, mountOptions);
|
||||||
|
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
|
|
@ -73,12 +73,18 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
// Components
|
||||||
import { getHighestFullySatisfiedTier, getPackageContents } from "@/helpers/service-package-helper";
|
|
||||||
|
|
||||||
import textLink from "@/ux-components/text-link/text-link";
|
import textLink from "@/ux-components/text-link/text-link";
|
||||||
import textBlock from "@/digital-components/text-block/text-block";
|
import textBlock from "@/digital-components/text-block/text-block";
|
||||||
|
|
||||||
|
// Mixins
|
||||||
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
|
|
||||||
|
// Helpers
|
||||||
import { deepClone } from "@/helpers/object-helper";
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
|
import { getHighestFullySatisfiedTier, getPackageContents } from "@/helpers/service-package-helper";
|
||||||
|
|
||||||
|
// Constants
|
||||||
import { partTypeStrings } from "@/constants/part-type-strings";
|
import { partTypeStrings } from "@/constants/part-type-strings";
|
||||||
import { cartItemCategories } from "@/constants/cart-item-categories";
|
import { cartItemCategories } from "@/constants/cart-item-categories";
|
||||||
import { cartItemTypes } from "@/constants/cart-item-types";
|
import { cartItemTypes } from "@/constants/cart-item-types";
|
||||||
|
|
@ -112,7 +118,7 @@ export default {
|
||||||
let subTotal = 0;
|
let subTotal = 0;
|
||||||
|
|
||||||
vapsItems.forEach((item) => {
|
vapsItems.forEach((item) => {
|
||||||
subTotal += item.subTotal; // baseMixin.methods.getTotalLineItemPrice(item);
|
subTotal += item.subTotal;
|
||||||
});
|
});
|
||||||
|
|
||||||
return subTotal;
|
return subTotal;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue