From 30e3ddc541e9004d6d91a45312bfc188c4fa76ff Mon Sep 17 00:00:00 2001 From: Herd Date: Thu, 16 Feb 2023 15:09:11 -0500 Subject: [PATCH 1/6] Initial implementation --- src/layouts/service-location/service-location.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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() { From 8874519cb06cde810d2a97fd957e7df8c31fcbd9 Mon Sep 17 00:00:00 2001 From: Herd Date: Thu, 16 Feb 2023 16:48:59 -0500 Subject: [PATCH 2/6] Added first basic test --- .../service-location/service-location.spec.js | 73 ++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) 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 From 97eaf64232a45f6d9c0ed9d1668090685692c552 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Thu, 16 Feb 2023 17:18:44 -0500 Subject: [PATCH 3/6] 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 +} From 1fb34d29b1029c95c9e06d84ff3c63c170b4ad77 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Fri, 17 Feb 2023 15:53:06 -0500 Subject: [PATCH 4/6] Updated test case data --- .../service-location/service-location.spec.js | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 1b6fcd57f..904580d9d 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -24,11 +24,20 @@ jest.mock("@/store", () => ({ dispatch: jest.fn(), getters: { lineItems: { - supportingItems: [], + supportingItems: [ + { + description: null, + kitPrice: 0, + laborAmount: 0, + partNumber: "SUPPLIES-REPAIR", + partType: "REPAIR FEE", + sellingPrice: 7.99 + } + ], }, order: { serviceLocation: { - zipCode: "00000", + zipCode: "43235", }, }, payment: { @@ -40,18 +49,27 @@ jest.mock("@/store", () => ({ beforeEach(() => { store.getters = { lineItems: { - supportingItems: [], + supportingItems: [ + { + description: null, + kitPrice: 0, + laborAmount: 0, + partNumber: "SUPPLIES-REPAIR", + partType: "REPAIR FEE", + sellingPrice: 7.99 + } + ], }, order: { serviceLocation: { - zipCode: "00000", + zipCode: "43235", }, }, payment: { isInsurance: false, }, - } -}) + }; +}); describe("service-location.vue", () => { describe("arePagePrerequisitesValid", () => { @@ -70,7 +88,7 @@ describe("service-location.vue", () => { payment: { isInsurance: null, }, - } + }; serviceLocation.beforeRouteEnter.call( wrapper.vm, From c148f56361871aa16221fd207b2ec4a237e5086a Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Mon, 20 Feb 2023 15:41:43 -0500 Subject: [PATCH 5/6] Removed unnecessary nextTick calls from tests --- src/layouts/service-location/service-location.spec.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 904580d9d..4dec285bd 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -73,7 +73,7 @@ beforeEach(() => { describe("service-location.vue", () => { describe("arePagePrerequisitesValid", () => { - test("No prerequisites set: Should return false.", async () => { + test("No prerequisites set: Should return false.", () => { const { wrapper } = setupMocks({}); store.getters = { @@ -98,12 +98,11 @@ describe("service-location.vue", () => { ); let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - await nextTick(); expect(arePagePrerequisitesValid).toBe(false); }); - test("All prerequisites set: Should return true.", async () => { + test("All prerequisites set: Should return true.", () => { const { wrapper } = setupMocks({}); serviceLocation.beforeRouteEnter.call( @@ -114,12 +113,11 @@ describe("service-location.vue", () => { ); let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - await nextTick(); expect(arePagePrerequisitesValid).toBe(true); }); - test("Some prerequisites set: Should return false.", async () => { + test("Some prerequisites set: Should return false.", () => { const { wrapper } = setupMocks({}); store.getters.order.serviceLocation.zipCode = null; @@ -132,7 +130,6 @@ describe("service-location.vue", () => { ); let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - await nextTick(); expect(arePagePrerequisitesValid).toBe(false); }); From ca215c3af53eece80d9e2924ec1ce0751c8619e5 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Mon, 20 Feb 2023 15:42:48 -0500 Subject: [PATCH 6/6] Fix formatting --- src/layouts/service-location/service-location.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 4dec285bd..a1f44936b 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -31,8 +31,8 @@ jest.mock("@/store", () => ({ laborAmount: 0, partNumber: "SUPPLIES-REPAIR", partType: "REPAIR FEE", - sellingPrice: 7.99 - } + sellingPrice: 7.99, + }, ], }, order: { @@ -56,8 +56,8 @@ beforeEach(() => { laborAmount: 0, partNumber: "SUPPLIES-REPAIR", partType: "REPAIR FEE", - sellingPrice: 7.99 - } + sellingPrice: 7.99, + }, ], }, order: {