130 lines
3.1 KiB
JavaScript
130 lines
3.1 KiB
JavaScript
import { shallowMount, flushPromises } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import { applicationConfig } from "@/constants/application-config";
|
|
import quote from "@/layouts/quote/quote.vue";
|
|
import store from "@/store";
|
|
import * as navigateToHeritage from "@/helpers/heritage-integration/navigation-helper";
|
|
|
|
jest.mock("@/store", () => ({
|
|
commit: jest.fn(),
|
|
dispatch: jest.fn()
|
|
}));
|
|
|
|
// Mock our module for promises.
|
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
|
settleAllPromises: jest.fn(),
|
|
}));
|
|
|
|
// Mock fetchCmsContentForPage
|
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
fetchCmsContentForPage: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
|
navigateToHeritageFunnel: jest.fn(),
|
|
}));
|
|
|
|
jest.mock(
|
|
"@/store",
|
|
() => {
|
|
return {};
|
|
},
|
|
{ virtual: true }
|
|
);
|
|
|
|
|
|
store.getters = {
|
|
order: {
|
|
accountNumber: applicationConfig.CASH_ACCOUNT_NUMBER,
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {},
|
|
isInsurance: false,
|
|
}
|
|
};
|
|
|
|
afterEach(() => {
|
|
// reset store after each test
|
|
store.getters = {
|
|
order: {
|
|
accountNumber: applicationConfig.CASH_ACCOUNT_NUMBER,
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {},
|
|
isInsurance: false,
|
|
}
|
|
};
|
|
});
|
|
|
|
describe("quote.vue", () => {
|
|
test("IsInsurance false should navigateWithSaving", async () => {
|
|
//Arrange
|
|
const { wrapper } = setupMocks({
|
|
customMountOptions: {
|
|
router: {
|
|
navigateWithSaving: jest.fn(),
|
|
},
|
|
route: { quote }
|
|
},
|
|
});
|
|
|
|
store.getters.payment = {
|
|
insuranceCoverage: {},
|
|
isInsurance : false
|
|
};
|
|
|
|
wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
|
return {
|
|
data: [],
|
|
};
|
|
});
|
|
|
|
//Act
|
|
await wrapper.vm.forwardButtonAction();
|
|
|
|
//Assert
|
|
expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled();
|
|
});
|
|
|
|
test("IsInsurance true should navigateToHeritageFunnel", async () => {
|
|
//Arrange
|
|
const { wrapper } = setupMocks({
|
|
customMountOptions: {
|
|
router: {
|
|
navigateWithSaving: jest.fn(),
|
|
},
|
|
route: { quote }
|
|
},
|
|
});
|
|
|
|
store.getters.payment = {
|
|
insuranceCoverage: {},
|
|
isInsurance : true
|
|
};
|
|
|
|
wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
|
return {
|
|
data: [],
|
|
};
|
|
});
|
|
|
|
//Act
|
|
await wrapper.vm.forwardButtonAction();
|
|
|
|
//Assert
|
|
expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
|
|
function setupMocks({ customMountOptions }) {
|
|
const mountOptions = getMountOptions({
|
|
...customMountOptions,
|
|
});
|
|
|
|
mountOptions.global.mocks["$store"] = store;
|
|
mountOptions["attachTo"] = document.body;
|
|
|
|
const wrapper = shallowMount(quote, mountOptions);
|
|
return { wrapper };
|
|
}
|