diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 85555dd59..a1f44936b 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -1,3 +1,152 @@ -describe("service-location.vue", () => { - test.todo("test this"); +// Components +import serviceLocation from "@/layouts/service-location/service-location.vue"; + +// Supporting files +import { shallowMount } from "@vue/test-utils"; +import { getMountOptions } from "@/helpers/unit-test-helper"; +import baseMixin from "@/mixins/base-mixin"; +import { nextTick } from "vue"; +import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; +import { settleAllPromises } from "@/helpers/layout-helper.js"; +import store from "@/store"; + +// Define Mocks +jest.mock("@/helpers/layout-helper.js", () => ({ + settleAllPromises: jest.fn(), +})); + +jest.mock("@/helpers/cms-content-helper", () => ({ + fetchCmsContentForPage: jest.fn(), +})); + +jest.mock("@/store", () => ({ + commit: jest.fn(), + dispatch: jest.fn(), + getters: { + lineItems: { + supportingItems: [ + { + description: null, + kitPrice: 0, + laborAmount: 0, + partNumber: "SUPPLIES-REPAIR", + partType: "REPAIR FEE", + sellingPrice: 7.99, + }, + ], + }, + order: { + serviceLocation: { + zipCode: "43235", + }, + }, + payment: { + isInsurance: false, + }, + }, +})); + +beforeEach(() => { + store.getters = { + lineItems: { + supportingItems: [ + { + description: null, + kitPrice: 0, + laborAmount: 0, + partNumber: "SUPPLIES-REPAIR", + partType: "REPAIR FEE", + sellingPrice: 7.99, + }, + ], + }, + order: { + serviceLocation: { + zipCode: "43235", + }, + }, + payment: { + isInsurance: false, + }, + }; }); + +describe("service-location.vue", () => { + describe("arePagePrerequisitesValid", () => { + test("No prerequisites set: Should return false.", () => { + const { wrapper } = setupMocks({}); + + store.getters = { + lineItems: { + supportingItems: null, + }, + order: { + serviceLocation: { + zipCode: null, + }, + }, + payment: { + isInsurance: null, + }, + }; + + serviceLocation.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-location" } }, + undefined, + (c) => c(wrapper.vm) + ); + + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + expect(arePagePrerequisitesValid).toBe(false); + }); + + test("All prerequisites set: Should return true.", () => { + const { wrapper } = setupMocks({}); + + serviceLocation.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-location" } }, + undefined, + (c) => c(wrapper.vm) + ); + + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + expect(arePagePrerequisitesValid).toBe(true); + }); + + test("Some prerequisites set: Should return false.", () => { + const { wrapper } = setupMocks({}); + + store.getters.order.serviceLocation.zipCode = null; + + serviceLocation.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-location" } }, + undefined, + (c) => c(wrapper.vm) + ); + + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + expect(arePagePrerequisitesValid).toBe(false); + }); + }); +}); + +function setupMocks({ mountOptionsMockData = {} }) { + const apiResponses = {}; + + const apiPromise = Promise.resolve(apiResponses); + + settleAllPromises.mockImplementation(() => apiPromise); + fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); + + const mountOptions = getMountOptions(mountOptionsMockData); + const wrapper = shallowMount(serviceLocation, mountOptions); + wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; + + return { wrapper, apiPromise }; +} diff --git a/src/layouts/service-location/service-location.vue b/src/layouts/service-location/service-location.vue index 37a4cda43..f8a6de292 100644 --- a/src/layouts/service-location/service-location.vue +++ b/src/layouts/service-location/service-location.vue @@ -26,6 +26,7 @@ import { Form } from "vee-validate"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import store from "@/store"; export default { name: "service-location", @@ -53,7 +54,11 @@ export default { }, methods: { arePagePrerequisitesValid() { - return true; + return ( + store.getters.lineItems.supportingItems !== null && + store.getters.order.serviceLocation.zipCode !== null && + store.getters.payment.isInsurance !== null + ); }, backButtonAction() {