From 97eaf64232a45f6d9c0ed9d1668090685692c552 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Thu, 16 Feb 2023 17:18:44 -0500 Subject: [PATCH] Added additional tests --- .../service-location/service-location.spec.js | 85 ++++++++++++++++--- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 5b2f3474a..1b6fcd57f 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -8,14 +8,15 @@ 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() + settleAllPromises: jest.fn(), })); jest.mock("@/helpers/cms-content-helper", () => ({ - fetchCmsContentForPage: jest.fn() + fetchCmsContentForPage: jest.fn(), })); jest.mock("@/store", () => ({ @@ -23,24 +24,88 @@ jest.mock("@/store", () => ({ dispatch: jest.fn(), getters: { lineItems: { - supportingItems: null + supportingItems: [], }, order: { serviceLocation: { - zipCode: null - } + zipCode: "00000", + }, }, payment: { - isInsurance: null - } + isInsurance: false, + }, }, })); +beforeEach(() => { + store.getters = { + lineItems: { + supportingItems: [], + }, + order: { + serviceLocation: { + zipCode: "00000", + }, + }, + payment: { + isInsurance: false, + }, + } +}) + describe("service-location.vue", () => { describe("arePagePrerequisitesValid", () => { test("No prerequisites set: Should return false.", async () => { 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(); + await nextTick(); + + expect(arePagePrerequisitesValid).toBe(false); + }); + + test("All prerequisites set: Should return true.", 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(true); + }); + + test("Some prerequisites set: Should return false.", async () => { + const { wrapper } = setupMocks({}); + + store.getters.order.serviceLocation.zipCode = null; + serviceLocation.beforeRouteEnter.call( wrapper.vm, { query: { fmgPage: "service-location" } }, @@ -56,9 +121,7 @@ describe("service-location.vue", () => { }); }); -function setupMocks({ - mountOptionsMockData = {} -}) { +function setupMocks({ mountOptionsMockData = {} }) { const apiResponses = {}; const apiPromise = Promise.resolve(apiResponses); @@ -71,4 +134,4 @@ function setupMocks({ wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; return { wrapper, apiPromise }; -} \ No newline at end of file +}