127 lines
3.6 KiB
JavaScript
127 lines
3.6 KiB
JavaScript
import baseMixin from "@/mixins/base-mixin";
|
|
import { storeActions } from "@/constants/store-actions.js";
|
|
import { storeMutations } from "@/constants/store-mutations.js";
|
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
|
import { vehicleCategories } from "@/constants/vehicle-categories.js";
|
|
import store from "@/store";
|
|
|
|
describe("baseMixin.js", () => {
|
|
test("dispatchNonblockingStoreAction: calls dispatch with type and payload", () => {
|
|
const mixIn = getMixInInstance({});
|
|
const type = "";
|
|
const payload = {};
|
|
|
|
mixIn.methods.dispatchNonBlockingStoreAction(type, payload);
|
|
|
|
expect(store.dispatch).toBeCalledWith(type, payload);
|
|
});
|
|
|
|
test("dispatchNonblockingStoreAction: calls dispatch with type and payload, handles Uri encode", () => {
|
|
const mixIn = getMixInInstance({});
|
|
const type = "";
|
|
const payload = { make: "Alfa Romeo/Chrysler" };
|
|
|
|
mixIn.methods.dispatchNonBlockingStoreAction(type, payload, true);
|
|
|
|
expect(store.dispatch).toBeCalledWith(type, payload);
|
|
});
|
|
|
|
test("savePageDataToStore, should call store commit", () => {
|
|
const mixIn = getMixInInstance({});
|
|
|
|
mixIn.methods.savePageDataToStore('vehicle-year', {});
|
|
|
|
expect(store.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, { page: 'vehicle-year', data: {}});
|
|
});
|
|
|
|
test("computed: storeActions should be equal to import object", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
|
|
// Act
|
|
let storeActionsForTest = mixIn.computed.storeActions();
|
|
|
|
// Assert
|
|
expect(storeActionsForTest).toEqual(storeActions);
|
|
});
|
|
|
|
test("computed: storeMutations should be equal to import object", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
|
|
// Act
|
|
let storeMutationsForTest = mixIn.computed.storeMutations();
|
|
|
|
// Assert
|
|
expect(storeMutationsForTest).toEqual(storeMutations);
|
|
});
|
|
|
|
test("computed: navigationScenarios should be equal to import object", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
|
|
// Act
|
|
let navigationScenariosForTest = mixIn.computed.navigationScenarios();
|
|
|
|
// Assert
|
|
expect(navigationScenariosForTest).toEqual(navigationScenarios);
|
|
});
|
|
test("computed: vehicleCategories should be equal to import object", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
|
|
// Act
|
|
let vehicleCategoriesForTest = mixIn.computed.vehicleCategories();
|
|
|
|
// Assert
|
|
expect(vehicleCategoriesForTest).toEqual(vehicleCategories);
|
|
});
|
|
|
|
test("onInvalidSubmit: puts focus on first error", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
const validationData = {
|
|
errors: {
|
|
fieldOne: 'error message 1',
|
|
fieldTwo: 'error message 2',
|
|
}
|
|
};
|
|
|
|
global.document.querySelector = jest.fn();
|
|
|
|
// Act
|
|
mixIn.methods.onInvalidSubmit(validationData);
|
|
|
|
// Assert
|
|
expect(global.document.querySelector).toBeCalledWith("[data-focus-target='fieldOne']");
|
|
});
|
|
});
|
|
|
|
function getMixInInstance({ isDispatchSuccess = true }) {
|
|
// Mock Store
|
|
const storeDispatch = jest.fn();
|
|
|
|
if (isDispatchSuccess) {
|
|
storeDispatch.mockReturnValue(Promise.resolve());
|
|
} else {
|
|
storeDispatch.mockReturnValue(Promise.reject());
|
|
}
|
|
|
|
// Mock Route
|
|
const route = {
|
|
query: {
|
|
fmgPage: "test-page",
|
|
},
|
|
};
|
|
|
|
// Attach mocks to mixin
|
|
const baseMixIn = baseMixin;
|
|
baseMixIn.methods.$route = route;
|
|
baseMixIn.methods.storeActions = storeActions;
|
|
baseMixIn.methods.vehicleCategories = vehicleCategories;
|
|
|
|
store.dispatch = storeDispatch;
|
|
store.commit = jest.fn();
|
|
|
|
return baseMixIn;
|
|
}
|