177 lines
5.2 KiB
JavaScript
177 lines
5.2 KiB
JavaScript
// Components
|
|
import vehicleModel from "@/layouts/vehicle-model/vehicle-model.vue";
|
|
import modelQuestion from "@/layouts/vehicle-model/model-question/model-question";
|
|
|
|
// Supporting files
|
|
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
|
import { shallowMount } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import { nextTick } from "vue";
|
|
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
import baseMixin from "@/mixins/base-mixin.js";
|
|
import store from "@/store";
|
|
|
|
// 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(),
|
|
}));
|
|
|
|
// Mock Store
|
|
jest.mock("@/store", () => ({
|
|
commit: jest.fn(),
|
|
dispatch: jest.fn(),
|
|
getters: {
|
|
vehicle: {
|
|
make: "Acura",
|
|
},
|
|
},
|
|
}));
|
|
|
|
describe("vehicle-model.vue", () => {
|
|
test("Model question component is initized with api data", async (done) => {
|
|
//Arange
|
|
const modelQuestionInitialData = ["accord", "civic", "insight"];
|
|
const { wrapper, apiPromise } = setupMocks({
|
|
modelQuestionInitialData: modelQuestionInitialData,
|
|
});
|
|
//Act
|
|
vehicleModel.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "vehicle-model" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
//Assert
|
|
apiPromise.finally(() => {
|
|
expect(modelQuestion.methods.initializeComponent).toHaveBeenCalledWith(
|
|
modelQuestionInitialData
|
|
);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("vehicle-model.vue", () => {
|
|
test("BackButtonAction triggers a router.navigate change", async (done) => {
|
|
//Arrange
|
|
const { wrapper, apiPromise } = setupMocks({
|
|
pageHeaderWidgetHeaderText: "Select a model to get started",
|
|
mountOptionsMockData: {
|
|
router: {
|
|
navigate: jest.fn(),
|
|
},
|
|
},
|
|
});
|
|
//Act
|
|
vehicleModel.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "vehicle-model" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
wrapper.vm.backButtonAction();
|
|
await nextTick();
|
|
//Assert
|
|
apiPromise.finally(() => {
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
describe("vehicle-model.vue", () => {
|
|
test("Make set, arePagePrerequisitesValid should be true ", async () => {
|
|
//Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
//Act
|
|
vehicleModel.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "vehicle-model" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
|
await nextTick();
|
|
|
|
//Assert
|
|
expect(arePagePrerequisitesValid).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("vehicle-model.vue", () => {
|
|
test("Year set, call invalidation, style, carId, category should be null", async () => {
|
|
|
|
//Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
//Act
|
|
vehicleModel.beforeRouteEnter.call(
|
|
wrapper.vm,
|
|
{ query: { fmgPage: "vehicle-model" } },
|
|
undefined,
|
|
(c) => c(wrapper.vm)
|
|
);
|
|
|
|
wrapper.vm.resetDependentState();
|
|
|
|
//Assert
|
|
expect(store.commit).toBeCalledWith(storeMutations.UPDATE_STYLE, null)
|
|
expect(store.commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, null)
|
|
expect(store.commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, null)
|
|
|
|
expect(store.dispatch).toBeCalledWith(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES)
|
|
expect(store.dispatch).toBeCalledWith(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES)
|
|
|
|
});
|
|
});
|
|
|
|
function setupMocks({
|
|
buttonQuestionContent = {},
|
|
modelQuestionInitialData = {},
|
|
pageHeaderWidgetHeaderText = {},
|
|
mountOptionsMockData = {},
|
|
}) {
|
|
//Mock api responses
|
|
const apiResponses = {
|
|
cmsContent: {
|
|
FunnelSubHeaderWidget: pageHeaderWidgetHeaderText,
|
|
VehicleModelQuestion: buttonQuestionContent,
|
|
VehicleBannerWidget: {
|
|
GenericVehicleImage:
|
|
"https://digitalconsumercms-dev.safelite.com/images/default-source/default-album/blurred-image.jpg?sfvrsn=a6ce3034_3",
|
|
},
|
|
FunnelHeaderWidget: {
|
|
LogoImage:
|
|
"https://digitalconsumercms-dev.safelite.com/images/default-source/default-album/safelite-logo.svg?sfvrsn=45e7ed06_3",
|
|
},
|
|
},
|
|
modelQuestionInitialData: modelQuestionInitialData,
|
|
};
|
|
const apiPromise = Promise.resolve(apiResponses);
|
|
|
|
settleAllPromises.mockImplementation(() => apiPromise);
|
|
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
|
|
|
//Mock model question methods
|
|
modelQuestion.methods = {
|
|
loadInitialData: jest.fn(),
|
|
initializeComponent: jest.fn(),
|
|
};
|
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
|
const wrapper = shallowMount(vehicleModel, mountOptions);
|
|
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
|
|
|
const modelQuestionWrapper = wrapper.findComponent({ name: "modelQuestion" });
|
|
modelQuestionWrapper.vm.initializeComponent =
|
|
modelQuestion.methods.initializeComponent;
|
|
|
|
return { wrapper, apiPromise };
|
|
}
|