Merge pull request #979 from Safelite/feature/unit-tests-quote-page
Unit Tests (Quote Page)
This commit is contained in:
commit
8e62508383
5 changed files with 302 additions and 30 deletions
|
|
@ -31,7 +31,7 @@ const storeActions = {
|
|||
LOAD_SESSION: "loadSession",
|
||||
UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE: "updateStoreWithSaveSessionResponse",
|
||||
VALIDATE_ZIP: "validateZip",
|
||||
PRICE_ORDER_ITEMS: "priceOrderItems",
|
||||
PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA: "priceOrderItemsAndSaveServerData",
|
||||
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
||||
LOG_PAGE_VIEW: "logPageView",
|
||||
LOG_CUSTOM_EVENT: "logCustomEvent",
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
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 our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
settleAllPromises: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
fetchCmsContentForPage: jest.fn(),
|
||||
fetchCmsContentForPage: () => Promise.resolve("content"),
|
||||
}));
|
||||
|
||||
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
||||
|
|
@ -32,6 +29,38 @@ jest.mock(
|
|||
{ 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];
|
||||
},
|
||||
getTierOnePackagePrice() {
|
||||
return mockTierOnePrice;
|
||||
},
|
||||
filterOutFees() {
|
||||
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: {
|
||||
accountNumber: applicationConfig.CASH_ACCOUNT_NUMBER,
|
||||
|
|
@ -117,6 +146,269 @@ describe("quote.vue", () => {
|
|||
//Assert
|
||||
expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled();
|
||||
});
|
||||
test("should pass arePagePrerequisitesValid with a repair order", () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
store.getters = {
|
||||
order: {
|
||||
serviceLocation: {
|
||||
zipCode: "12345",
|
||||
zipCodeCtu: "value",
|
||||
},
|
||||
damage: {
|
||||
isRepair: true,
|
||||
},
|
||||
referralNumber: "1234567",
|
||||
},
|
||||
};
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
});
|
||||
test("should pass arePagePrerequisitesValid with a replace order", () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
store.getters = {
|
||||
order: {
|
||||
serviceLocation: {
|
||||
zipCode: "12345",
|
||||
zipCodeCtu: "value",
|
||||
},
|
||||
damage: {
|
||||
isRepair: false,
|
||||
},
|
||||
referralNumber: "1234567",
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
});
|
||||
test("should fail arePagePrerequisitesValid without glass parts or flagged as repair", () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
store.getters = {
|
||||
order: {
|
||||
serviceLocation: {
|
||||
zipCode: "12345",
|
||||
zipCodeCtu: "value",
|
||||
},
|
||||
damage: {
|
||||
isRepair: false,
|
||||
},
|
||||
referralNumber: "1234567",
|
||||
},
|
||||
};
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(false);
|
||||
});
|
||||
test("should have non-null values for necessary data members after 'beforeRouteEnter'", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
//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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
// 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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
// 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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: null, // Ensure that previous selection isn't overriding selection
|
||||
},
|
||||
},
|
||||
};
|
||||
mockTierOnePrice = 200;
|
||||
// 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
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
store.getters = {
|
||||
order: {
|
||||
lineItems: {
|
||||
glassParts: ["item", "item2"],
|
||||
},
|
||||
payment: {
|
||||
isInsurance: null, // Ensure that previous selection isn't overriding selection
|
||||
},
|
||||
},
|
||||
};
|
||||
mockTierOnePrice = 505;
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks({ customMountOptions }) {
|
||||
|
|
@ -128,5 +420,6 @@ function setupMocks({ customMountOptions }) {
|
|||
mountOptions["attachTo"] = document.body;
|
||||
|
||||
const wrapper = shallowMount(quote, mountOptions);
|
||||
wrapper.vm.setCmsContent = jest.fn();
|
||||
return { wrapper };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ export default {
|
|||
];
|
||||
|
||||
const pricingResults = await baseMixin.methods.dispatchStoreAction(
|
||||
storeActions.PRICE_ORDER_ITEMS,
|
||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||
availableLineItems,
|
||||
false
|
||||
);
|
||||
|
|
|
|||
|
|
@ -90,13 +90,6 @@ describe("service-location.vue", () => {
|
|||
},
|
||||
};
|
||||
|
||||
serviceLocation.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "service-location" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(false);
|
||||
|
|
@ -105,13 +98,6 @@ describe("service-location.vue", () => {
|
|||
test("All prerequisites set: Should return true.", () => {
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
serviceLocation.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "service-location" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
|
|
@ -122,13 +108,6 @@ describe("service-location.vue", () => {
|
|||
|
||||
store.getters.order.serviceLocation.zipCode = null;
|
||||
|
||||
serviceLocation.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { fmgPage: "service-location" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
expect(arePagePrerequisitesValid).toBe(false);
|
||||
|
|
|
|||
|
|
@ -1416,7 +1416,7 @@ export const actions = {
|
|||
context.commit(storeMutations.UPDATE_VAPS, vaps);
|
||||
},
|
||||
// Price order actions
|
||||
async priceOrderItems(context, availableLineItems) {
|
||||
async priceOrderItemsAndSaveServerData(context, availableLineItems) {
|
||||
const availableLineItemsFormattedForRequest =
|
||||
getLineItemQueryStringForPricing(availableLineItems);
|
||||
const vehicle = context.getters.order.vehicle;
|
||||
|
|
|
|||
Loading…
Reference in a new issue