Added new tests.

This commit is contained in:
Chloe Herd 2023-04-06 10:55:32 -04:00
parent 572831254d
commit 031453f427

View file

@ -8,6 +8,7 @@ import { getMountOptions } from "@/helpers/unit-test-helper";
import store from "@/store";
import baseMixin from "@/mixins/base-mixin";
import { getServiceabilityDetails } from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
import { TRUE } from "sass";
// Define Mocks
jest.mock("@/helpers/cms-content-helper", () => ({
@ -733,6 +734,87 @@ describe("service-location.vue", () => {
expect(wrapper.vm.isServiceableInshop).toEqual(false);
expect(wrapper.vm.displayNoShopsAlert).toEqual(false);
});
test("displayServiceableInshopOnly should be true if inshop is true and mobile is false", async () => {
// Arrange
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: true,
isRecalibrationServiceableInshop: true,
isGlassServiceableMobile: false,
isRecalibrationServiceableMobile: false,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isServiceableMobile).toEqual(false);
expect(wrapper.vm.isServiceableInshop).toEqual(true);
expect(wrapper.vm.displayServiceableInshopOnly).toEqual(true);
});
test("displayServiceableInshopOnly should be false if inshop is false", async () => {
// Arrange
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: false,
isRecalibrationServiceableInshop: false,
isGlassServiceableMobile: false,
isRecalibrationServiceableMobile: false,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isServiceableMobile).toEqual(false);
expect(wrapper.vm.isServiceableInshop).toEqual(false);
expect(wrapper.vm.displayServiceableInshopOnly).toEqual(false);
});
test("displayServiceableInshopOnly should be false if mobile is true", async () => {
// Arrange
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: true,
isRecalibrationServiceableInshop: true,
isGlassServiceableMobile: true,
isRecalibrationServiceableMobile: true,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isServiceableMobile).toEqual(true);
expect(wrapper.vm.isServiceableInshop).toEqual(true);
expect(wrapper.vm.displayServiceableInshopOnly).toEqual(false);
});
});
describe("should be based only on glass serviceability if recalibration is not defined.", () => {
@ -870,6 +952,142 @@ describe("service-location.vue", () => {
});
});
describe("should check for dual or static recalibration", () => {
test("isDualOrStaticRecalibration should be true if dual recalibration is present", async () => {
// Arrange
store.getters = {
lineItems: {
supportingItems: [
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "SUPPLIES-REPAIR",
partType: "REPAIR FEE",
sellingPrice: 7.99,
},
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "RECAL DUAL",
partType: "RECALIBRATION",
sellingPrice: 0,
},
],
},
order: {
serviceLocation: {
zipCode: "43235",
state: "OH",
},
},
damage: {
isRepair: false,
},
payment: {
isInsurance: false,
},
vehicle: {
registration: {
address: "5555 Sulgrave Dr",
city: "New Albany",
state: "OH",
zipCode: "43054",
},
},
};
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isDualOrStaticRecalibration).toBe(true);
});
test("isDualOrStaticRecalibration should be true if static recalibration is present", async () => {
// Arrange
store.getters = {
lineItems: {
supportingItems: [
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "SUPPLIES-REPAIR",
partType: "REPAIR FEE",
sellingPrice: 7.99,
},
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "RECAL STATIC",
partType: "RECALIBRATION",
sellingPrice: 0,
},
],
},
order: {
serviceLocation: {
zipCode: "43235",
state: "OH",
},
},
damage: {
isRepair: false,
},
payment: {
isInsurance: false,
},
vehicle: {
registration: {
address: "5555 Sulgrave Dr",
city: "New Albany",
state: "OH",
zipCode: "43054",
},
},
};
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isDualOrStaticRecalibration).toBe(true);
});
test("isDualOrStaticRecalibration should be false if neither are present.", async () => {
// Arrange
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
// Assert
expect(wrapper.vm.isDualOrStaticRecalibration).toBe(false);
});
});
describe("should properly display alerts.", () => {
test("Should show mobile-only error if only mobile is available.", async () => {
// Arrange
@ -978,6 +1196,150 @@ describe("service-location.vue", () => {
// Assert
expect(alertComponent.exists()).toBe(false);
});
test("Should show inshop-only error if only inshop is available", async () => {
// Arrange
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: true,
isRecalibrationServiceableInshop: true,
isGlassServiceableMobile: false,
isRecalibrationServiceableMobile: false,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
const alertComponent = wrapper.findComponent({ ref: "alertInshopOnly" });
// Assert
expect(alertComponent.exists()).toBe(true);
});
test("Should not show inshop-only error if not inshop-only", async () => {
// Arrange
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: false,
isRecalibrationServiceableInshop: false,
isGlassServiceableMobile: false,
isRecalibrationServiceableMobile: false,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
const alertComponent = wrapper.findComponent({ ref: "alertInshopOnly" });
// Assert
expect(alertComponent.exists()).toBe(false);
});
test("Should not show inshop-only error if dual or static recalibration, but should show that error instead.", async () => {
// Arrange
store.getters = {
lineItems: {
supportingItems: [
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "SUPPLIES-REPAIR",
partType: "REPAIR FEE",
sellingPrice: 7.99,
},
{
description: null,
kitPrice: 0,
laborAmount: 0,
partNumber: "RECAL STATIC",
partType: "RECALIBRATION",
sellingPrice: 0,
},
],
},
order: {
serviceLocation: {
zipCode: "43235",
state: "OH",
},
},
damage: {
isRepair: false,
},
payment: {
isInsurance: false,
},
vehicle: {
registration: {
address: "5555 Sulgrave Dr",
city: "New Albany",
state: "OH",
zipCode: "43054",
},
},
};
getServiceabilityDetails.mockImplementation(() =>
Promise.resolve({
isGlassServiceableInshop: false,
isRecalibrationServiceableInshop: false,
isGlassServiceableMobile: false,
isRecalibrationServiceableMobile: false,
})
);
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
const alertInshopComponent = wrapper.findComponent({ ref: "alertInshopOnly" });
const alertRecalComponent = wrapper.findComponent({ ref: "alertRecalNoMobile" });
// Assert
expect(alertInshopComponent.exists()).toBe(false);
expect(alertRecalComponent.exists()).toBe(true);
});
test("Should not show dual/static recalibration error if not those recalibration types", async () => {
// Arrange
const { wrapper } = setupMocks({});
// Act
await serviceLocation.beforeRouteEnter.call(
wrapper.vm,
{ query: { fmgPage: "serviceLocation" } },
undefined,
(c) => c(wrapper.vm)
);
const alertComponent = wrapper.findComponent({ ref: "alertRecalNoMobile" });
// Assert
expect(alertComponent.exists()).toBe(false);
});
});
});
});