Implementation of validate and revalidate endpoints in the store Validate promo on quote via query string promo Revalidate promos on quote page load Remove promo query string on quote and payment-method forward navigation Add in Id logic for all line items Send relevant pricing data to service package question to be used later for UX changes
511 lines
15 KiB
JavaScript
511 lines
15 KiB
JavaScript
import { shallowMount, flushPromises } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import { applicationConfig } from "@/constants/application-config";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
import quote from "@/layouts/quote/quote.vue";
|
|
import store from "@/store";
|
|
import * as navigateToHeritage from "@/helpers/heritage-integration/navigation-helper";
|
|
import { nextTick } from "vue";
|
|
|
|
jest.mock("@/store", () => ({
|
|
commit: jest.fn(),
|
|
dispatch: jest.fn(),
|
|
}));
|
|
|
|
// Mock fetchCmsContentForPage
|
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
fetchCmsContentForPage: () => Promise.resolve("content"),
|
|
}));
|
|
|
|
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
|
navigateToHeritageFunnel: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/promotions-helper", () => ({
|
|
revalidatePromosAndValidateNewPromo: jest.fn(() => {
|
|
return { validatePromoResponse: null, revalidatePromoResponse: null };
|
|
}),
|
|
}));
|
|
|
|
jest.mock(
|
|
"@/store",
|
|
() => {
|
|
return {};
|
|
},
|
|
{ virtual: true }
|
|
);
|
|
|
|
// START beforeRouteEnter mock arranging //
|
|
jest.mock("@/mixins/base-mixin", () => ({
|
|
methods: {
|
|
dispatchStoreAction(action, items, encode) {
|
|
if (action === mockPriceOrderStoreAction) return items;
|
|
else return mockStoreActionResults[action];
|
|
},
|
|
dispatchStoreActionWithLogging(action, items, pageName, encode) {
|
|
if (action === mockPriceOrderStoreAction) return items;
|
|
else return mockStoreActionResults[action];
|
|
},
|
|
getTierOnePackagePrice() {
|
|
return mockTierOnePrice;
|
|
},
|
|
filterOutFees(items) {
|
|
return null;
|
|
},
|
|
},
|
|
}));
|
|
|
|
const mockMixin = {
|
|
methods: {
|
|
filterOutFees: jest.fn().mockImplementation(() => {
|
|
return null;
|
|
}),
|
|
},
|
|
};
|
|
|
|
let mockTierOnePrice = 501;
|
|
|
|
const mockPriceOrderStoreAction = storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA;
|
|
const mockStoreActionResults = {};
|
|
|
|
mockStoreActionResults[storeActions.GET_WIPERS] = Promise.resolve([
|
|
{ partNumber: "SBB24", partType: "FRONT WIPER" },
|
|
]);
|
|
mockStoreActionResults[storeActions.GET_RAIN_DEFENSE] = Promise.resolve({
|
|
partNumber: "RAIN DEFENSE",
|
|
partType: "RAIN DEFENSE",
|
|
});
|
|
mockStoreActionResults[storeActions.GET_SUPPORTING_ITEMS] = Promise.resolve([
|
|
{ partNumber: "WSREPAIR", partType: "WSREPAIR" },
|
|
]);
|
|
// END beforeRouteEnter mock arranging
|
|
|
|
store.getters = {
|
|
order: {
|
|
payment: {
|
|
insuranceCoverage: {},
|
|
isInsurance: false,
|
|
parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER,
|
|
},
|
|
},
|
|
};
|
|
|
|
afterEach(() => {
|
|
// reset store after each test
|
|
store.getters = {
|
|
order: {
|
|
payment: {
|
|
parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER,
|
|
},
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {},
|
|
isInsurance: false,
|
|
},
|
|
};
|
|
});
|
|
|
|
describe("quote.vue", () => {
|
|
test("IsInsurance false should navigateWithSaving", async () => {
|
|
//Arrange
|
|
store.getters.payment = {
|
|
insuranceCoverage: {},
|
|
isInsurance: false,
|
|
};
|
|
store.getters.order = {
|
|
lineItems: [],
|
|
payment: {
|
|
parentAccountNumber: 167132,
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({
|
|
customMountOptions: {
|
|
router: {
|
|
navigateWithSaving: jest.fn(),
|
|
},
|
|
route: { quote },
|
|
},
|
|
});
|
|
|
|
wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
|
return {
|
|
data: [],
|
|
};
|
|
});
|
|
|
|
wrapper.vm.pricedGlassParts = [];
|
|
|
|
//Act
|
|
await wrapper.vm.forwardButtonAction();
|
|
|
|
//Assert
|
|
expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled();
|
|
});
|
|
|
|
test("IsInsurance true should navigateToHeritageFunnel", async () => {
|
|
//Arrange
|
|
store.getters = {
|
|
payment: {
|
|
insuranceCoverage: {},
|
|
isInsurance: true,
|
|
},
|
|
order: {
|
|
lineItems: [],
|
|
payment: {
|
|
parentAccountNumber: null,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({
|
|
customMountOptions: {
|
|
router: {
|
|
navigateWithSaving: jest.fn(),
|
|
},
|
|
route: { quote },
|
|
mixins: [mockMixin],
|
|
},
|
|
});
|
|
|
|
wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
|
return {
|
|
data: [],
|
|
};
|
|
});
|
|
|
|
wrapper.vm.pricedGlassParts = [];
|
|
|
|
//Act
|
|
await wrapper.vm.forwardButtonAction();
|
|
|
|
//Assert
|
|
expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled();
|
|
});
|
|
test("should pass arePagePrerequisitesValid with a repair order", () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: [],
|
|
serviceLocation: {
|
|
zipCode: "12345",
|
|
zipCodeCtu: "value",
|
|
},
|
|
damage: {
|
|
isRepair: true,
|
|
},
|
|
referralNumber: "1234567",
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: false,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(true);
|
|
});
|
|
test("should pass arePagePrerequisitesValid with a replace order", () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
serviceLocation: {
|
|
zipCode: "12345",
|
|
zipCodeCtu: "value",
|
|
},
|
|
damage: {
|
|
isRepair: false,
|
|
},
|
|
referralNumber: "1234567",
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: false,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(true);
|
|
});
|
|
test("should fail arePagePrerequisitesValid without glass parts or flagged as repair", () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: [],
|
|
serviceLocation: {
|
|
zipCode: "12345",
|
|
zipCodeCtu: "value",
|
|
},
|
|
damage: {
|
|
isRepair: false,
|
|
},
|
|
referralNumber: "1234567",
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
|
|
expect(arePagePrerequisitesValid).toBe(false);
|
|
});
|
|
test("should have non-null values for necessary data members after 'beforeRouteEnter'", async () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
//mock this to avoid needing to populate this.$route in an unrelated test
|
|
wrapper.vm.getDefaultIsInsuranceSelectedValue = jest.fn();
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.pricedGlassParts !== null).toBe(true);
|
|
expect(wrapper.vm.supportingItems !== null).toBe(true);
|
|
expect(wrapper.vm.availableLineItems !== null).toBe(true);
|
|
// This should have its own test
|
|
//expect(vm.isInsuranceSelected !== null).toBe(true);
|
|
});
|
|
test("should default to insurance if query param 'isInsurance' is true", async () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: null,
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$route = { query: { isInsurance: "true" } };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(true);
|
|
});
|
|
test("should default to cash if query param 'isInsurance' is false", async () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: null,
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$route = { query: { isInsurance: "false" } };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(false);
|
|
});
|
|
test("should default to insurance if insurance selection is saved to store", async () => {
|
|
//Arrange
|
|
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: true,
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
// Ensure that query param isn't overriding selection
|
|
wrapper.vm.$route = { query: null };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(true);
|
|
});
|
|
test("should default to cash if cash selection is saved to store", async () => {
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: false,
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
// Ensure that query param isn't overriding selection
|
|
wrapper.vm.$route = { query: null };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(false);
|
|
});
|
|
test("should default to cash if total economy package price is under $500", async () => {
|
|
// Also needs no query parameter or previous selection in store to be present
|
|
//Arrange
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: null, // Ensure that previous selection isn't overriding selection
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
mockTierOnePrice = 200;
|
|
const { wrapper } = setupMocks({});
|
|
// Ensure that query param isn't overriding selection
|
|
wrapper.vm.$route = { query: null };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(false);
|
|
});
|
|
test("should default to insurance if total economy package price is over $500", async () => {
|
|
// Also needs no query parameter or previous selection in store to be present
|
|
//Arrange
|
|
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: null, // Ensure that previous selection isn't overriding selection
|
|
},
|
|
serviceLocation: {
|
|
state: null,
|
|
},
|
|
},
|
|
};
|
|
mockTierOnePrice = 505;
|
|
const { wrapper } = setupMocks({});
|
|
// Ensure that query param isn't overriding selection
|
|
wrapper.vm.$route = { query: null };
|
|
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(true);
|
|
});
|
|
test("Should default to insurence if user Service zip is from certain States", async () => {
|
|
//Arrange
|
|
|
|
store.getters = {
|
|
order: {
|
|
lineItems: {
|
|
glassParts: ["item", "item2"],
|
|
},
|
|
payment: {
|
|
isInsurance: null,
|
|
},
|
|
serviceLocation: {
|
|
state: "AZ",
|
|
},
|
|
},
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
wrapper.vm.$route = { query: null };
|
|
//Act
|
|
await quote.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "quote" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
//Assert
|
|
expect(wrapper.vm.isInsuranceSelected).toBe(true);
|
|
});
|
|
});
|
|
|
|
function setupMocks({ customMountOptions }) {
|
|
const mountOptions = getMountOptions({
|
|
...customMountOptions,
|
|
});
|
|
|
|
mountOptions.global.mocks["$store"] = store;
|
|
mountOptions["attachTo"] = document.body;
|
|
|
|
const wrapper = shallowMount(quote, mountOptions);
|
|
wrapper.vm.setCmsContent = jest.fn();
|
|
return { wrapper };
|
|
}
|