diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 85555dd59..5b2f3474a 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -1,3 +1,74 @@ +// 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"; + +// 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: null + }, + order: { + serviceLocation: { + zipCode: null + } + }, + payment: { + isInsurance: null + } + }, +})); + describe("service-location.vue", () => { - test.todo("test this"); + describe("arePagePrerequisitesValid", () => { + test("No prerequisites set: Should return false.", async () => { + const { wrapper } = setupMocks({}); + + serviceLocation.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-location" } }, + undefined, + (c) => c(wrapper.vm) + ); + + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + await nextTick(); + + 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 }; +} \ No newline at end of file