Feat: Adds reconnect for failing datasource in Explore (#16226)

* Style: made outlined buttons and used it in Alert component

* Refactor: clean up state on load data source failure

* Refactor: test data source thunk created

* Refactor: move logic to changeDatasource and call that from intialize

* Refactor: move load explore datasources to own thunk

* Refactor: move logic to updateDatasourceInstanceAction

* Tests: reducer tests

* Test(Explore): Added tests and made thunkTester async

* Fix(Explore): Fixed so that we do not render StartPage if there is no StartPage

* Fix(Explore): Missed type in merge

* Refactor: Thunktester did not fail tests on async failures and prevented queires from running on datasource failures

* Feat: Fadein error alert to prevent flickering

* Feat: Refresh labels after reconnect

* Refactor: Move useLokiForceLabels into useLokiLabels from PR comments

* Feat: adds refresh metrics to Prometheus languageprovider

* Style: removes padding for connected datasources

* Chore: remove implicit anys
This commit is contained in:
Hugo Häggmark
2019-04-01 07:38:00 +02:00
committed by GitHub
parent e69039d8d1
commit 988b7c4dc3
21 changed files with 796 additions and 348 deletions

View File

@@ -1,3 +1,4 @@
// @ts-ignore
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { ActionOf } from 'app/core/redux/actionCreatorFactory';
@@ -9,18 +10,13 @@ export interface ThunkGiven {
}
export interface ThunkWhen {
whenThunkIsDispatched: (...args: any) => ThunkThen;
whenThunkIsDispatched: (...args: any) => Promise<Array<ActionOf<any>>>;
}
export interface ThunkThen {
thenDispatchedActionsEqual: (actions: Array<ActionOf<any>>) => ThunkWhen;
thenDispatchedActionsAreEqual: (callback: (actions: Array<ActionOf<any>>) => boolean) => ThunkWhen;
thenThereAreNoDispatchedActions: () => ThunkWhen;
}
export const thunkTester = (initialState: any): ThunkGiven => {
export const thunkTester = (initialState: any, debug?: boolean): ThunkGiven => {
const store = mockStore(initialState);
let thunkUnderTest = null;
let thunkUnderTest: any = null;
let dispatchedActions: Array<ActionOf<any>> = [];
const givenThunk = (thunkFunction: any): ThunkWhen => {
thunkUnderTest = thunkFunction;
@@ -28,36 +24,20 @@ export const thunkTester = (initialState: any): ThunkGiven => {
return instance;
};
function whenThunkIsDispatched(...args: any): ThunkThen {
store.dispatch(thunkUnderTest(...arguments));
const whenThunkIsDispatched = async (...args: any): Promise<Array<ActionOf<any>>> => {
await store.dispatch(thunkUnderTest(...args));
return instance;
}
dispatchedActions = store.getActions();
if (debug) {
console.log('resultingActions:', dispatchedActions);
}
const thenDispatchedActionsEqual = (actions: Array<ActionOf<any>>): ThunkWhen => {
const resultingActions = store.getActions();
expect(resultingActions).toEqual(actions);
return instance;
};
const thenDispatchedActionsAreEqual = (callback: (dispathedActions: Array<ActionOf<any>>) => boolean): ThunkWhen => {
const resultingActions = store.getActions();
expect(callback(resultingActions)).toBe(true);
return instance;
};
const thenThereAreNoDispatchedActions = () => {
return thenDispatchedActionsEqual([]);
return dispatchedActions;
};
const instance = {
givenThunk,
whenThunkIsDispatched,
thenDispatchedActionsEqual,
thenDispatchedActionsAreEqual,
thenThereAreNoDispatchedActions,
};
return instance;