55 lines
No EOL
1.6 KiB
JavaScript
55 lines
No EOL
1.6 KiB
JavaScript
import baseMixin from "@/mixins/base-mixin"
|
|
import { storeActions } from "@/constants/store-actions.js";
|
|
import { widgetNames } from "@/constants/widget-names.js";
|
|
import { flushPromises } from "@vue/test-utils";
|
|
|
|
describe("baseMixin.js", () => {
|
|
test('dispatchNonblockingStoreAction: calls dispatch with type and payload', () => {
|
|
const mixIn = getMixInInstance({});
|
|
const type = {};
|
|
const payload = {};
|
|
|
|
mixIn.methods.dispatchNonBlockingStoreAction(type, payload);
|
|
|
|
expect(mixIn.methods.$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(mixIn.methods.$store.dispatch).toBeCalledWith(type, payload);
|
|
});
|
|
})
|
|
function getMixInInstance({ isDispatchSuccess = true }) {
|
|
|
|
// Mock Store
|
|
const store = {
|
|
dispatch: jest.fn()
|
|
}
|
|
|
|
if (isDispatchSuccess) {
|
|
store.dispatch.mockReturnValue(Promise.resolve())
|
|
} else {
|
|
store.dispatch.mockReturnValue(Promise.reject())
|
|
}
|
|
|
|
// Mock Route
|
|
const route = {
|
|
query: {
|
|
fmgPage: 'test-page'
|
|
}
|
|
};
|
|
|
|
// Attach mocks to mixin
|
|
const baseMixIn = baseMixin;
|
|
baseMixIn.methods.$route = route;
|
|
baseMixIn.methods.$store = store;
|
|
baseMixIn.methods.storeActions = storeActions;
|
|
baseMixIn.methods.widgetNames = widgetNames;
|
|
|
|
return baseMixIn;
|
|
} |