Added additional tests

This commit is contained in:
Chloe Herd 2023-02-16 17:18:44 -05:00
parent 8874519cb0
commit 97eaf64232

View file

@ -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 };
}
}