99 lines
2.7 KiB
JavaScript
99 lines
2.7 KiB
JavaScript
import baseMixin from "@/mixins/base-mixin";
|
|
import { storeActions } from "@/constants/store-actions.js";
|
|
import { widgetNames } from "@/constants/widget-names.js";
|
|
import { storeMutations } from "@/constants/store-mutations.js";
|
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
|
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("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: widgetNames should be equal to import object", () => {
|
|
// Arrange
|
|
const mixIn = getMixInInstance({});
|
|
|
|
// Act
|
|
let widgetNamesForTest = mixIn.computed.widgetNames();
|
|
|
|
// Assert
|
|
expect(widgetNamesForTest).toEqual(widgetNames);
|
|
});
|
|
});
|
|
|
|
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;
|
|
store.dispatch = storeDispatch;
|
|
baseMixIn.methods.storeActions = storeActions;
|
|
baseMixIn.methods.widgetNames = widgetNames;
|
|
|
|
return baseMixIn;
|
|
}
|