DigitalConsumer.FixMyGlass/src/fmg-components/cart/cart.spec.js

462 lines
16 KiB
JavaScript

// 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";
import { packageNames } from "@/constants/package-names";
import store from "@/store";
jest.mock("@/mixins/experiment-mixin.js", () => ({
methods: {
getSettingValue(settingName) {
return false;
},
hasSetting(settingName) {
return false;
},
hasSettingEqualTo(settingName, settingValue) {
return false;
},
},
}));
global.$logger = {
logInformation: jest.fn(),
logWarning: jest.fn(),
logError: jest.fn(),
logCritical: jest.fn(),
};
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 availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// 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 availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// 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 Repel on the order, a rain repel cart item should be added to the cart", () => {
// Arrange
const lineItems = {
glassParts: [],
supportingItems: [],
vaps: [
{
cartItemType: "RAIN REPEL",
description: null,
kitPrice: 0,
laborAmount: 0,
listPrice: "44.99",
partNumber: "RAIN REPEL",
partType: "RAIN REPEL",
salesTax: 3.37,
sellingPrice: 44.99,
},
],
promos: [],
};
const availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// Assert
expect(wrapper.vm.rainRepelCartItem).not.toBeNull();
expect(wrapper.vm.rainRepelCartItem.subTotal).toEqual(44.99);
expect(wrapper.vm.rainRepelCartItem.salesTax).toEqual(3.37);
const found =
wrapper.vm.cartItems.findIndex(
(cartItem) => cartItem == wrapper.vm.rainRepelCartItem
) >= 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 availableVaps = [];
// // Act
// const { wrapper } = setupMocks({
// props: {
// modelValue: lineItems,
// availableVaps: availableVaps,
// },
// });
// // Assert
// expect(wrapper.vm.glassPartCartItems[0]).not.toBeNull();
// expect(wrapper.vm.glassPartCartItems[0].subTotal).toEqual(875.01);
// expect(wrapper.vm.glassPartCartItems[0].salesTax).toEqual(65.63);
// expect(wrapper.vm.glassPartCartItems[0].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 availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// 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
store.getters.order.isMSRFeeApplicable = false;
const lineItems = {
glassParts: [],
supportingItems: [
{
description: null,
id: "9ff98501-03a4-432b-884e-e4e28f884a2f",
kitPrice: 0,
laborAmount: 34.98,
partNumber: "MOBILE FEE",
partType: "MOBILE FEE",
salesTax: 2.62,
sellingPrice: 0,
},
],
vaps: [],
promos: [],
};
const availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// 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 availableVaps = [];
// Act
const { wrapper } = setupMocks({
props: {
modelValue: lineItems,
availableVaps: availableVaps,
},
});
// 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);
});
});
describe("servicePackageTitle", () => {
const servicePackageCmsContent = {
ServicePackageTitle: {
Answers: [
{
Name: packageNames.TIER_ONE,
SubWidgetName: "EconomyServiceTitle",
},
{
Name: packageNames.TIER_TWO,
SubWidgetName: "StandardServiceTitle",
},
{
Name: packageNames.TIER_THREE,
SubWidgetName: "PremiumServiceTitle",
},
],
},
EconomyServiceTitle: {
Text: "Glass service only",
},
};
const defaultServicePackageProps = {
servicePackageOptionsCmsName: "ServicePackageTitle",
damage: {
glassToReplace: [{ glassLocation: "Windshield" }],
isRepair: false,
},
modelValue: {
glassParts: [],
supportingItems: [],
vaps: [],
promos: [],
},
availableVaps: [],
};
test("uses CMS widget name when experiment is not active", () => {
const { wrapper } = setupMocks({
props: defaultServicePackageProps,
cmsContent: servicePackageCmsContent,
});
expect(wrapper.vm.servicePackageTitleWidget).toBe("EconomyServiceTitle");
expect(wrapper.vm.servicePackageTitleText).toBeNull();
});
test("uses experiment display name when ServicePackageNameTest is active", () => {
const getExperimentPackageLabelSpy = jest
.spyOn(cart.methods, "getExperimentPackageLabel")
.mockReturnValue("Essential");
const { wrapper } = setupMocks({
props: defaultServicePackageProps,
cmsContent: servicePackageCmsContent,
});
expect(wrapper.vm.servicePackageTitleText).toBe("Essential");
getExperimentPackageLabelSpy.mockRestore();
});
});
});
function setupMocks({ options, props, cmsContent }) {
const mountOptions = getMountOptions({
...options,
});
const mockBaseMixin = {
methods: {
getTierOnePackagePrice: jest.fn(),
filterOutFees: jest.fn(),
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
return cmsContent?.[widgetName]?.[cmsFieldName];
}),
},
};
if (props) mountOptions.propsData = props;
mountOptions.global.mixins = [mockBaseMixin];
mountOptions.global.mocks["$store"] = store;
const wrapper = shallowMount(cart, mountOptions);
return { wrapper };
}