Chore: some test type fixes (#82889)

* some test type fixes

* ignore table-old since it's an angular panel that will be removed
pull/81206/head
Ashley Harrison 1 year ago committed by GitHub
parent 82e3e2e558
commit ffb9a4de4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 163
      .betterer.results
  2. 3
      .betterer.ts
  3. 5
      public/app/core/specs/time_series.test.ts
  4. 3
      public/app/features/alerting/unified/AlertsFolderView.test.tsx
  5. 2
      public/app/features/dashboard-scene/panel-edit/VizPanelManager.test.tsx
  6. 2
      public/app/features/dashboard-scene/scene/DashboardScene.test.tsx
  7. 2
      public/app/features/dashboard-scene/scene/setDashboardPanelContext.test.ts
  8. 5
      public/app/features/dashboard-scene/serialization/angularMigration.test.ts
  9. 45
      public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts
  10. 24
      public/app/features/dashboard/state/DashboardMigrator.test.ts
  11. 28
      public/app/features/dashboard/state/DashboardModel.repeat.test.ts
  12. 4
      public/app/features/dashboard/state/initDashboard.test.ts
  13. 5
      public/app/features/plugins/tests/datasource_srv.test.ts
  14. 2
      public/app/features/query/state/updateQueries.test.ts
  15. 20
      public/app/features/transformers/prepareTimeSeries/prepareTimeSeries.test.ts
  16. 2
      public/app/features/variables/query/QueryVariableEditor.test.tsx
  17. 54
      public/app/features/variables/query/queryRunners.test.ts

@ -1334,9 +1334,6 @@ exports[`better eslint`] = {
"public/app/core/specs/backend_srv.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/specs/time_series.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/time_series2.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -1559,9 +1556,6 @@ exports[`better eslint`] = {
"public/app/features/alerting/unified/AlertWarning.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]
],
"public/app/features/alerting/unified/AlertsFolderView.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/alerting/unified/AlertsFolderView.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"],
@ -2570,9 +2564,6 @@ exports[`better eslint`] = {
"public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataPane.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/dashboard-scene/panel-edit/VizPanelManager.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard-scene/saving/SaveDashboardForm.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"],
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"]
@ -2584,21 +2575,11 @@ exports[`better eslint`] = {
"public/app/features/dashboard-scene/saving/shared.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
],
"public/app/features/dashboard-scene/scene/DashboardScene.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"]
],
"public/app/features/dashboard-scene/scene/setDashboardPanelContext.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard-scene/serialization/angularMigration.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -2664,22 +2645,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
[0, 0, 0, "Unexpected any. Specify a different type.", "19"],
[0, 0, 0, "Unexpected any. Specify a different type.", "20"]
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
],
"public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -2967,14 +2933,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"]
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
],
"public/app/features/dashboard/state/DashboardMigrator.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -3013,10 +2972,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
"public/app/features/dashboard/state/DashboardModel.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -3085,8 +3041,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard/state/initDashboard.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard/utils/getPanelMenu.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -4076,8 +4031,7 @@ exports[`better eslint`] = {
"public/app/features/plugins/tests/datasource_srv.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"public/app/features/plugins/utils.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@ -4158,8 +4112,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
[0, 0, 0, "Unexpected any. Specify a different type.", "10"]
],
"public/app/features/search/page/components/ActionRow.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
@ -4405,8 +4358,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Styles should be written using objects.", "0"]
],
"public/app/features/transformers/prepareTimeSeries/prepareTimeSeries.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/transformers/prepareTimeSeries/prepareTimeSeries.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -4527,9 +4479,6 @@ exports[`better eslint`] = {
"public/app/features/variables/pickers/shared/VariableOptions.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
],
"public/app/features/variables/query/QueryVariableEditor.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/variables/query/QueryVariableEditor.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
@ -4553,13 +4502,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/variables/query/queryRunners.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/variables/query/queryRunners.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -6116,96 +6059,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/table-old/column_options.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
[0, 0, 0, "Unexpected any. Specify a different type.", "19"],
[0, 0, 0, "Unexpected any. Specify a different type.", "20"],
[0, 0, 0, "Unexpected any. Specify a different type.", "21"]
],
"public/app/plugins/panel/table-old/editor.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/app/plugins/panel/table-old/module.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
],
"public/app/plugins/panel/table-old/renderer.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
],
"public/app/plugins/panel/table-old/transformers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/app/plugins/panel/table-old/types.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
],
"public/app/plugins/panel/table/TablePanel.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"]

@ -5,11 +5,12 @@ import path from 'path';
import { glob } from 'glob';
// Why are we ignoring these?
// They're all deprecated/being removed soon so doesn't make sense to fix types
// They're all deprecated/being removed so doesn't make sense to fix types
const eslintPathsToIgnore = [
'packages/grafana-e2e', // deprecated.
'public/app/angular', // will be removed in Grafana 11
'public/app/plugins/panel/graph', // will be removed alongside angular
'public/app/plugins/panel/table-old', // will be removed alongside angular
];
// Avoid using functions that report the position of the issues, as this causes a lot of merge conflicts

@ -406,7 +406,10 @@ describe('TimeSeries', () => {
describe('legend decimals', () => {
let series: TimeSeries;
let panel: any;
let panel: {
decimals: number | null;
yaxes: Array<{ decimals: number | null }>;
};
const height = 200;
beforeEach(() => {
testData = {

@ -8,6 +8,7 @@ import { FolderState } from 'app/types';
import { CombinedRuleNamespace } from 'app/types/unified-alerting';
import { AlertsFolderView } from './AlertsFolderView';
import { useCombinedRuleNamespaces } from './hooks/useCombinedRuleNamespaces';
import { mockCombinedRule } from './mocks';
import { GRAFANA_RULES_SOURCE_NAME } from './utils/datasource';
@ -21,7 +22,7 @@ const ui = {
},
};
const combinedNamespaceMock = jest.fn<CombinedRuleNamespace[], any>();
const combinedNamespaceMock = jest.fn(useCombinedRuleNamespaces);
jest.mock('./hooks/useCombinedRuleNamespaces', () => ({
useCombinedRuleNamespaces: () => combinedNamespaceMock(),
}));

@ -621,7 +621,7 @@ describe('VizPanelManager', () => {
});
const setupTest = (panelId: string) => {
const scene = transformSaveModelToScene({ dashboard: testDashboard as any, meta: {} });
const scene = transformSaveModelToScene({ dashboard: testDashboard, meta: {} });
const panel = findVizPanelByKey(scene, panelId)!;
const vizPanelManager = new VizPanelManager(panel.clone());

@ -71,7 +71,7 @@ describe('DashboardScene', () => {
${'links'} | ${[]}
`(
'A change to $prop should set isDirty true',
({ prop, value }: { prop: keyof DashboardSceneState; value: any }) => {
({ prop, value }: { prop: keyof DashboardSceneState; value: unknown }) => {
const prevState = scene.state[prop];
scene.setState({ [prop]: value });

@ -15,7 +15,7 @@ setBackendSrv({
post: postFn,
put: putFn,
delete: deleteFn,
} as any as BackendSrv);
} as unknown as BackendSrv);
describe('setDashboardPanelContext', () => {
describe('canAddAnnotations', () => {

@ -1,3 +1,4 @@
import { PanelTypeChangedHandler } from '@grafana/data';
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
import { PanelModel } from 'app/features/dashboard/state';
@ -6,12 +7,12 @@ import { getAngularPanelMigrationHandler } from './angularMigration';
describe('getAngularPanelMigrationHandler', () => {
describe('Given an old angular panel', () => {
it('Should call migration handler', () => {
const onPanelTypeChanged = (panel: PanelModel, prevPluginId: string, prevOptions: Record<string, any>) => {
const onPanelTypeChanged: PanelTypeChangedHandler = (panel, prevPluginId, prevOptions) => {
panel.fieldConfig = { defaults: { unit: 'bytes' }, overrides: [] };
return { name: prevOptions.angular.oldOptionProp };
};
const reactPlugin = getPanelPlugin({ id: 'timeseries' }).setPanelChangeHandler(onPanelTypeChanged as any);
const reactPlugin = getPanelPlugin({ id: 'timeseries' }).setPanelChangeHandler(onPanelTypeChanged);
const oldModel = new PanelModel({
autoMigrateFrom: 'graph',

@ -25,9 +25,8 @@ jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
getDataSourceSrv: () => {
return {
get: (v: any) => {
get: (v: string | DataSourceRef) => {
const s = getStubInstanceSettings(v);
// console.log('GET', v, s);
return Promise.resolve(s);
},
getInstanceSettings: getStubInstanceSettings,
@ -169,7 +168,7 @@ it('replaces datasource ref in library panel', async () => {
});
it('If a panel queries has no datasource prop ignore it', async () => {
const dashboard: any = {
const dashboard = {
panels: [
{
id: 1,
@ -181,7 +180,7 @@ it('If a panel queries has no datasource prop ignore it', async () => {
targets: [{ refId: 'A', a: 'A' }],
},
],
};
} as unknown as Dashboard;
const dashboardModel = new DashboardModel(dashboard, undefined, {
getVariablesFromState: () => [],
});
@ -348,9 +347,9 @@ describe('given dashboard with repeated panels', () => {
});
it('should not include default datasource in __inputs unnecessarily', async () => {
const testJson: any = {
const testJson = {
panels: [{ id: 1, datasource: { uid: 'other', type: 'other' }, type: 'graph' }],
};
} as unknown as Dashboard;
const testDash = new DashboardModel(testJson);
const exporter = new DashboardExporter();
const exportedJson: any = await exporter.makeExportable(testDash);
@ -380,7 +379,7 @@ describe('given dashboard with repeated panels', () => {
});
it('should add datasource to required', () => {
const require: any = find(exported.__requires, { name: 'TestDB' });
const require = find(exported.__requires, { name: 'TestDB' });
expect(require.name).toBe('TestDB');
expect(require.id).toBe('testdb');
expect(require.type).toBe('datasource');
@ -388,52 +387,52 @@ describe('given dashboard with repeated panels', () => {
});
it('should not add built in datasources to required', () => {
const require: any = find(exported.__requires, { name: 'Mixed' });
const require = find(exported.__requires, { name: 'Mixed' });
expect(require).toBe(undefined);
});
it('should add datasources used in mixed mode', () => {
const require: any = find(exported.__requires, { name: 'OtherDB' });
const require = find(exported.__requires, { name: 'OtherDB' });
expect(require).not.toBe(undefined);
});
it('should add graph panel to required', () => {
const require: any = find(exported.__requires, { name: 'Graph' });
const require = find(exported.__requires, { name: 'Graph' });
expect(require.name).toBe('Graph');
expect(require.id).toBe('graph');
expect(require.version).toBe('1.1.0');
});
it('should add table panel to required', () => {
const require: any = find(exported.__requires, { name: 'Table' });
const require = find(exported.__requires, { name: 'Table' });
expect(require.name).toBe('Table');
expect(require.id).toBe('table');
expect(require.version).toBe('1.1.1');
});
it('should add heatmap panel to required', () => {
const require: any = find(exported.__requires, { name: 'Heatmap' });
const require = find(exported.__requires, { name: 'Heatmap' });
expect(require.name).toBe('Heatmap');
expect(require.id).toBe('heatmap');
expect(require.version).toBe('1.1.2');
});
it('should add grafana version', () => {
const require: any = find(exported.__requires, { name: 'Grafana' });
const require = find(exported.__requires, { name: 'Grafana' });
expect(require.type).toBe('grafana');
expect(require.id).toBe('grafana');
expect(require.version).toBe('3.0.2');
});
it('should add constant template variables as inputs', () => {
const input: any = find(exported.__inputs, { name: 'VAR_PREFIX' });
const input = find(exported.__inputs, { name: 'VAR_PREFIX' });
expect(input.type).toBe('constant');
expect(input.label).toBe('prefix');
expect(input.value).toBe('collectd');
});
it('should templatize constant variables', () => {
const variable: any = find(exported.templating.list, { name: 'prefix' });
const variable = find(exported.templating.list, { name: 'prefix' });
expect(variable.query).toBe('${VAR_PREFIX}');
expect(variable.current.text).toBe('${VAR_PREFIX}');
expect(variable.current.value).toBe('${VAR_PREFIX}');
@ -442,7 +441,7 @@ describe('given dashboard with repeated panels', () => {
});
it('should add datasources only use via datasource variable to requires', () => {
const require: any = find(exported.__requires, { name: 'OtherDB_2' });
const require = find(exported.__requires, { name: 'OtherDB_2' });
expect(require.id).toBe('other2');
});
@ -472,25 +471,25 @@ describe('given dashboard with repeated panels', () => {
function getStubInstanceSettings(v: string | DataSourceRef): DataSourceInstanceSettings {
let key = (v as DataSourceRef)?.type ?? v;
return (stubs[(key as any) ?? 'gfdb'] ?? stubs['gfdb']) as any;
return stubs[(key as string) ?? 'gfdb'] ?? stubs['gfdb'];
}
// Stub responses
const stubs: { [key: string]: {} } = {};
const stubs: { [key: string]: DataSourceInstanceSettings } = {};
stubs['gfdb'] = {
name: 'gfdb',
meta: { id: 'testdb', info: { version: '1.2.1' }, name: 'TestDB' },
};
} as DataSourceInstanceSettings;
stubs['other'] = {
name: 'other',
meta: { id: 'other', info: { version: '1.2.1' }, name: 'OtherDB' },
};
} as DataSourceInstanceSettings;
stubs['other2'] = {
name: 'other2',
meta: { id: 'other2', info: { version: '1.2.1' }, name: 'OtherDB_2' },
};
} as DataSourceInstanceSettings;
stubs['mixed'] = {
name: 'mixed',
@ -500,7 +499,7 @@ stubs['mixed'] = {
name: 'Mixed',
builtIn: true,
},
};
} as DataSourceInstanceSettings;
stubs['grafana'] = {
name: '-- Grafana --',
@ -510,4 +509,4 @@ stubs['grafana'] = {
name: 'grafana',
builtIn: true,
},
};
} as DataSourceInstanceSettings;

@ -46,7 +46,7 @@ setDataSourceSrv(new MockDataSourceSrv(dataSources));
describe('DashboardModel', () => {
describe('when creating dashboard with old schema', () => {
let model: any;
let model: DashboardModel;
let graph: any;
let singlestat: any;
let table: any;
@ -517,7 +517,7 @@ describe('DashboardModel', () => {
});
describe('when migrating panel links', () => {
let model: any;
let model: DashboardModel;
beforeEach(() => {
model = new DashboardModel({
@ -564,24 +564,26 @@ describe('DashboardModel', () => {
});
it('should add keepTime as variable', () => {
expect(model.panels[0].links[0].url).toBe(`http://mylink.com?$${DataLinkBuiltInVars.keepTime}`);
expect(model.panels[0].links?.[0].url).toBe(`http://mylink.com?$${DataLinkBuiltInVars.keepTime}`);
});
it('should add params to url', () => {
expect(model.panels[0].links[1].url).toBe('http://mylink.com?existingParam&customParam');
expect(model.panels[0].links?.[1].url).toBe('http://mylink.com?existingParam&customParam');
});
it('should add includeVars to url', () => {
expect(model.panels[0].links[2].url).toBe(`http://mylink.com?existingParam&$${DataLinkBuiltInVars.includeVars}`);
expect(model.panels[0].links?.[2].url).toBe(
`http://mylink.com?existingParam&$${DataLinkBuiltInVars.includeVars}`
);
});
it('should slugify dashboard name', () => {
expect(model.panels[0].links[3].url).toBe(`dashboard/db/my-other-dashboard`);
expect(model.panels[0].links?.[3].url).toBe(`dashboard/db/my-other-dashboard`);
});
});
describe('when migrating variables', () => {
let model: any;
let model: DashboardModel;
beforeEach(() => {
model = new DashboardModel({
panels: [
@ -648,7 +650,7 @@ describe('DashboardModel', () => {
});
describe('when migrating labels from DataFrame to Field', () => {
let model: any;
let model: DashboardModel;
beforeEach(() => {
model = new DashboardModel({
panels: [
@ -892,7 +894,7 @@ describe('DashboardModel', () => {
});
it('should migrate panels with new Text Panel id', () => {
const reactPanel: any = model.panels[1];
const reactPanel = model.panels[1];
expect(reactPanel.id).toEqual(3);
expect(reactPanel.type).toEqual('text');
expect(reactPanel.title).toEqual('React Text Panel from scratch');
@ -903,7 +905,7 @@ describe('DashboardModel', () => {
});
it('should clean up old angular options for panels with new Text Panel id', () => {
const reactPanel: any = model.panels[2];
const reactPanel = model.panels[2];
expect(reactPanel.id).toEqual(4);
expect(reactPanel.type).toEqual('text');
expect(reactPanel.title).toEqual('React Text Panel from Angular Panel');
@ -1564,7 +1566,7 @@ describe('DashboardModel', () => {
});
describe('migrating legacy CloudWatch queries', () => {
let model: any;
let model: DashboardModel;
let panelTargets: any;
beforeEach(() => {

@ -194,7 +194,7 @@ describe('given dashboard with panel repeat in horizontal direction', () => {
});
describe('given dashboard with panel repeat in vertical direction', () => {
let dashboard: any;
let dashboard: DashboardModel;
beforeEach(() => {
const dashboardJSON = {
@ -238,7 +238,7 @@ describe('given dashboard with panel repeat in vertical direction', () => {
});
describe('given dashboard with row repeat and panel repeat in horizontal direction', () => {
let dashboard: any, dashboardJSON: any;
let dashboard: DashboardModel, dashboardJSON: any;
beforeEach(() => {
dashboardJSON = {
@ -280,7 +280,7 @@ describe('given dashboard with row repeat and panel repeat in horizontal directi
},
};
dashboard = getDashboardModel(dashboardJSON);
dashboard.processRepeats(false);
dashboard.processRepeats();
});
it('should panels in self row', () => {
@ -325,7 +325,7 @@ describe('given dashboard with row repeat and panel repeat in horizontal directi
});
describe('given dashboard with row repeat', () => {
let dashboard: any, dashboardJSON: any;
let dashboard: DashboardModel, dashboardJSON: any;
beforeEach(() => {
dashboardJSON = {
@ -382,7 +382,7 @@ describe('given dashboard with row repeat', () => {
const scopedVars = compact(
map(dashboard.panels, (panel) => {
return panel.scopedVars ? panel.scopedVars.apps.value : null;
return panel.scopedVars ? panel.scopedVars.apps?.value : null;
})
);
@ -474,14 +474,14 @@ describe('given dashboard with row repeat', () => {
'graph',
]);
expect(dashboard.panels[0].scopedVars['apps'].value).toBe('se1');
expect(dashboard.panels[1].scopedVars['apps'].value).toBe('se1');
expect(dashboard.panels[3].scopedVars['apps'].value).toBe('se2');
expect(dashboard.panels[4].scopedVars['apps'].value).toBe('se2');
expect(dashboard.panels[8].scopedVars['hosts'].value).toBe('backend01');
expect(dashboard.panels[9].scopedVars['hosts'].value).toBe('backend01');
expect(dashboard.panels[11].scopedVars['hosts'].value).toBe('backend02');
expect(dashboard.panels[12].scopedVars['hosts'].value).toBe('backend02');
expect(dashboard.panels[0].scopedVars?.['apps']?.value).toBe('se1');
expect(dashboard.panels[1].scopedVars?.['apps']?.value).toBe('se1');
expect(dashboard.panels[3].scopedVars?.['apps']?.value).toBe('se2');
expect(dashboard.panels[4].scopedVars?.['apps']?.value).toBe('se2');
expect(dashboard.panels[8].scopedVars?.['hosts']?.value).toBe('backend01');
expect(dashboard.panels[9].scopedVars?.['hosts']?.value).toBe('backend01');
expect(dashboard.panels[11].scopedVars?.['hosts']?.value).toBe('backend02');
expect(dashboard.panels[12].scopedVars?.['hosts']?.value).toBe('backend02');
});
it('should assign unique ids for repeated panels', () => {
@ -505,7 +505,7 @@ describe('given dashboard with row repeat', () => {
const panelIds = flattenDeep(
map(dashboard.panels, (panel) => {
let ids = [];
let ids: number[] = [];
if (panel.panels && panel.panels.length) {
ids = map(panel.panels, 'id');
}

@ -1,4 +1,4 @@
import configureMockStore from 'redux-mock-store';
import configureMockStore, { MockStore } from 'redux-mock-store';
import thunk from 'redux-thunk';
import { Subject } from 'rxjs';
@ -71,7 +71,7 @@ interface ScenarioContext {
loaderSrv: DashboardLoaderSrv;
backendSrv: jest.Mocked<BackendSrv>;
setup: (fn: () => void) => void;
actions: any[];
actions: ReturnType<MockStore['getActions']>;
storeState: any;
}

@ -5,11 +5,12 @@ import {
DataSourcePluginMeta,
ScopedVars,
} from '@grafana/data';
import { TemplateSrv } from '@grafana/runtime';
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { DatasourceSrv, getNameOrUid } from 'app/features/plugins/datasource_srv';
// Datasource variable $datasource with current value 'BBB'
const templateSrv: any = {
const templateSrv = {
getVariables: () => [
{
type: 'datasource',
@ -43,7 +44,7 @@ const templateSrv: any = {
result = result.replace('${datasourceDefault}', 'default');
return result;
},
};
} as TemplateSrv;
class TestDataSource {
constructor(public instanceSettings: DataSourceInstanceSettings) {}

@ -577,7 +577,7 @@ describe('updateQueries with import', () => {
importQueries: (queries, origin) => {
return Promise.resolve([] as DataQuery[]);
},
} as DataSourceApi<any>;
} as DataSourceApi;
const oldUidDS = {
uid: 'old-uid',

@ -39,7 +39,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3, 4, 5, 6] },
{ name: 'count', type: FieldType.number, values: [10, 20, 30, 40, 50, 60] },
],
] as DataFrame['fields'],
meta: {
type: DataFrameType.TimeSeriesMulti,
},
@ -51,7 +51,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3, 4, 5, 6] },
{ name: 'more', type: FieldType.number, values: [2, 3, 4, 5, 6, 7] },
],
] as DataFrame['fields'],
meta: {
type: DataFrameType.TimeSeriesMulti,
},
@ -181,7 +181,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [0, 1, 2, 3, 4, 5] },
{ name: 'another', type: FieldType.number, values: [2, 3, 4, 5, 6, 7] },
],
] as DataFrame['fields'],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -193,7 +193,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [0, 1, 2, 3, 4, 5] },
{ name: 'count', type: FieldType.number, values: [10, 20, 30, 40, 50, 60] },
],
] as DataFrame['fields'],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -205,7 +205,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [4, 5, 6, 7, 8, 9] },
{ name: 'value', type: FieldType.number, values: [2, 3, 4, 5, 6, 7] },
],
] as DataFrame['fields'],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -304,7 +304,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'a' }, type: FieldType.number, values: [10, 30, 50] },
],
] as DataFrame['fields'],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -316,7 +316,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'b' }, type: FieldType.number, values: [20, 40, 60] },
],
] as DataFrame['fields'],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -351,7 +351,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'a' }, type: FieldType.number, values: [10, 30, 50] },
],
] as DataFrame['fields'],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -363,7 +363,7 @@ describe('Prepare time series transformer', () => {
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'b' }, type: FieldType.number, values: [20, 40, 60] },
],
] as DataFrame['fields'],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
@ -415,7 +415,7 @@ describe('Prepare time series transformer', () => {
});
});
function toEquableDataFrame(source: any): DataFrame {
function toEquableDataFrame(source: DataFrame): DataFrame {
return toDataFrame({
meta: undefined,
...source,

@ -32,7 +32,7 @@ const setupTestContext = (options: Partial<Props>) => {
onPropChange: jest.fn(),
};
const props: Props & Record<string, any> = { ...defaults, ...options };
const props: Props & Record<string, unknown> = { ...defaults, ...options };
const { rerender } = render(<QueryVariableEditorUnConnected {...props} />);
return { rerender, props };

@ -1,6 +1,12 @@
import { of } from 'rxjs';
import { DataQueryRequest, getDefaultTimeRange, QueryVariableModel, VariableSupportType } from '@grafana/data';
import {
DataQueryRequest,
DataSourceApi,
getDefaultTimeRange,
QueryVariableModel,
VariableSupportType,
} from '@grafana/data';
import { VariableRefresh } from '../types';
@ -8,13 +14,15 @@ import { QueryRunners, RunnerArgs, variableDummyRefId } from './queryRunners';
describe('QueryRunners', () => {
describe('when using a legacy data source', () => {
const getLegacyTestContext = (variable?: any) => {
const getLegacyTestContext = (variable?: QueryVariableModel) => {
const defaultTimeRange = getDefaultTimeRange();
variable = variable ?? { query: 'A query' };
variable = variable ?? ({ query: 'A query' } as QueryVariableModel);
const timeSrv = {
timeRange: jest.fn().mockReturnValue(defaultTimeRange),
};
const datasource: any = { metricFindQuery: jest.fn().mockResolvedValue([{ text: 'A', value: 'A' }]) };
const datasource = {
metricFindQuery: jest.fn().mockResolvedValue([{ text: 'A', value: 'A' }]),
} as unknown as DataSourceApi;
const runner = new QueryRunners().getRunnerForDatasource(datasource);
const runRequest = jest.fn().mockReturnValue(of({}));
const runnerArgs = {
@ -48,7 +56,7 @@ describe('QueryRunners', () => {
const { datasource, runner, runnerArgs, request, timeSrv, defaultTimeRange } = getLegacyTestContext({
query: 'A query',
refresh: VariableRefresh.onTimeRangeChanged,
});
} as QueryVariableModel);
const observable = runner.runRequest(runnerArgs, request);
it('then it should return correct observable', async () => {
@ -83,7 +91,7 @@ describe('QueryRunners', () => {
const { datasource, runner, runnerArgs, request, timeSrv, defaultTimeRange } = getLegacyTestContext({
query: 'A query',
refresh: VariableRefresh.onDashboardLoad,
});
} as QueryVariableModel);
const observable = runner.runRequest(runnerArgs, request);
it('then it should return correct observable', async () => {
@ -118,7 +126,7 @@ describe('QueryRunners', () => {
const { datasource, runner, runnerArgs, request, timeSrv } = getLegacyTestContext({
query: 'A query',
refresh: VariableRefresh.never,
});
} as QueryVariableModel);
const observable = runner.runRequest(runnerArgs, request);
it('then it should return correct observable', async () => {
@ -151,15 +159,17 @@ describe('QueryRunners', () => {
});
describe('when using a data source with standard variable support', () => {
const getStandardTestContext = (datasource?: any) => {
const getStandardTestContext = (datasource?: DataSourceApi) => {
const variable = { query: { refId: 'A', query: 'A query' } } as QueryVariableModel;
const timeSrv = {};
datasource = datasource ?? {
variables: {
getType: () => VariableSupportType.Standard,
toDataQuery: (query: any) => ({ ...query, extra: 'extra' }),
},
};
datasource =
datasource ??
({
variables: {
getType: () => VariableSupportType.Standard,
toDataQuery: (query: any) => ({ ...query, extra: 'extra' }),
},
} as DataSourceApi);
const runner = new QueryRunners().getRunnerForDatasource(datasource);
const runRequest = jest.fn().mockReturnValue(of({}));
const runnerArgs = {
@ -196,7 +206,7 @@ describe('QueryRunners', () => {
toDataQuery: () => undefined,
query: () => undefined,
},
});
} as unknown as DataSourceApi);
const observable = runner.runRequest(runnerArgs, request);
it('then it should return correct observable', async () => {
@ -215,7 +225,7 @@ describe('QueryRunners', () => {
describe('and calling runRequest with a datasource that has no custom query', () => {
const { runner, request, runnerArgs, runRequest, datasource } = getStandardTestContext({
variables: { getType: () => VariableSupportType.Standard, toDataQuery: () => undefined },
});
} as unknown as DataSourceApi);
const observable = runner.runRequest(runnerArgs, request);
it('then it should return correct observable', async () => {
@ -236,9 +246,9 @@ describe('QueryRunners', () => {
const getCustomTestContext = () => {
const variable = { query: { refId: 'A', query: 'A query' } } as QueryVariableModel;
const timeSrv = {};
const datasource: any = {
const datasource = {
variables: { getType: () => VariableSupportType.Custom, query: () => undefined, editor: {} },
};
} as unknown as DataSourceApi;
const runner = new QueryRunners().getRunnerForDatasource(datasource);
const runRequest = jest.fn().mockReturnValue(of({}));
const runnerArgs = {
@ -290,9 +300,9 @@ describe('QueryRunners', () => {
const getDatasourceTestContext = () => {
const variable = { query: { refId: 'A', query: 'A query' } } as QueryVariableModel;
const timeSrv = {};
const datasource: any = {
const datasource = {
variables: { getType: () => VariableSupportType.Datasource },
};
} as unknown as DataSourceApi;
const runner = new QueryRunners().getRunnerForDatasource(datasource);
const runRequest = jest.fn().mockReturnValue(of({}));
const runnerArgs = {
@ -352,9 +362,9 @@ describe('QueryRunners', () => {
describe('when using a data source with unknown variable support', () => {
describe('and calling getRunnerForDatasource', () => {
it('then it should throw', () => {
const datasource: any = {
const datasource = {
variables: {},
};
} as unknown as DataSourceApi;
expect(() => new QueryRunners().getRunnerForDatasource(datasource)).toThrow();
});

Loading…
Cancel
Save