mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -15,11 +15,11 @@ jest.mock('app/features/dashboard/components/DashboardSettings/SettingsCtrl', ()
|
||||
|
||||
interface ScenarioContext {
|
||||
cleanUpDashboardMock: ToolkitActionCreatorWithoutPayloadMockType;
|
||||
dashboard?: DashboardModel;
|
||||
dashboard?: DashboardModel | null;
|
||||
setDashboardProp: (overrides?: any, metaOverrides?: any) => void;
|
||||
wrapper?: ShallowWrapper<Props, State, DashboardPage>;
|
||||
mount: (propOverrides?: Partial<Props>) => void;
|
||||
setup?: (fn: () => void) => void;
|
||||
setup: (fn: () => void) => void;
|
||||
}
|
||||
|
||||
function getTestDashboard(overrides?: any, metaOverrides?: any): DashboardModel {
|
||||
@@ -53,7 +53,7 @@ function dashboardPageScenario(description: string, scenarioFn: (ctx: ScenarioCo
|
||||
},
|
||||
setDashboardProp: (overrides?: any, metaOverrides?: any) => {
|
||||
ctx.dashboard = getTestDashboard(overrides, metaOverrides);
|
||||
ctx.wrapper.setProps({ dashboard: ctx.dashboard });
|
||||
ctx.wrapper?.setProps({ dashboard: ctx.dashboard });
|
||||
},
|
||||
mount: (propOverrides?: Partial<Props>) => {
|
||||
const props: Props = {
|
||||
@@ -102,7 +102,7 @@ describe('DashboardPage', () => {
|
||||
dashboardPageScenario('Dashboard is fetching slowly', ctx => {
|
||||
ctx.setup(() => {
|
||||
ctx.mount();
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setProps({
|
||||
isInitSlow: true,
|
||||
initPhase: DashboardInitPhase.Fetching,
|
||||
});
|
||||
@@ -132,7 +132,7 @@ describe('DashboardPage', () => {
|
||||
ctx.setup(() => {
|
||||
ctx.mount();
|
||||
ctx.setDashboardProp();
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setProps({
|
||||
urlFullscreen: true,
|
||||
urlEdit: true,
|
||||
urlPanelId: '1',
|
||||
@@ -140,14 +140,16 @@ describe('DashboardPage', () => {
|
||||
});
|
||||
|
||||
it('Should update model state to fullscreen & edit', () => {
|
||||
expect(ctx.dashboard.meta.fullscreen).toBe(true);
|
||||
expect(ctx.dashboard.meta.isEditing).toBe(true);
|
||||
expect(ctx.dashboard).not.toBe(null);
|
||||
expect(ctx.dashboard?.meta.fullscreen).toBe(true);
|
||||
expect(ctx.dashboard?.meta.isEditing).toBe(true);
|
||||
});
|
||||
|
||||
it('Should update component state to fullscreen and edit', () => {
|
||||
const state = ctx.wrapper.state();
|
||||
expect(state.isEditing).toBe(true);
|
||||
expect(state.isFullscreen).toBe(true);
|
||||
const state = ctx.wrapper?.state();
|
||||
expect(state).not.toBe(null);
|
||||
expect(state?.isEditing).toBe(true);
|
||||
expect(state?.isFullscreen).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -155,29 +157,32 @@ describe('DashboardPage', () => {
|
||||
ctx.setup(() => {
|
||||
ctx.mount();
|
||||
ctx.setDashboardProp();
|
||||
ctx.wrapper.setState({ scrollTop: 100 });
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setState({ scrollTop: 100 });
|
||||
ctx.wrapper?.setProps({
|
||||
urlFullscreen: true,
|
||||
urlEdit: true,
|
||||
urlPanelId: '1',
|
||||
});
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setProps({
|
||||
urlFullscreen: false,
|
||||
urlEdit: false,
|
||||
urlPanelId: null,
|
||||
urlPanelId: (null as unknown) as string,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should update model state normal state', () => {
|
||||
expect(ctx.dashboard.meta.fullscreen).toBe(false);
|
||||
expect(ctx.dashboard.meta.isEditing).toBe(false);
|
||||
expect(ctx.dashboard).not.toBe(null);
|
||||
expect(ctx.dashboard?.meta.fullscreen).toBe(false);
|
||||
expect(ctx.dashboard?.meta.isEditing).toBe(false);
|
||||
});
|
||||
|
||||
it('Should update component state to normal and restore scrollTop', () => {
|
||||
const state = ctx.wrapper.state();
|
||||
expect(state.isEditing).toBe(false);
|
||||
expect(state.isFullscreen).toBe(false);
|
||||
expect(state.scrollTop).toBe(100);
|
||||
const state = ctx.wrapper?.state();
|
||||
expect(ctx.wrapper).not.toBe(null);
|
||||
expect(state).not.toBe(null);
|
||||
expect(state?.isEditing).toBe(false);
|
||||
expect(state?.isFullscreen).toBe(false);
|
||||
expect(state?.scrollTop).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -185,7 +190,7 @@ describe('DashboardPage', () => {
|
||||
ctx.setup(() => {
|
||||
ctx.mount();
|
||||
ctx.setDashboardProp();
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setProps({
|
||||
editview: 'settings',
|
||||
});
|
||||
});
|
||||
@@ -195,7 +200,7 @@ describe('DashboardPage', () => {
|
||||
});
|
||||
|
||||
it('should set animation state', () => {
|
||||
expect(ctx.wrapper.state().isSettingsOpening).toBe(true);
|
||||
expect(ctx.wrapper?.state().isSettingsOpening).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -203,16 +208,19 @@ describe('DashboardPage', () => {
|
||||
ctx.setup(() => {
|
||||
ctx.mount();
|
||||
ctx.setDashboardProp();
|
||||
ctx.wrapper.setState({ scrollTop: 100 });
|
||||
ctx.wrapper.instance().onAddPanel();
|
||||
ctx.wrapper?.setState({ scrollTop: 100 });
|
||||
ctx.wrapper?.instance().onAddPanel();
|
||||
});
|
||||
|
||||
it('should set scrollTop to 0', () => {
|
||||
expect(ctx.wrapper.state().scrollTop).toBe(0);
|
||||
expect(ctx.wrapper).not.toBe(null);
|
||||
expect(ctx.wrapper?.state()).not.toBe(null);
|
||||
expect(ctx.wrapper?.state().scrollTop).toBe(0);
|
||||
});
|
||||
|
||||
it('should add panel widget to dashboard panels', () => {
|
||||
expect(ctx.dashboard.panels[0].type).toBe('add-panel');
|
||||
expect(ctx.dashboard).not.toBe(null);
|
||||
expect(ctx.dashboard?.panels[0].type).toBe('add-panel');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,7 +231,7 @@ describe('DashboardPage', () => {
|
||||
panels: [{ id: 0, type: 'graph' }],
|
||||
schemaVersion: 17,
|
||||
});
|
||||
ctx.wrapper.setProps({
|
||||
ctx.wrapper?.setProps({
|
||||
urlEdit: true,
|
||||
urlFullscreen: true,
|
||||
urlPanelId: '0',
|
||||
@@ -231,8 +239,11 @@ describe('DashboardPage', () => {
|
||||
});
|
||||
|
||||
it('Should go into edit mode', () => {
|
||||
expect(ctx.wrapper.state().isEditing).toBe(true);
|
||||
expect(ctx.wrapper.state().fullscreenPanel.id).toBe(0);
|
||||
const state = ctx.wrapper?.state();
|
||||
expect(ctx.wrapper).not.toBe(null);
|
||||
expect(state).not.toBe(null);
|
||||
expect(state?.fullscreenPanel).not.toBe(null);
|
||||
expect(state?.fullscreenPanel?.id).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -243,7 +254,7 @@ describe('DashboardPage', () => {
|
||||
panels: [{ id: 0, type: 'graph' }],
|
||||
schemaVersion: 17,
|
||||
});
|
||||
ctx.wrapper.unmount();
|
||||
ctx.wrapper?.unmount();
|
||||
});
|
||||
|
||||
it('Should call clean up action', () => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
panelEditorCleanUp,
|
||||
panelEditorInitCompleted,
|
||||
panelEditorReducer,
|
||||
PanelEditorState,
|
||||
PanelEditorTab,
|
||||
PanelEditorTabIds,
|
||||
} from './reducers';
|
||||
@@ -18,7 +19,7 @@ describe('panelEditorReducer', () => {
|
||||
getPanelEditorTab(PanelEditorTabIds.Visualization),
|
||||
getPanelEditorTab(PanelEditorTabIds.Advanced),
|
||||
];
|
||||
reducerTester()
|
||||
reducerTester<PanelEditorState>()
|
||||
.givenReducer(panelEditorReducer, initialState)
|
||||
.whenActionIsDispatched(panelEditorInitCompleted({ activeTab, tabs }))
|
||||
.thenStateShouldEqual({ activeTab, tabs });
|
||||
@@ -33,7 +34,7 @@ describe('panelEditorReducer', () => {
|
||||
getPanelEditorTab(PanelEditorTabIds.Visualization),
|
||||
getPanelEditorTab(PanelEditorTabIds.Advanced),
|
||||
];
|
||||
reducerTester()
|
||||
reducerTester<PanelEditorState>()
|
||||
.givenReducer(panelEditorReducer, { activeTab, tabs })
|
||||
.whenActionIsDispatched(panelEditorCleanUp())
|
||||
.thenStateShouldEqual(initialState);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
loadDashboardPermissions,
|
||||
dashboardInitFetching,
|
||||
dashboardInitCompleted,
|
||||
dashboardInitFailed,
|
||||
dashboardInitFetching,
|
||||
dashboardInitSlow,
|
||||
loadDashboardPermissions,
|
||||
} from './actions';
|
||||
import { OrgRole, PermissionLevel, DashboardState, DashboardInitPhase } from 'app/types';
|
||||
import { initialState, dashboardReducer } from './reducers';
|
||||
import { DashboardInitPhase, DashboardState, OrgRole, PermissionLevel } from 'app/types';
|
||||
import { dashboardReducer, initialState } from './reducers';
|
||||
import { DashboardModel } from './DashboardModel';
|
||||
|
||||
describe('dashboard reducer', () => {
|
||||
@@ -22,7 +22,7 @@ describe('dashboard reducer', () => {
|
||||
});
|
||||
|
||||
it('should add permissions to state', async () => {
|
||||
expect(state.permissions.length).toBe(2);
|
||||
expect(state.permissions?.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('dashboard reducer', () => {
|
||||
});
|
||||
|
||||
it('should set model', async () => {
|
||||
expect(state.model.title).toBe('My dashboard');
|
||||
expect(state.model?.title).toBe('My dashboard');
|
||||
});
|
||||
|
||||
it('should set reset isInitSlow', async () => {
|
||||
@@ -53,7 +53,7 @@ describe('dashboard reducer', () => {
|
||||
});
|
||||
|
||||
it('should set model', async () => {
|
||||
expect(state.model.title).toBe('Dashboard init failed');
|
||||
expect(state.model?.title).toBe('Dashboard init failed');
|
||||
});
|
||||
|
||||
it('should set reset isInitSlow', async () => {
|
||||
@@ -61,7 +61,7 @@ describe('dashboard reducer', () => {
|
||||
});
|
||||
|
||||
it('should set initError', async () => {
|
||||
expect(state.initError.message).toBe('Oh no');
|
||||
expect(state.initError?.message).toBe('Oh no');
|
||||
});
|
||||
|
||||
it('should set phase failed', async () => {
|
||||
|
||||
Reference in New Issue
Block a user