CASH-1428 - Fixed unit test

This commit is contained in:
Minojhini Valaiyapathi 2025-09-18 20:51:59 -04:00
parent e8f5bc9e24
commit e8d7ee5353

View file

@ -6,10 +6,16 @@ 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";
globalMethods.callHttpClient = jest.fn();
global.crypto = { randomUUID: jest.fn() };
const mockPriceOrderItemsAndSaveServerData = jest
.fn()
.mockResolvedValue(/* your mock return value */);
global.crypto = {
randomUUID: jest.fn(),
};
// Mock our module for promises.
jest.mock("@/helpers/layout-helper.js", () => ({
settleAllPromises: jest.fn(),
@ -37,16 +43,140 @@ describe("payment-method.vue", () => {
// Assert
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
});
});
test("if the continue button is clicked, navigate forward", async () => {
// Arrange
const { wrapper } = setupMocks();
describe("forwardButtonAction", () => {
let wrapper;
let mockDispatchStoreAction;
let mockGetCalcOrderAndTaxedLineItems;
let mockSubmitWorkOrder;
let mockRouter;
let mockLoadingModal;
let mockStoreGetters;
let mockLineItems;
let mockInactivePromos;
let mockIsRecalAckOptIn;
let mockPaymentMethod;
let mockPaymentMethods;
// Act
await wrapper.vm.forwardButtonAction();
beforeEach(() => {
mockDispatchStoreAction = jest.fn().mockResolvedValue();
mockGetCalcOrderAndTaxedLineItems = jest.fn().mockResolvedValue({
glassParts: [],
supportingItems: [],
vaps: [],
promos: [],
});
mockSubmitWorkOrder = jest.fn().mockResolvedValue();
mockRouter = {
navigateWithoutSaving: jest.fn(),
navigateWithSaving: jest.fn(),
};
mockLoadingModal = { showModal: jest.fn(), hideModal: jest.fn() };
mockStoreGetters = {
order: {
lineItems: {
glassParts: [],
supportingItems: [],
vaps: [],
},
payment: { isInsurance: false, piaType: null, isPia: false },
serviceLocation: {
provider: { providerNumber: "0000567" },
appointmentType: "Mobile",
city: "Anytown",
state: "OH",
zipCode: "00000",
},
schedule: {
date: "2024-01-01",
startTime: "09:00",
endTime: "10:00",
jobMaxMinutes: 60,
jobMinMinutes: 60,
},
customer: {
firstName: "Test",
lastName: "User",
phoneNumber: "555-555-5555",
emailAddress: "test@example.com",
},
policy: { currentDeductible: 123, isNoComp: false, isItac: false },
},
payment: { insuranceCoverage: { coverageStatus: "VERIFIED" } },
policy: { currentDeductible: 123 },
};
mockLineItems = { glassParts: [], supportingItems: [], vaps: [], promos: [] };
mockInactivePromos = [];
mockIsRecalAckOptIn = false;
mockPaymentMethod = "LATER";
mockPaymentMethods = { LATER: "LATER", INSURANCE: "INSURANCE" };
// Assert
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
wrapper = {
$refs: { loadingModal: mockLoadingModal },
$router: mockRouter,
$store: { getters: mockStoreGetters },
dispatchStoreAction: mockDispatchStoreAction,
getCalcOrderAndTaxedLineItems: mockGetCalcOrderAndTaxedLineItems,
lineItems: mockLineItems,
inactivePromos: mockInactivePromos,
isRecalAckOptIn: mockIsRecalAckOptIn,
paymentMethod: mockPaymentMethod,
paymentMethods: mockPaymentMethods,
storeActions: require("@/constants/store-actions"),
navigationScenarios: {
CLICKED_FORWARD: "CLICKED_FORWARD",
CLICKED_INSURANCE: "CLICKED_INSURANCE",
CLICKED_PAY_NOW: "CLICKED_PAY_NOW",
},
pageName: "payment-method",
setupPia: jest.fn(),
customCtaCopy: "Continue",
};
jest.mock("@/helpers/heritage-integration/order-helper.js", () => ({
submitWorkOrder: mockSubmitWorkOrder,
}));
});
it("should call all expected methods and navigate when paymentMethod is LATER", async () => {
wrapper.paymentMethod = mockPaymentMethods.LATER;
const submitWorkOrder =
require("@/helpers/heritage-integration/order-helper.js").submitWorkOrder;
await require("@/layouts/payment-method/payment-method.vue").default.methods.forwardButtonAction.call(
wrapper
);
expect(mockLoadingModal.showModal).toHaveBeenCalled();
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"savePaymentMethodChoice",
wrapper.paymentMethod,
false
);
expect(mockGetCalcOrderAndTaxedLineItems).toHaveBeenCalled();
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"saveGlassPartsSuppressingStateResetting",
mockLineItems.glassParts,
false
);
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"saveSupportingItemsSuppressingStateResetting",
mockLineItems.supportingItems,
false
);
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"saveVaps",
mockLineItems.vaps,
false
);
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"saveActiveAndOrInactivePromos",
{ activePromos: mockLineItems.promos, inactivePromos: mockInactivePromos },
false
);
expect(mockDispatchStoreAction).toHaveBeenCalledWith(
"saveIsRecalAckOptIn",
mockIsRecalAckOptIn
);
});
});
});
@ -107,6 +237,9 @@ function setupMocks() {
store: {
getters: store.getters,
},
actions: {
priceOrderItemsAndSaveServerData: mockPriceOrderItemsAndSaveServerData,
},
});
const mockMixin = {