Chore: fix type errors in tests (#63270)

* fix any's in tests

* fix more any's in tests

* more test type fixes

* fixing any's in tests part 3

* more test type fixes

* fixing test any's p5

* some tidy up

* fix template_srv
This commit is contained in:
Ashley Harrison
2023-02-14 16:46:42 +01:00
committed by GitHub
parent 4b0faf1c9e
commit f8d89eff56
139 changed files with 675 additions and 1080 deletions

View File

@@ -20,7 +20,7 @@ jest.mock('app/core/store', () => {
});
jest.mock('@grafana/runtime', () => ({
...(jest.requireActual('@grafana/runtime') as unknown as object),
...jest.requireActual('@grafana/runtime'),
getDataSourceSrv: () => {
return {
get: (v: any) => {

View File

@@ -1,6 +1,6 @@
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
import { setContextSrv } from '../../../../core/services/context_srv';
import { ContextSrv, setContextSrv } from '../../../../core/services/context_srv';
import { PanelModel } from '../../state/PanelModel';
import { createDashboardModelFixture, createPanelJSONFixture } from '../../state/__fixtures__/dashboardFixtures';
@@ -32,7 +32,7 @@ function getDefaultDashboardModel() {
}
function getTestContext() {
const contextSrv: any = { isSignedIn: true, isEditor: true };
const contextSrv = { isSignedIn: true, isEditor: true } as ContextSrv;
setContextSrv(contextSrv);
const dash = getDefaultDashboardModel();
const original = dash.getSaveModelClone();

View File

@@ -10,6 +10,7 @@ import {
PanelData,
standardEditorsRegistry,
standardFieldConfigEditorRegistry,
TimeRange,
toDataFrame,
} from '@grafana/data';
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
@@ -42,7 +43,7 @@ class OptionsPaneOptionsTestScenario {
panelData: PanelData = {
series: [],
state: LoadingState.Done,
timeRange: {} as any,
timeRange: {} as TimeRange,
};
plugin = getPanelPlugin({

View File

@@ -1,4 +1,6 @@
import { PanelPlugin } from '@grafana/data';
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
import { LibraryElementDTOMeta } from '@grafana/schema';
import { createDashboardModelFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
import { panelModelAndPluginReady, removePanel } from 'app/features/panel/state/reducers';
@@ -104,7 +106,7 @@ describe('panelEditor actions', () => {
const sourcePanel = new PanelModel({ id: 12, type: 'graph' });
sourcePanel.plugin = {
customFieldConfigs: {},
} as any;
} as unknown as PanelPlugin;
const dashboard = createDashboardModelFixture({
panels: [{ id: 12, type: 'graph' }],
@@ -242,9 +244,9 @@ describe('panelEditor actions', () => {
describe('skipPanelUpdate', () => {
describe('when called with panel with an library uid different from the modified panel', () => {
it('then it should return true', () => {
const meta: any = {};
const modified: any = { libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const panel: any = { libraryPanel: { uid: '456', name: 'Name', meta, version: 1 } };
const meta = {} as LibraryElementDTOMeta;
const modified = new PanelModel({ libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
const panel = new PanelModel({ libraryPanel: { uid: '456', name: 'Name', meta, version: 1 } });
expect(skipPanelUpdate(modified, panel)).toEqual(true);
});
@@ -252,9 +254,9 @@ describe('panelEditor actions', () => {
describe('when called with a panel that is the same as the modified panel', () => {
it('then it should return true', () => {
const meta: any = {};
const modified: any = { id: 14, libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const panel: any = { id: 14, libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const meta = {} as LibraryElementDTOMeta;
const modified = new PanelModel({ id: 14, libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
const panel = new PanelModel({ id: 14, libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
expect(skipPanelUpdate(modified, panel)).toEqual(true);
});
@@ -262,9 +264,12 @@ describe('panelEditor actions', () => {
describe('when called with a panel that is repeated', () => {
it('then it should return true', () => {
const meta: any = {};
const modified: any = { libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const panel: any = { repeatPanelId: 14, libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const meta = {} as LibraryElementDTOMeta;
const modified = new PanelModel({ libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
const panel = new PanelModel({
repeatPanelId: 14,
libraryPanel: { uid: '123', name: 'Name', meta, version: 1 },
});
expect(skipPanelUpdate(modified, panel)).toEqual(true);
});
@@ -272,9 +277,9 @@ describe('panelEditor actions', () => {
describe('when called with a panel that is a duplicate of the modified panel', () => {
it('then it should return false', () => {
const meta: any = {};
const modified: any = { libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const panel: any = { libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } };
const meta = {} as LibraryElementDTOMeta;
const modified = new PanelModel({ libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
const panel = new PanelModel({ libraryPanel: { uid: '123', name: 'Name', meta, version: 1 } });
expect(skipPanelUpdate(modified, panel)).toEqual(false);
});

View File

@@ -12,8 +12,8 @@ import { SaveDashboardForm } from './SaveDashboardForm';
const prepareDashboardMock = (
timeChanged: boolean,
variableValuesChanged: boolean,
resetTimeSpy: any,
resetVarsSpy: any
resetTimeSpy: jest.Mock,
resetVarsSpy: jest.Mock
) => {
const json = {
title: 'name',
@@ -29,12 +29,12 @@ const prepareDashboardMock = (
meta: {},
...json,
getSaveModelClone: () => json,
};
} as unknown as DashboardModel;
};
const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => {
const renderAndSubmitForm = async (dashboard: DashboardModel, submitSpy: jest.Mock) => {
render(
<SaveDashboardForm
dashboard={dashboard as DashboardModel}
dashboard={dashboard}
onCancel={() => {}}
onSuccess={() => {}}
onSubmit={async (jsonModel) => {
@@ -62,14 +62,14 @@ describe('SaveDashboardAsForm', () => {
it('renders switches when variables or timerange', () => {
render(
<SaveDashboardForm
dashboard={prepareDashboardMock(true, true, jest.fn(), jest.fn()) as any}
dashboard={prepareDashboardMock(true, true, jest.fn(), jest.fn())}
onCancel={() => {}}
onSuccess={() => {}}
onSubmit={async () => {
return {};
}}
saveModel={{
clone: prepareDashboardMock(true, true, jest.fn(), jest.fn()) as any,
clone: prepareDashboardMock(true, true, jest.fn(), jest.fn()),
diff: {},
diffCount: 0,
hasChanges: true,
@@ -99,7 +99,7 @@ describe('SaveDashboardAsForm', () => {
const resetVarsSpy = jest.fn();
const submitSpy = jest.fn();
await renderAndSubmitForm(prepareDashboardMock(false, false, resetTimeSpy, resetVarsSpy) as any, submitSpy);
await renderAndSubmitForm(prepareDashboardMock(false, false, resetTimeSpy, resetVarsSpy), submitSpy);
expect(resetTimeSpy).not.toBeCalled();
expect(resetVarsSpy).not.toBeCalled();
@@ -112,7 +112,7 @@ describe('SaveDashboardAsForm', () => {
const resetTimeSpy = jest.fn();
const resetVarsSpy = jest.fn();
const submitSpy = jest.fn();
await renderAndSubmitForm(prepareDashboardMock(true, true, resetTimeSpy, resetVarsSpy) as any, submitSpy);
await renderAndSubmitForm(prepareDashboardMock(true, true, resetTimeSpy, resetVarsSpy), submitSpy);
expect(resetTimeSpy).toBeCalledTimes(0);
expect(resetVarsSpy).toBeCalledTimes(0);

View File

@@ -24,7 +24,7 @@ import { PublicDashboard } from './SharePublicDashboardUtils';
const server = setupServer();
jest.mock('@grafana/runtime', () => ({
...(jest.requireActual('@grafana/runtime') as unknown as object),
...jest.requireActual('@grafana/runtime'),
getBackendSrv: () => backendSrv,
}));

View File

@@ -1,3 +1,6 @@
import { backendSrv } from 'app/core/services/__mocks__/backend_srv';
import { LinkSrv } from 'app/features/panel/panellinks/link_srv';
import { DashboardSearchItem, DashboardSearchItemType } from '../../../search/types';
import { DashboardLink } from '../../state/DashboardModel';
@@ -18,9 +21,7 @@ describe('searchForTags', () => {
type: 'dashboards',
url: '/d/6ieouugGk/DashLinks',
};
const backendSrv: any = {
search: jest.fn((args) => []),
};
jest.spyOn(backendSrv, 'search').mockResolvedValue([]);
return { link, backendSrv };
};
@@ -64,9 +65,9 @@ describe('resolveLinks', () => {
type: DashboardSearchItemType.DashDB,
},
];
const linkSrv: any = {
const linkSrv = {
getLinkUrl: jest.fn((args) => args.url),
};
} as unknown as LinkSrv;
const sanitize = jest.fn((args) => args);
const sanitizeUrl = jest.fn((args) => args);