mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 13:09:22 -06:00
9bd6ed887c
* Refactor: Makes PanelEditor use state and shows validation message on AlerTab * Refactor: Makes validation message nicer looking * Refactor: Changes imports * Refactor: Removes conditional props * Refactor: Changes after feedback from PR review * Refactor: Removes unused action
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
// @ts-ignore
|
|
import configureMockStore from 'redux-mock-store';
|
|
import thunk from 'redux-thunk';
|
|
import { ActionOf } from 'app/core/redux/actionCreatorFactory';
|
|
|
|
const mockStore = configureMockStore([thunk]);
|
|
|
|
export interface ThunkGiven {
|
|
givenThunk: (thunkFunction: any) => ThunkWhen;
|
|
}
|
|
|
|
export interface ThunkWhen {
|
|
whenThunkIsDispatched: (...args: any) => Promise<Array<ActionOf<any>>>;
|
|
}
|
|
|
|
export const thunkTester = (initialState: any, debug?: boolean): ThunkGiven => {
|
|
const store = mockStore(initialState);
|
|
let thunkUnderTest: any = null;
|
|
let dispatchedActions: Array<ActionOf<any>> = [];
|
|
|
|
const givenThunk = (thunkFunction: any): ThunkWhen => {
|
|
thunkUnderTest = thunkFunction;
|
|
|
|
return instance;
|
|
};
|
|
|
|
const whenThunkIsDispatched = async (...args: any): Promise<Array<ActionOf<any>>> => {
|
|
await store.dispatch(thunkUnderTest(...args));
|
|
|
|
dispatchedActions = store.getActions();
|
|
if (debug) {
|
|
console.log('resultingActions:', JSON.stringify(dispatchedActions, null, 2));
|
|
}
|
|
|
|
return dispatchedActions;
|
|
};
|
|
|
|
const instance = {
|
|
givenThunk,
|
|
whenThunkIsDispatched,
|
|
};
|
|
|
|
return instance;
|
|
};
|