242 lines
7 KiB
JavaScript
242 lines
7 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";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
import globalMethods from "@/global-methods";
|
|
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
|
|
|
globalMethods.callHttpClient = jest.fn();
|
|
|
|
global.crypto = { randomUUID: jest.fn() };
|
|
const mockPriceOrderItemsAndSaveServerData = jest
|
|
.fn()
|
|
.mockResolvedValue(/* your mock return value */);
|
|
|
|
// 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(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/pricing-helper.js", () => ({
|
|
getAmountDue: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/debug-log-helper.js", () => ({
|
|
debugLog: jest.fn(),
|
|
}));
|
|
|
|
let piaDisabledFlag = false;
|
|
|
|
const createValidOrderForPaymentMethod = () => ({
|
|
payment: {
|
|
isPia: false,
|
|
isInsurance: false,
|
|
insuranceCoverage: { isVerified: true },
|
|
},
|
|
lineItems: {
|
|
glassParts: [{ id: "part1", partType: "WINDSHIELD" }],
|
|
supportingItems: [],
|
|
vaps: [],
|
|
promos: [],
|
|
},
|
|
policy: {
|
|
currentDeductible: 123,
|
|
isNoComp: false,
|
|
isItac: false,
|
|
},
|
|
serviceLocation: {
|
|
appointmentType: AppointmentTypeStrings.MOBILE,
|
|
address: "123 Test Ave",
|
|
address2: "",
|
|
city: "Anytown",
|
|
state: "OH",
|
|
zipCode: "00000",
|
|
zipCodeCtu: "00000",
|
|
provider: {
|
|
address: {
|
|
streetAddress: "456 Provider St",
|
|
city: "Anytown",
|
|
state: "OH",
|
|
zipCode: "00000",
|
|
zipCodeCtu: "00000",
|
|
},
|
|
},
|
|
},
|
|
customer: {
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
emailAddress: "john@example.com",
|
|
phoneNumber: "555-555-5555",
|
|
},
|
|
schedule: {
|
|
date: "2024-01-15",
|
|
startTime: "09:00",
|
|
endTime: "10:00",
|
|
jobMinMinutes: "30",
|
|
jobMaxMinutes: "45",
|
|
},
|
|
vehicle: { year: 2020, make: "Toyota", model: "Camry", carId: "12345" },
|
|
damage: { isRepair: 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();
|
|
});
|
|
});
|
|
|
|
describe("arePagePrerequisitesValid", () => {
|
|
test("returns true when all prerequisites are valid", () => {
|
|
const { wrapper } = setupMocks();
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test("returns false when service location info is missing", () => {
|
|
const { wrapper } = setupMocks();
|
|
store.getters.order.serviceLocation.address = null;
|
|
store.getters.order.serviceLocation.provider.address.streetAddress = null;
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test("returns false when insurance info is invalid", () => {
|
|
const { wrapper } = setupMocks();
|
|
store.getters.order.payment.isInsurance = null;
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test("returns false when scheduling info is missing", () => {
|
|
const { wrapper } = setupMocks();
|
|
store.getters.order.schedule.date = null;
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test("returns false when customer info is missing", () => {
|
|
const { wrapper } = setupMocks();
|
|
store.getters.order.customer.firstName = null;
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test("returns false when glass parts or repair info is missing", () => {
|
|
const { wrapper } = setupMocks();
|
|
store.getters.order.damage.isRepair = false;
|
|
store.getters.order.lineItems.glassParts = [];
|
|
|
|
const result = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupMocks() {
|
|
store.getters = {
|
|
damage: {},
|
|
lineItems: {
|
|
glassParts: [],
|
|
supportingItems: [],
|
|
vaps: [],
|
|
promos: [],
|
|
},
|
|
order: createValidOrderForPaymentMethod(),
|
|
applicationUser: {
|
|
experiments: [],
|
|
},
|
|
policy: {
|
|
currentDeductible: 123,
|
|
},
|
|
payment: {
|
|
isInsurance: false,
|
|
},
|
|
};
|
|
|
|
const mountOptions = getMountOptions({
|
|
route: { query: {}, params: {} },
|
|
router: {
|
|
navigate: jest.fn(),
|
|
navigateWithSaving: jest.fn(),
|
|
navigateWithoutSaving: jest.fn(),
|
|
},
|
|
store: {
|
|
getters: store.getters,
|
|
},
|
|
actions: {
|
|
priceOrderItemsAndSaveServerData: mockPriceOrderItemsAndSaveServerData,
|
|
},
|
|
});
|
|
|
|
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";
|
|
}),
|
|
hasSettingEqualTo: jest.fn((settingName) => {
|
|
if (settingName === experimentSettings.DISPLAY_AFTERPAY_BREAKOUT_DISPLAY) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}),
|
|
getCmsContent: jest.fn().mockImplementation(() => {
|
|
return "test text";
|
|
}),
|
|
},
|
|
};
|
|
|
|
mountOptions.global.mixins = [mockMixin];
|
|
|
|
const wrapper = shallowMount(customerDetails, mountOptions);
|
|
|
|
wrapper.vm.$refs.loadingModal.showModal = jest.fn();
|
|
|
|
return { wrapper };
|
|
}
|