Chore: Fixes various strict null errors (#21763)

* Chore: Removes strict null checks in ReducerTester

* Chore: Fixes strict null errors in ConfigureStore

* Chore: Fixes strict null errors in reducer tests

* Chore: Fixes strict null errors in reducers tests

* Chore: Fixes strict null errors in reducers tests

* Chore: Fixes strict null errors in toggleLogActionsMiddleware

* Chore: Fixes strict null errors in navModelReducer

* Core: Fixes strict null errors in public/app/features/admin/state

* Chore: Fixes strict null errors in public/app/features/dashboard/state/reducers.test.ts

* Chore: Fixes strict null errors in public/app/features/explore/state/reducers.test.ts

* Chore: Fixes strict null errors in public/app/features/datasources/state/reducers.test.ts

* Chore: Fixes strict null errors in public/e2e-test/scenarios/templating/templatevariables-crud.test.ts

* Chore: Fixes strict null errors in public/app/features/dashboard/containers/DashboardPage.test.tsx
This commit is contained in:
Hugo Häggmark
2020-01-28 09:13:56 +01:00
committed by GitHub
parent 6c32a4c0ab
commit 044bea0935
15 changed files with 181 additions and 152 deletions

View File

@@ -1,4 +1,12 @@
import { DataQuery, DataSourceApi, dateTime, LoadingState, LogsDedupStrategy, toDataFrame } from '@grafana/data';
import {
DataQuery,
DataSourceApi,
dateTime,
LoadingState,
LogsDedupStrategy,
RawTimeRange,
toDataFrame,
} from '@grafana/data';
import {
createEmptyQueryResponse,
@@ -24,6 +32,7 @@ import {
} from './actionTypes';
import { serializeStateToUrlParam } from 'app/core/utils/explore';
import { updateLocation } from '../../../core/actions';
import { UrlQueryMap } from '@grafana/runtime';
describe('Explore item reducer', () => {
describe('scanning', () => {
@@ -33,7 +42,7 @@ describe('Explore item reducer', () => {
scanning: false,
};
reducerTester()
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, initialState)
.whenActionIsDispatched(scanStartAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({
@@ -45,10 +54,10 @@ describe('Explore item reducer', () => {
const initialState = {
...makeExploreItemState(),
scanning: true,
scanRange: {},
scanRange: {} as RawTimeRange,
};
reducerTester()
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, initialState)
.whenActionIsDispatched(scanStopAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({
@@ -62,8 +71,8 @@ describe('Explore item reducer', () => {
describe('changing datasource', () => {
describe('when changeMode is dispatched', () => {
it('then it should set correct state', () => {
reducerTester()
.givenReducer(itemReducer, {})
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, ({} as unknown) as ExploreItemState)
.whenActionIsDispatched(changeModeAction({ exploreId: ExploreId.left, mode: ExploreMode.Logs }))
.thenStatePredicateShouldEqual((resultingState: ExploreItemState) => {
expect(resultingState.mode).toEqual(ExploreMode.Logs);
@@ -90,11 +99,11 @@ describe('Explore item reducer', () => {
} as DataSourceApi;
const queries: DataQuery[] = [];
const queryKeys: string[] = [];
const initialState: Partial<ExploreItemState> = {
const initialState: ExploreItemState = ({
datasourceInstance: null,
queries,
queryKeys,
};
} as unknown) as ExploreItemState;
const expectedState: any = {
datasourceInstance,
queries,
@@ -109,7 +118,7 @@ describe('Explore item reducer', () => {
queryResponse: createEmptyQueryResponse(),
};
reducerTester()
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, initialState)
.whenActionIsDispatched(updateDatasourceInstanceAction({ exploreId: ExploreId.left, datasourceInstance }))
.thenStateShouldEqual(expectedState);
@@ -135,7 +144,7 @@ describe('Explore item reducer', () => {
state: LoadingState.Streaming,
},
};
reducerTester()
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, initialState)
.whenActionIsDispatched(changeRefreshIntervalAction({ exploreId: ExploreId.left, refreshInterval: 'LIVE' }))
.thenStateShouldEqual(expectedState);
@@ -155,7 +164,7 @@ describe('Explore item reducer', () => {
state: LoadingState.Done,
},
};
reducerTester()
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, initialState)
.whenActionIsDispatched(changeRefreshIntervalAction({ exploreId: ExploreId.left, refreshInterval: '' }))
.thenStateShouldEqual(expectedState);
@@ -165,12 +174,12 @@ describe('Explore item reducer', () => {
describe('toggling panels', () => {
describe('when toggleGraphAction is dispatched', () => {
it('then it should set correct state', () => {
reducerTester()
.givenReducer(itemReducer, { graphResult: [] })
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, ({ graphResult: [] } as unknown) as ExploreItemState)
.whenActionIsDispatched(toggleGraphAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({ showingGraph: true, graphResult: [] })
.thenStateShouldEqual(({ showingGraph: true, graphResult: [] } as unknown) as ExploreItemState)
.whenActionIsDispatched(toggleGraphAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({ showingGraph: false, graphResult: null });
.thenStateShouldEqual(({ showingGraph: false, graphResult: null } as unknown) as ExploreItemState);
});
});
@@ -187,12 +196,12 @@ describe('Explore item reducer', () => {
],
});
reducerTester()
.givenReducer(itemReducer, { tableResult: table })
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, ({ tableResult: table } as unknown) as ExploreItemState)
.whenActionIsDispatched(toggleTableAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({ showingTable: true, tableResult: table })
.thenStateShouldEqual(({ showingTable: true, tableResult: table } as unknown) as ExploreItemState)
.whenActionIsDispatched(toggleTableAction({ exploreId: ExploreId.left }))
.thenStateShouldEqual({ showingTable: false, tableResult: null });
.thenStateShouldEqual(({ showingTable: false, tableResult: null } as unknown) as ExploreItemState);
});
});
});
@@ -200,12 +209,12 @@ describe('Explore item reducer', () => {
describe('changing range', () => {
describe('when changeRangeAction is dispatched', () => {
it('then it should set correct state', () => {
reducerTester()
.givenReducer(itemReducer, {
reducerTester<ExploreItemState>()
.givenReducer(itemReducer, ({
update: { ...makeInitialUpdateState(), range: true },
range: null,
absoluteRange: null,
})
} as unknown) as ExploreItemState)
.whenActionIsDispatched(
changeRangeAction({
exploreId: ExploreId.left,
@@ -213,11 +222,11 @@ describe('Explore item reducer', () => {
range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } },
})
)
.thenStateShouldEqual({
.thenStateShouldEqual(({
update: { ...makeInitialUpdateState(), range: false },
absoluteRange: { from: 1546297200000, to: 1546383600000 },
range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } },
});
} as unknown) as ExploreItemState);
});
});
});
@@ -242,7 +251,11 @@ export const setup = (urlStateOverrides?: any) => {
};
const urlState: ExploreUrlState = { ...urlStateDefaults, ...urlStateOverrides };
const serializedUrlState = serializeStateToUrlParam(urlState);
const initialState = { split: false, left: { urlState, update }, right: { urlState, update } };
const initialState = ({
split: false,
left: { urlState, update },
right: { urlState, update },
} as unknown) as ExploreState;
return {
initialState,
@@ -253,76 +266,76 @@ export const setup = (urlStateOverrides?: any) => {
describe('Explore reducer', () => {
describe('split view', () => {
it("should make right pane a duplicate of the given item's state on split open", () => {
const leftItemMock = {
const leftItemMock = ({
containerWidth: 100,
} as ExploreItemState;
} as unknown) as ExploreItemState;
const initialState = {
const initialState = ({
split: null,
left: leftItemMock as ExploreItemState,
right: makeExploreItemState(),
} as ExploreState;
} as unknown) as ExploreState;
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(splitOpenAction({ itemState: leftItemMock }))
.thenStateShouldEqual({
.thenStateShouldEqual(({
split: true,
left: leftItemMock,
right: leftItemMock,
});
} as unknown) as ExploreState);
});
describe('split close', () => {
it('should keep right pane as left when left is closed', () => {
const leftItemMock = {
const leftItemMock = ({
containerWidth: 100,
} as ExploreItemState;
} as unknown) as ExploreItemState;
const rightItemMock = {
const rightItemMock = ({
containerWidth: 200,
} as ExploreItemState;
} as unknown) as ExploreItemState;
const initialState = {
const initialState = ({
split: null,
left: leftItemMock,
right: rightItemMock,
} as ExploreState;
} as unknown) as ExploreState;
// closing left item
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(splitCloseAction({ itemId: ExploreId.left }))
.thenStateShouldEqual({
.thenStateShouldEqual(({
split: false,
left: rightItemMock,
right: initialExploreState.right,
});
} as unknown) as ExploreState);
});
it('should reset right pane when it is closed ', () => {
const leftItemMock = {
const leftItemMock = ({
containerWidth: 100,
} as ExploreItemState;
} as unknown) as ExploreItemState;
const rightItemMock = {
const rightItemMock = ({
containerWidth: 200,
} as ExploreItemState;
} as unknown) as ExploreItemState;
const initialState = {
const initialState = ({
split: null,
left: leftItemMock,
right: rightItemMock,
} as ExploreState;
} as unknown) as ExploreState;
// closing left item
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(splitCloseAction({ itemId: ExploreId.right }))
.thenStateShouldEqual({
.thenStateShouldEqual(({
split: false,
left: leftItemMock,
right: initialExploreState.right,
});
} as unknown) as ExploreState);
});
});
});
@@ -330,20 +343,20 @@ describe('Explore reducer', () => {
describe('when updateLocation is dispatched', () => {
describe('and payload does not contain a query', () => {
it('then it should just return state', () => {
reducerTester()
.givenReducer(exploreReducer, {})
.whenActionIsDispatched(updateLocation({ query: null }))
.thenStateShouldEqual({});
reducerTester<ExploreState>()
.givenReducer(exploreReducer, ({} as unknown) as ExploreState)
.whenActionIsDispatched(updateLocation({ query: (null as unknown) as UrlQueryMap }))
.thenStateShouldEqual(({} as unknown) as ExploreState);
});
});
describe('and payload contains a query', () => {
describe("but does not contain 'left'", () => {
it('then it should just return state', () => {
reducerTester()
.givenReducer(exploreReducer, {})
reducerTester<ExploreState>()
.givenReducer(exploreReducer, ({} as unknown) as ExploreState)
.whenActionIsDispatched(updateLocation({ query: {} }))
.thenStateShouldEqual({});
.thenStateShouldEqual(({} as unknown) as ExploreState);
});
});
@@ -352,7 +365,7 @@ describe('Explore reducer', () => {
const { initialState, serializedUrlState } = setup();
const expectedState = { ...initialState, split: true };
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(
updateLocation({
@@ -370,11 +383,11 @@ describe('Explore reducer', () => {
describe('but urlState is not set in state', () => {
it('then it should just add urlState and update in state', () => {
const { initialState, serializedUrlState } = setup();
const urlState: ExploreUrlState = null;
const stateWithoutUrlState = { ...initialState, left: { urlState } };
const urlState: ExploreUrlState = (null as unknown) as ExploreUrlState;
const stateWithoutUrlState = ({ ...initialState, left: { urlState } } as unknown) as ExploreState;
const expectedState = { ...initialState };
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, stateWithoutUrlState)
.whenActionIsDispatched(
updateLocation({
@@ -393,7 +406,7 @@ describe('Explore reducer', () => {
const { initialState, serializedUrlState } = setup();
const expectedState = { ...initialState };
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(
updateLocation({
@@ -432,7 +445,7 @@ describe('Explore reducer', () => {
},
};
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, stateWithDifferentDataSource)
.whenActionIsDispatched(
updateLocation({
@@ -473,7 +486,7 @@ describe('Explore reducer', () => {
},
};
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, stateWithDifferentDataSource)
.whenActionIsDispatched(
updateLocation({
@@ -511,7 +524,7 @@ describe('Explore reducer', () => {
},
};
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, stateWithDifferentDataSource)
.whenActionIsDispatched(
updateLocation({
@@ -552,7 +565,7 @@ describe('Explore reducer', () => {
},
};
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, stateWithDifferentDataSource)
.whenActionIsDispatched(
updateLocation({
@@ -571,7 +584,7 @@ describe('Explore reducer', () => {
const { initialState, serializedUrlState } = setup();
const expectedState = { ...initialState };
reducerTester()
reducerTester<ExploreState>()
.givenReducer(exploreReducer, initialState)
.whenActionIsDispatched(
updateLocation({