111 lines
3.8 KiB
JavaScript
111 lines
3.8 KiB
JavaScript
import { shallowMount } from "@vue/test-utils";
|
|
import scheduling from "./scheduling";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import { settleAllPromises } from "@/helpers/layout-helper";
|
|
|
|
jest.mock("@/store", () => ({
|
|
dispatch: jest.fn().mockResolvedValue(null),
|
|
getters: {
|
|
order: {
|
|
serviceLocation: { zipCode: "43235", appointmentType: null },
|
|
payment: { isInsurance: false, insuranceCoverage: { isVerified: false } },
|
|
referralNumber: "",
|
|
damage: { isRepair: false },
|
|
lineItems: { glassParts: [] },
|
|
policy: { isItac: false, isNoComp: false },
|
|
},
|
|
},
|
|
}));
|
|
|
|
jest.mock("@/helpers/layout-helper", () => ({
|
|
settleAllPromises: jest.fn().mockResolvedValue({}),
|
|
}));
|
|
|
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
fetchCmsContentForPage: jest.fn().mockResolvedValue({}),
|
|
}));
|
|
|
|
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
|
navigateToHeritageFunnel: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/debug-log-helper", () => ({
|
|
debugLog: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/page-prerequisites-helper.js", () => ({
|
|
flushPagePrereqsLogs: jest.fn(),
|
|
hasServiceZipInfo: jest.fn(() => true),
|
|
hasGlassPartsOrRepairInfo: jest.fn(() => true),
|
|
hasInsuranceInfo: jest.fn(() => true),
|
|
}));
|
|
|
|
function setupMocks() {
|
|
const baseMixin = {
|
|
methods: {
|
|
getCmsContent: jest.fn(() => ""),
|
|
setCmsContent: jest.fn(),
|
|
getTotalLineItemPrice: jest.fn(() => 0),
|
|
},
|
|
};
|
|
const mountOptions = getMountOptions({
|
|
route: { name: "scheduling" },
|
|
router: {
|
|
navigate: jest.fn(),
|
|
navigateWithSaving: jest.fn(),
|
|
navigateWithoutSaving: jest.fn(),
|
|
},
|
|
});
|
|
mountOptions.global.mixins = [baseMixin];
|
|
const wrapper = shallowMount(scheduling, mountOptions);
|
|
return { wrapper };
|
|
}
|
|
|
|
describe("scheduling.vue", () => {
|
|
describe("intercept overlay", () => {
|
|
test("does not render interceptOverlay when isLoadingDates is false", async () => {
|
|
const { wrapper } = setupMocks();
|
|
await wrapper.setData({ isLoadingDates: false });
|
|
expect(wrapper.find("intercept-overlay-stub").exists()).toBe(false);
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("renders interceptOverlay when isLoadingDates is true", async () => {
|
|
const { wrapper } = setupMocks();
|
|
await wrapper.setData({ isLoadingDates: true });
|
|
expect(wrapper.find("intercept-overlay-stub").exists()).toBe(true);
|
|
wrapper.unmount();
|
|
});
|
|
});
|
|
|
|
describe("handleRequestMoreDates", () => {
|
|
test("sets isLoadingDates to true while fetching and false after resolving", async () => {
|
|
let resolve;
|
|
settleAllPromises.mockReturnValueOnce(
|
|
new Promise((r) => {
|
|
resolve = r;
|
|
})
|
|
);
|
|
|
|
const { wrapper } = setupMocks();
|
|
const fetchPromise = wrapper.vm.handleRequestMoreDates();
|
|
|
|
expect(wrapper.vm.isLoadingDates).toBe(true);
|
|
|
|
resolve({});
|
|
await fetchPromise;
|
|
|
|
expect(wrapper.vm.isLoadingDates).toBe(false);
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("completes without invoking loadingModal methods (stub has none)", async () => {
|
|
// The loadingModal stub rendered by shallowMount has no showModal/hideModal.
|
|
// If those calls were still in handleRequestMoreDates they would throw here.
|
|
settleAllPromises.mockResolvedValueOnce({});
|
|
const { wrapper } = setupMocks();
|
|
await expect(wrapper.vm.handleRequestMoreDates()).resolves.toBeUndefined();
|
|
wrapper.unmount();
|
|
});
|
|
});
|
|
});
|