CASH-1428 - Fixed unit test
This commit is contained in:
parent
e8f5bc9e24
commit
e8d7ee5353
1 changed files with 143 additions and 10 deletions
|
|
@ -6,10 +6,16 @@ import { shallowMount } from "@vue/test-utils";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import { experimentSettings } from "@/constants/experiments";
|
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.
|
// Mock our module for promises.
|
||||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
settleAllPromises: jest.fn(),
|
settleAllPromises: jest.fn(),
|
||||||
|
|
@ -37,16 +43,140 @@ describe("payment-method.vue", () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
|
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("if the continue button is clicked, navigate forward", async () => {
|
describe("forwardButtonAction", () => {
|
||||||
// Arrange
|
let wrapper;
|
||||||
const { wrapper } = setupMocks();
|
let mockDispatchStoreAction;
|
||||||
|
let mockGetCalcOrderAndTaxedLineItems;
|
||||||
|
let mockSubmitWorkOrder;
|
||||||
|
let mockRouter;
|
||||||
|
let mockLoadingModal;
|
||||||
|
let mockStoreGetters;
|
||||||
|
let mockLineItems;
|
||||||
|
let mockInactivePromos;
|
||||||
|
let mockIsRecalAckOptIn;
|
||||||
|
let mockPaymentMethod;
|
||||||
|
let mockPaymentMethods;
|
||||||
|
|
||||||
// Act
|
beforeEach(() => {
|
||||||
await wrapper.vm.forwardButtonAction();
|
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
|
wrapper = {
|
||||||
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled();
|
$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: {
|
store: {
|
||||||
getters: store.getters,
|
getters: store.getters,
|
||||||
},
|
},
|
||||||
|
actions: {
|
||||||
|
priceOrderItemsAndSaveServerData: mockPriceOrderItemsAndSaveServerData,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue