92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
// Components
|
|
import customerDetails from "@/layouts/payment-method/payment-method.vue";
|
|
|
|
// Supporting Files
|
|
import { shallowMount } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import store from "@/store";
|
|
import { experimentSettings } from "@/constants/experiments";
|
|
|
|
// Mock our module for promises.
|
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
|
settleAllPromises: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/heritage-integration/order-helper.js", () => ({
|
|
submitWorkOrder: jest.fn(),
|
|
}));
|
|
|
|
let piaDisabledFlag = false;
|
|
|
|
describe("payment-method.vue", () => {
|
|
describe("navigation", () => {
|
|
test("if the back button is clicked, navigate back", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks();
|
|
|
|
// Act
|
|
await wrapper.vm.backButtonAction();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
|
|
});
|
|
|
|
test("if the continue button is clicked, navigate forward", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks();
|
|
|
|
// Act
|
|
await wrapper.vm.forwardButtonAction();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupMocks() {
|
|
store.getters = {
|
|
damage: {},
|
|
lineItems: [],
|
|
order: {
|
|
payment: {
|
|
isPia: false,
|
|
},
|
|
},
|
|
};
|
|
|
|
const mountOptions = getMountOptions({
|
|
route: { query: {}, params: {} },
|
|
router: {
|
|
navigate: jest.fn(),
|
|
navigateWithSaving: jest.fn(),
|
|
navigateWithoutSaving: jest.fn(),
|
|
},
|
|
store: {
|
|
getters: store.getters,
|
|
},
|
|
});
|
|
|
|
const mockMixin = {
|
|
methods: {
|
|
getSettingValue: jest.fn((settingName) => {
|
|
if (!piaDisabledFlag) {
|
|
if (settingName === experimentSettings.PIA_EXPERIENCE) {
|
|
return "PIA Optional";
|
|
}
|
|
if (settingName === experimentSettings.SUBMIT_ORDER_ENABLE_PIA) {
|
|
return "true";
|
|
}
|
|
}
|
|
|
|
return "false";
|
|
}),
|
|
},
|
|
};
|
|
|
|
mountOptions.global.mixins = [mockMixin];
|
|
|
|
const wrapper = shallowMount(customerDetails, mountOptions);
|
|
|
|
return { wrapper };
|
|
}
|