diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 2a056c4d1..4757c6a78 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -7,6 +7,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"; // Define Mocks jest.mock("@/helpers/cms-content-helper", () => ({ @@ -437,6 +438,386 @@ describe("service-location.vue", () => { expect(wrapper.vm.serviceZipCodeQuestion).toStrictEqual(newServiceZipCodeInfo); }); }); + + describe("serviceability logic", () => { + describe("should be logical AND when recalibration is defined.", () => { + test("T & T => T", 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); + }); + + test("T & F => F", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: false, + isGlassServiceableMobile: true, + 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); + }); + + test("F & T => F", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: true, + isGlassServiceableMobile: false, + 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(false); + expect(wrapper.vm.isServiceableInshop).toEqual(false); + }); + + test("F & F => F", 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); + }); + + test("isServiceableMobileOnly should be true if mobile is true and inshop is false.", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: false, + 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(false); + expect(wrapper.vm.isServiceableMobileOnly).toEqual(true); + }); + + test("isServiceableMobileOnly should be false if mobile 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.isServiceableMobileOnly).toEqual(false); + }); + + test("isServiceableMobileOnly should be false if inShop 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.isServiceableMobileOnly).toEqual(false); + }); + }); + + describe("should be based only on glass serviceability if recalibration is not defined.", () => { + test("Should return true", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: null, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: null, + }) + ); + + 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); + }); + + test("Should return false", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: null, + isGlassServiceableMobile: false, + isRecalibrationServiceableMobile: null, + }) + ); + + 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); + }); + + test("isServiceableMobileOnly should be true if mobile is true and inshop is false.", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: null, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: null, + }) + ); + + 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(false); + expect(wrapper.vm.isServiceableMobileOnly).toEqual(true); + }); + + test("isServiceableMobileOnly should be false if mobile is false", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: null, + isGlassServiceableMobile: false, + isRecalibrationServiceableMobile: null, + }) + ); + + 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.isServiceableMobileOnly).toEqual(false); + }); + + test("isServiceableMobileOnly should be false if inShop is true", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: null, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: null, + }) + ); + + 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.isServiceableMobileOnly).toEqual(false); + }); + }); + + describe("should properly display alerts.", () => { + test("Should show mobile-only error if only mobile is available.", async () => { + // Arrange + getServiceabilityDetails.mockImplementation(() => + Promise.resolve({ + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: false, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: true, + }) + ); + + const { wrapper } = setupMocks({}); + + // Act + await serviceLocation.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "serviceLocation" } }, + undefined, + (c) => c(wrapper.vm) + ); + + const alertComponent = wrapper.findComponent('[data-test="mobileOnlyAlert"]'); + + // Assert + expect(alertComponent.exists()).toBe(true); + }); + + test("Should not show mobile-only error if not mobile-only.", 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) + ); + + const alertComponent = wrapper.findComponent('[data-test="mobileOnlyAlert"]'); + + // Assert + expect(alertComponent.exists()).toBe(false); + }); + }); + }); }); function setupMocks({ mountOptionsMockData = {} }) { diff --git a/src/layouts/service-location/service-location.vue b/src/layouts/service-location/service-location.vue index 774aafd87..4d591edcc 100644 --- a/src/layouts/service-location/service-location.vue +++ b/src/layouts/service-location/service-location.vue @@ -22,7 +22,8 @@ class="my-4" cmsWidgetName="AlertMobileOnlyWidget" v-if="isServiceableMobileOnly" - alertClass="alert-warning" /> + alertClass="alert-warning" + data-test="mobileOnlyAlert" />