Commit b51e28bc by Hugo Häggmark Committed by GitHub

Chore: reduces strict null errors to 824 (#22744)

* Chore: reduces strict null errors with 100+

* Chore: lowers the build error number
parent 4fecf5a7
import { import {
DataFrame, DataFrame,
FieldType, FieldType,
LogsMetaKind,
LogsDedupStrategy,
LogLevel, LogLevel,
LogRowModel,
LogsDedupStrategy,
LogsMetaKind,
MutableDataFrame, MutableDataFrame,
toDataFrame, toDataFrame,
LogRowModel,
} from '@grafana/data'; } from '@grafana/data';
import { dedupLogRows, dataFrameToLogsModel } from './logs_model'; import { dataFrameToLogsModel, dedupLogRows } from './logs_model';
describe('dedupLogRows()', () => { describe('dedupLogRows()', () => {
test('should return rows as is when dedup is set to none', () => { test('should return rows as is when dedup is set to none', () => {
...@@ -240,12 +240,12 @@ describe('dataFrameToLogsModel', () => { ...@@ -240,12 +240,12 @@ describe('dataFrameToLogsModel', () => {
expect(logsModel.series).toHaveLength(2); expect(logsModel.series).toHaveLength(2);
expect(logsModel.meta).toHaveLength(2); expect(logsModel.meta).toHaveLength(2);
expect(logsModel.meta[0]).toMatchObject({ expect(logsModel.meta![0]).toMatchObject({
label: 'Common labels', label: 'Common labels',
value: series[0].fields[1].labels, value: series[0].fields[1].labels,
kind: LogsMetaKind.LabelsMap, kind: LogsMetaKind.LabelsMap,
}); });
expect(logsModel.meta[1]).toMatchObject({ expect(logsModel.meta![1]).toMatchObject({
label: 'Limit', label: 'Limit',
value: `1000 (2 returned)`, value: `1000 (2 returned)`,
kind: LogsMetaKind.String, kind: LogsMetaKind.String,
...@@ -364,7 +364,7 @@ describe('dataFrameToLogsModel', () => { ...@@ -364,7 +364,7 @@ describe('dataFrameToLogsModel', () => {
expect(logsModel.series).toHaveLength(2); expect(logsModel.series).toHaveLength(2);
expect(logsModel.meta).toHaveLength(1); expect(logsModel.meta).toHaveLength(1);
expect(logsModel.meta[0]).toMatchObject({ expect(logsModel.meta![0]).toMatchObject({
label: 'Common labels', label: 'Common labels',
value: { value: {
foo: 'bar', foo: 'bar',
......
...@@ -12,7 +12,7 @@ describe('flatten', () => { ...@@ -12,7 +12,7 @@ describe('flatten', () => {
}, },
}, },
}, },
null (null as unknown) as { delimiter?: any; maxDepth?: any; safe?: any }
); );
expect(flattened['level1']).toBe('level1-value'); expect(flattened['level1']).toBe('level1-value');
......
import { getMessageFromError } from 'app/core/utils/errors'; import { getMessageFromError } from 'app/core/utils/errors';
describe('errors functions', () => { describe('errors functions', () => {
let message: string; let message: string | null;
describe('when getMessageFromError gets an error string', () => { describe('when getMessageFromError gets an error string', () => {
beforeEach(() => { beforeEach(() => {
......
import { import {
DEFAULT_RANGE, buildQueryTransaction,
serializeStateToUrlParam,
parseUrlState,
updateHistory,
clearHistory, clearHistory,
hasNonEmptyQuery, DEFAULT_RANGE,
getValueWithRefId,
getFirstQueryErrorWithoutRefId, getFirstQueryErrorWithoutRefId,
getRefIds, getRefIds,
getValueWithRefId,
hasNonEmptyQuery,
parseUrlState,
refreshIntervalToSortOrder, refreshIntervalToSortOrder,
SortOrder, serializeStateToUrlParam,
sortLogsResult, sortLogsResult,
buildQueryTransaction, SortOrder,
updateHistory,
} from './explore'; } from './explore';
import { ExploreUrlState } from 'app/types/explore'; import { ExploreUrlState } from 'app/types/explore';
import store from 'app/core/store'; import store from 'app/core/store';
import { import {
DataQueryError, DataQueryError,
LogsDedupStrategy,
LogsModel,
LogLevel,
dateTime, dateTime,
MutableDataFrame,
ExploreMode, ExploreMode,
LogLevel,
LogRowModel, LogRowModel,
LogsDedupStrategy,
LogsModel,
MutableDataFrame,
} from '@grafana/data'; } from '@grafana/data';
import { RefreshPicker } from '@grafana/ui'; import { RefreshPicker } from '@grafana/ui';
const DEFAULT_EXPLORE_STATE: ExploreUrlState = { const DEFAULT_EXPLORE_STATE: ExploreUrlState = {
datasource: null, datasource: '',
queries: [], queries: [],
range: DEFAULT_RANGE, range: DEFAULT_RANGE,
mode: ExploreMode.Metrics, mode: ExploreMode.Metrics,
...@@ -259,7 +259,7 @@ describe('hasRefId', () => { ...@@ -259,7 +259,7 @@ describe('hasRefId', () => {
describe('getFirstQueryErrorWithoutRefId', () => { describe('getFirstQueryErrorWithoutRefId', () => {
describe('when called with a null value', () => { describe('when called with a null value', () => {
it('then it should return undefined', () => { it('then it should return undefined', () => {
const errors: DataQueryError[] = null; const errors: DataQueryError[] | undefined = undefined;
const result = getFirstQueryErrorWithoutRefId(errors); const result = getFirstQueryErrorWithoutRefId(errors);
expect(result).toBeUndefined(); expect(result).toBeUndefined();
......
...@@ -43,6 +43,7 @@ const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => { ...@@ -43,6 +43,7 @@ const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => {
/> />
); );
// @ts-ignore strict null error below
await act(async () => { await act(async () => {
const button = container.find('button[aria-label="Save dashboard button"]'); const button = container.find('button[aria-label="Save dashboard button"]');
button.simulate('submit'); button.simulate('submit');
......
...@@ -39,6 +39,7 @@ const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => { ...@@ -39,6 +39,7 @@ const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => {
/> />
); );
// @ts-ignore strict null error below
await act(async () => { await act(async () => {
const button = container.find('button[aria-label="Dashboard settings Save Dashboard Modal Save button"]'); const button = container.find('button[aria-label="Dashboard settings Save Dashboard Modal Save button"]');
button.simulate('submit'); button.simulate('submit');
......
import { versions, restore } from './__mocks__/history'; import { restore, versions } from './__mocks__/history';
import { HistorySrv } from './HistorySrv'; import { HistorySrv } from './HistorySrv';
import { DashboardModel } from '../../state/DashboardModel'; import { DashboardModel } from '../../state/DashboardModel';
...@@ -49,7 +49,7 @@ describe('historySrv', () => { ...@@ -49,7 +49,7 @@ describe('historySrv', () => {
}); });
it('should return an empty array when not given a dashboard', () => { it('should return an empty array when not given a dashboard', () => {
return historySrv.getHistoryList(null, historyListOpts).then((versions: any) => { return historySrv.getHistoryList((null as unknown) as DashboardModel, historyListOpts).then((versions: any) => {
expect(versions).toEqual([]); expect(versions).toEqual([]);
}); });
}); });
......
import { LoadingState, toDataFrame, dateTime, PanelData, DataQueryRequest } from '@grafana/data'; import { DataQueryRequest, dateTime, LoadingState, PanelData, toDataFrame } from '@grafana/data';
import { filterPanelDataToQuery } from './QueryEditorRow'; import { filterPanelDataToQuery } from './QueryEditorRow';
function makePretendRequest(requestId: string, subRequests?: DataQueryRequest[]): DataQueryRequest { function makePretendRequest(requestId: string, subRequests?: DataQueryRequest[]): DataQueryRequest {
...@@ -32,15 +32,15 @@ describe('filterPanelDataToQuery', () => { ...@@ -32,15 +32,15 @@ describe('filterPanelDataToQuery', () => {
it('should not have an error unless the refId matches', () => { it('should not have an error unless the refId matches', () => {
const panelData = filterPanelDataToQuery(data, 'A'); const panelData = filterPanelDataToQuery(data, 'A');
expect(panelData.series.length).toBe(1); expect(panelData?.series.length).toBe(1);
expect(panelData.series[0].refId).toBe('A'); expect(panelData?.series[0].refId).toBe('A');
expect(panelData.error).toBeUndefined(); expect(panelData?.error).toBeUndefined();
}); });
it('should match the error to the query', () => { it('should match the error to the query', () => {
const panelData = filterPanelDataToQuery(data, 'B'); const panelData = filterPanelDataToQuery(data, 'B');
expect(panelData.series.length).toBe(3); expect(panelData?.series.length).toBe(3);
expect(panelData.series[0].refId).toBe('B'); expect(panelData?.series[0].refId).toBe('B');
expect(panelData.error!.refId).toBe('B'); expect(panelData?.error!.refId).toBe('B');
}); });
}); });
...@@ -652,14 +652,14 @@ describe('DashboardModel', () => { ...@@ -652,14 +652,14 @@ describe('DashboardModel', () => {
it('toggleLegendsForAll should toggle all legends on on first execution', () => { it('toggleLegendsForAll should toggle all legends on on first execution', () => {
model.toggleLegendsForAll(); model.toggleLegendsForAll();
const legendsOn = model.panels.filter(panel => panel.legend.show === true); const legendsOn = model.panels.filter(panel => panel.legend!.show === true);
expect(legendsOn.length).toBe(3); expect(legendsOn.length).toBe(3);
}); });
it('toggleLegendsForAll should toggle all legends off on second execution', () => { it('toggleLegendsForAll should toggle all legends off on second execution', () => {
model.toggleLegendsForAll(); model.toggleLegendsForAll();
model.toggleLegendsForAll(); model.toggleLegendsForAll();
const legendsOn = model.panels.filter(panel => panel.legend.show === true); const legendsOn = model.panels.filter(panel => panel.legend!.show === true);
expect(legendsOn.length).toBe(0); expect(legendsOn.length).toBe(0);
}); });
}); });
......
import { PanelModel } from './PanelModel'; import { PanelModel } from './PanelModel';
import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks'; import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks';
import { PanelProps } from '@grafana/data';
import { ComponentClass } from 'react';
class TablePanelCtrl {} class TablePanelCtrl {}
...@@ -58,7 +60,7 @@ describe('PanelModel', () => { ...@@ -58,7 +60,7 @@ describe('PanelModel', () => {
{ {
id: 'table', id: 'table',
}, },
null, // react (null as unknown) as ComponentClass<PanelProps>, // react
TablePanelCtrl // angular TablePanelCtrl // angular
); );
panelPlugin.setDefaults(defaultOptionsMock); panelPlugin.setDefaults(defaultOptionsMock);
......
import { PanelQueryRunner } from './PanelQueryRunner'; import { PanelQueryRunner } from './PanelQueryRunner';
import { PanelData, DataQueryRequest, dateTime, ScopedVars } from '@grafana/data'; import { DataQueryRequest, dateTime, PanelData, ScopedVars } from '@grafana/data';
import { DashboardModel } from './index'; import { DashboardModel } from './index';
import { setEchoSrv } from '@grafana/runtime'; import { setEchoSrv } from '@grafana/runtime';
import { Echo } from '../../../core/services/echo/Echo'; import { Echo } from '../../../core/services/echo/Echo';
...@@ -97,7 +97,7 @@ function describeQueryRunnerScenario(description: string, scenarioFn: ScenarioFn ...@@ -97,7 +97,7 @@ function describeQueryRunnerScenario(description: string, scenarioFn: ScenarioFn
ctx.runner.getData().subscribe({ ctx.runner.getData().subscribe({
next: (data: PanelData) => { next: (data: PanelData) => {
ctx.res = data; ctx.res = data;
ctx.events.push(data); ctx.events?.push(data);
}, },
}); });
...@@ -112,17 +112,17 @@ function describeQueryRunnerScenario(description: string, scenarioFn: ScenarioFn ...@@ -112,17 +112,17 @@ function describeQueryRunnerScenario(description: string, scenarioFn: ScenarioFn
describe('PanelQueryRunner', () => { describe('PanelQueryRunner', () => {
describeQueryRunnerScenario('simple scenario', ctx => { describeQueryRunnerScenario('simple scenario', ctx => {
it('should set requestId on request', async () => { it('should set requestId on request', async () => {
expect(ctx.queryCalledWith.requestId).toBe('Q100'); expect(ctx.queryCalledWith?.requestId).toBe('Q100');
}); });
it('should set datasource name on request', async () => { it('should set datasource name on request', async () => {
expect(ctx.queryCalledWith.targets[0].datasource).toBe('TestDB'); expect(ctx.queryCalledWith?.targets[0].datasource).toBe('TestDB');
}); });
it('should pass scopedVars to datasource with interval props', async () => { it('should pass scopedVars to datasource with interval props', async () => {
expect(ctx.queryCalledWith.scopedVars.server.text).toBe('Server1'); expect(ctx.queryCalledWith?.scopedVars.server.text).toBe('Server1');
expect(ctx.queryCalledWith.scopedVars.__interval.text).toBe('5m'); expect(ctx.queryCalledWith?.scopedVars.__interval.text).toBe('5m');
expect(ctx.queryCalledWith.scopedVars.__interval_ms.text).toBe('300000'); expect(ctx.queryCalledWith?.scopedVars.__interval_ms.text).toBe('300000');
}); });
}); });
...@@ -133,20 +133,20 @@ describe('PanelQueryRunner', () => { ...@@ -133,20 +133,20 @@ describe('PanelQueryRunner', () => {
}); });
it('should return data', async () => { it('should return data', async () => {
expect(ctx.res.error).toBeUndefined(); expect(ctx.res?.error).toBeUndefined();
expect(ctx.res.series.length).toBe(1); expect(ctx.res?.series.length).toBe(1);
}); });
it('should use widthPixels as maxDataPoints', async () => { it('should use widthPixels as maxDataPoints', async () => {
expect(ctx.queryCalledWith.maxDataPoints).toBe(200); expect(ctx.queryCalledWith?.maxDataPoints).toBe(200);
}); });
it('should calculate interval based on width', async () => { it('should calculate interval based on width', async () => {
expect(ctx.queryCalledWith.interval).toBe('5m'); expect(ctx.queryCalledWith?.interval).toBe('5m');
}); });
it('fast query should only publish 1 data events', async () => { it('fast query should only publish 1 data events', async () => {
expect(ctx.events.length).toBe(1); expect(ctx.events?.length).toBe(1);
}); });
}); });
...@@ -157,7 +157,7 @@ describe('PanelQueryRunner', () => { ...@@ -157,7 +157,7 @@ describe('PanelQueryRunner', () => {
}); });
it('should limit interval to data source min interval', async () => { it('should limit interval to data source min interval', async () => {
expect(ctx.queryCalledWith.interval).toBe('15s'); expect(ctx.queryCalledWith?.interval).toBe('15s');
}); });
}); });
...@@ -169,7 +169,7 @@ describe('PanelQueryRunner', () => { ...@@ -169,7 +169,7 @@ describe('PanelQueryRunner', () => {
}); });
it('should limit interval to panel min interval', async () => { it('should limit interval to panel min interval', async () => {
expect(ctx.queryCalledWith.interval).toBe('30s'); expect(ctx.queryCalledWith?.interval).toBe('30s');
}); });
}); });
...@@ -179,7 +179,7 @@ describe('PanelQueryRunner', () => { ...@@ -179,7 +179,7 @@ describe('PanelQueryRunner', () => {
}); });
it('should pass maxDataPoints if specified', async () => { it('should pass maxDataPoints if specified', async () => {
expect(ctx.queryCalledWith.maxDataPoints).toBe(10); expect(ctx.queryCalledWith?.maxDataPoints).toBe(10);
}); });
}); });
}); });
import { import {
DataFrame, DataFrame,
LoadingState,
dateTime,
PanelData,
DataSourceApi,
DataQueryRequest, DataQueryRequest,
DataQueryResponse, DataQueryResponse,
DataSourceApi,
dateTime,
LoadingState,
PanelData,
} from '@grafana/data'; } from '@grafana/data';
import { Subscriber, Observable, Subscription } from 'rxjs'; import { Observable, Subscriber, Subscription } from 'rxjs';
import { runRequest } from './runRequest'; import { runRequest } from './runRequest';
import { deepFreeze } from '../../../../test/core/redux/reducerTester'; import { deepFreeze } from '../../../../test/core/redux/reducerTester';
import { DashboardModel } from './DashboardModel'; import { DashboardModel } from './DashboardModel';
...@@ -37,7 +37,7 @@ class ScenarioCtx { ...@@ -37,7 +37,7 @@ class ScenarioCtx {
results: PanelData[]; results: PanelData[];
subscription: Subscription; subscription: Subscription;
wasStarted = false; wasStarted = false;
error: Error = null; error: Error | null = null;
toStartTime = dateTime(); toStartTime = dateTime();
fromStartTime = dateTime(); fromStartTime = dateTime();
...@@ -203,7 +203,7 @@ describe('runRequest', () => { ...@@ -203,7 +203,7 @@ describe('runRequest', () => {
}); });
it('should emit 1 error result', () => { it('should emit 1 error result', () => {
expect(ctx.results[0].error.message).toBe('Ohh no'); expect(ctx.results[0].error?.message).toBe('Ohh no');
expect(ctx.results[0].state).toBe(LoadingState.Error); expect(ctx.results[0].state).toBe(LoadingState.Error);
}); });
}); });
...@@ -223,7 +223,7 @@ describe('runRequest', () => { ...@@ -223,7 +223,7 @@ describe('runRequest', () => {
it('should add the correct timeRange property and the request range should not be mutated', () => { it('should add the correct timeRange property and the request range should not be mutated', () => {
expect(ctx.results[0].timeRange.to.valueOf()).toBeDefined(); expect(ctx.results[0].timeRange.to.valueOf()).toBeDefined();
expect(ctx.results[0].timeRange.to.valueOf()).not.toBe(ctx.toStartTime.valueOf()); expect(ctx.results[0].timeRange.to.valueOf()).not.toBe(ctx.toStartTime.valueOf());
expect(ctx.results[0].timeRange.to.valueOf()).not.toBe(ctx.results[0].request.range.to.valueOf()); expect(ctx.results[0].timeRange.to.valueOf()).not.toBe(ctx.results[0].request?.range?.to.valueOf());
expectThatRangeHasNotMutated(ctx); expectThatRangeHasNotMutated(ctx);
}); });
...@@ -231,8 +231,8 @@ describe('runRequest', () => { ...@@ -231,8 +231,8 @@ describe('runRequest', () => {
runRequestScenario('If time range is not relative', ctx => { runRequestScenario('If time range is not relative', ctx => {
ctx.setup(async () => { ctx.setup(async () => {
ctx.request.range.raw.from = ctx.fromStartTime; ctx.request.range!.raw.from = ctx.fromStartTime;
ctx.request.range.raw.to = ctx.toStartTime; ctx.request.range!.raw.to = ctx.toStartTime;
// any changes to ctx.request.range will throw and state would become LoadingState.Error // any changes to ctx.request.range will throw and state would become LoadingState.Error
deepFreeze(ctx.request.range); deepFreeze(ctx.request.range);
ctx.start(); ctx.start();
...@@ -246,7 +246,7 @@ describe('runRequest', () => { ...@@ -246,7 +246,7 @@ describe('runRequest', () => {
it('should add the correct timeRange property and the request range should not be mutated', () => { it('should add the correct timeRange property and the request range should not be mutated', () => {
expect(ctx.results[0].timeRange).toBeDefined(); expect(ctx.results[0].timeRange).toBeDefined();
expect(ctx.results[0].timeRange.to.valueOf()).toBe(ctx.toStartTime.valueOf()); expect(ctx.results[0].timeRange.to.valueOf()).toBe(ctx.toStartTime.valueOf());
expect(ctx.results[0].timeRange.to.valueOf()).toBe(ctx.results[0].request.range.to.valueOf()); expect(ctx.results[0].timeRange.to.valueOf()).toBe(ctx.results[0].request?.range?.to.valueOf());
expectThatRangeHasNotMutated(ctx); expectThatRangeHasNotMutated(ctx);
}); });
...@@ -255,7 +255,7 @@ describe('runRequest', () => { ...@@ -255,7 +255,7 @@ describe('runRequest', () => {
const expectThatRangeHasNotMutated = (ctx: ScenarioCtx) => { const expectThatRangeHasNotMutated = (ctx: ScenarioCtx) => {
// Make sure that the range for request is not changed and that deepfreeze hasn't thrown // Make sure that the range for request is not changed and that deepfreeze hasn't thrown
expect(ctx.results[0].request.range.to.valueOf()).toBe(ctx.toStartTime.valueOf()); expect(ctx.results[0].request?.range?.to.valueOf()).toBe(ctx.toStartTime.valueOf());
expect(ctx.results[0].error).not.toBeDefined(); expect(ctx.results[0].error).not.toBeDefined();
expect(ctx.results[0].state).toBe(LoadingState.Done); expect(ctx.results[0].state).toBe(LoadingState.Done);
}; };
......
import { TimeRange } from '@grafana/data'; import { dateTime, DateTime, PanelProps, TimeRange } from '@grafana/data';
import { applyPanelTimeOverrides, calculateInnerPanelHeight } from 'app/features/dashboard/utils/panel'; import { applyPanelTimeOverrides, calculateInnerPanelHeight } from 'app/features/dashboard/utils/panel';
import { advanceTo, clear } from 'jest-date-mock'; import { advanceTo, clear } from 'jest-date-mock';
import { dateTime, DateTime } from '@grafana/data';
import { PanelModel } from '../state'; import { PanelModel } from '../state';
import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks'; import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks';
import { ComponentClass } from 'react';
const dashboardTimeRange: TimeRange = { const dashboardTimeRange: TimeRange = {
from: dateTime([2019, 1, 11, 12, 0]), from: dateTime([2019, 1, 11, 12, 0]),
...@@ -83,7 +83,9 @@ describe('applyPanelTimeOverrides', () => { ...@@ -83,7 +83,9 @@ describe('applyPanelTimeOverrides', () => {
it('Calculate panel height with panel plugin zeroChromePadding', () => { it('Calculate panel height with panel plugin zeroChromePadding', () => {
const panelModel = new PanelModel({}); const panelModel = new PanelModel({});
panelModel.pluginLoaded(getPanelPlugin({ id: 'table' }, null, null).setNoPadding()); panelModel.pluginLoaded(
getPanelPlugin({ id: 'table' }, (null as unknown) as ComponentClass<PanelProps>, null).setNoPadding()
);
const height = calculateInnerPanelHeight(panelModel, 100); const height = calculateInnerPanelHeight(panelModel, 100);
expect(height).toBe(98); expect(height).toBe(98);
......
import { PayloadAction } from '@reduxjs/toolkit'; import { PayloadAction } from '@reduxjs/toolkit';
import { DataQuery, DefaultTimeZone, LogsDedupStrategy, RawTimeRange, toUtc, ExploreMode } from '@grafana/data'; import { DataQuery, DefaultTimeZone, ExploreMode, LogsDedupStrategy, RawTimeRange, toUtc } from '@grafana/data';
import * as Actions from './actions'; import * as Actions from './actions';
import { changeDatasource, loadDatasource, navigateToExplore, refreshExplore } from './actions'; import { changeDatasource, loadDatasource, navigateToExplore, refreshExplore } from './actions';
...@@ -289,7 +289,7 @@ describe('loading datasource', () => { ...@@ -289,7 +289,7 @@ describe('loading datasource', () => {
}); });
}); });
const getNavigateToExploreContext = async (openInNewWindow: (url: string) => void = undefined) => { const getNavigateToExploreContext = async (openInNewWindow?: (url: string) => void) => {
const url = 'http://www.someurl.com'; const url = 'http://www.someurl.com';
const panel: Partial<PanelModel> = { const panel: Partial<PanelModel> = {
datasource: 'mocked datasource', datasource: 'mocked datasource',
...@@ -320,7 +320,7 @@ const getNavigateToExploreContext = async (openInNewWindow: (url: string) => voi ...@@ -320,7 +320,7 @@ const getNavigateToExploreContext = async (openInNewWindow: (url: string) => voi
describe('navigateToExplore', () => { describe('navigateToExplore', () => {
describe('when navigateToExplore thunk is dispatched', () => { describe('when navigateToExplore thunk is dispatched', () => {
describe('and openInNewWindow is undefined', () => { describe('and openInNewWindow is undefined', () => {
const openInNewWindow: (url: string) => void = undefined; const openInNewWindow: (url: string) => void = (undefined as unknown) as (url: string) => void;
it('then it should dispatch correct actions', async () => { it('then it should dispatch correct actions', async () => {
const { dispatchedActions, url } = await getNavigateToExploreContext(openInNewWindow); const { dispatchedActions, url } = await getNavigateToExploreContext(openInNewWindow);
......
...@@ -16,7 +16,7 @@ jest.mock('@grafana/data/src/datetime/moment_wrapper', () => ({ ...@@ -16,7 +16,7 @@ jest.mock('@grafana/data/src/datetime/moment_wrapper', () => ({
import { ResultProcessor } from './ResultProcessor'; import { ResultProcessor } from './ResultProcessor';
import { ExploreItemState } from 'app/types/explore'; import { ExploreItemState } from 'app/types/explore';
import TableModel from 'app/core/table_model'; import TableModel from 'app/core/table_model';
import { TimeSeries, LogRowModel, toDataFrame, FieldType, ExploreMode } from '@grafana/data'; import { ExploreMode, FieldType, LogRowModel, TimeSeries, toDataFrame } from '@grafana/data';
const testContext = (options: any = {}) => { const testContext = (options: any = {}) => {
const timeSeries = toDataFrame({ const timeSeries = toDataFrame({
...@@ -131,11 +131,11 @@ describe('ResultProcessor', () => { ...@@ -131,11 +131,11 @@ describe('ResultProcessor', () => {
it('then it should return correct table result', () => { it('then it should return correct table result', () => {
const { resultProcessor } = testContext(); const { resultProcessor } = testContext();
let theResult = resultProcessor.getTableResult(); let theResult = resultProcessor.getTableResult();
expect(theResult.fields[0].name).toEqual('value'); expect(theResult?.fields[0].name).toEqual('value');
expect(theResult.fields[1].name).toEqual('time'); expect(theResult?.fields[1].name).toEqual('time');
expect(theResult.fields[2].name).toEqual('message'); expect(theResult?.fields[2].name).toEqual('message');
expect(theResult.fields[1].display).not.toBeNull(); expect(theResult?.fields[1].display).not.toBeNull();
expect(theResult.length).toBe(3); expect(theResult?.length).toBe(3);
// Same data though a DataFrame // Same data though a DataFrame
theResult = toDataFrame( theResult = toDataFrame(
......
import { getLinksFromLogsField, getFieldLinksSupplier } from './linkSuppliers'; import { getFieldLinksSupplier, getLinksFromLogsField } from './linkSuppliers';
import { import {
applyFieldOverrides,
ArrayVector, ArrayVector,
DataFrameView,
dateTime, dateTime,
Field, Field,
FieldDisplay,
FieldType, FieldType,
toDataFrame,
applyFieldOverrides,
GrafanaTheme, GrafanaTheme,
FieldDisplay, toDataFrame,
DataFrameView,
} from '@grafana/data'; } from '@grafana/data';
import { getLinkSrv, LinkService, LinkSrv, setLinkSrv } from './link_srv'; import { getLinkSrv, LinkService, LinkSrv, setLinkSrv } from './link_srv';
import { TemplateSrv } from '../../templating/template_srv'; import { TemplateSrv } from '../../templating/template_srv';
...@@ -152,7 +152,7 @@ describe('getLinksFromLogsField', () => { ...@@ -152,7 +152,7 @@ describe('getLinksFromLogsField', () => {
}; };
const supplier = getFieldLinksSupplier(fieldDisp); const supplier = getFieldLinksSupplier(fieldDisp);
const links = supplier.getLinks({}).map(m => { const links = supplier?.getLinks({}).map(m => {
return { return {
title: m.title, title: m.title,
href: m.href, href: m.href,
......
import '../playlist_edit_ctrl'; import '../playlist_edit_ctrl';
import { PlaylistEditCtrl } from '../playlist_edit_ctrl'; import { PlaylistEditCtrl } from '../playlist_edit_ctrl';
import { ILocationService, IScope } from 'angular';
import { AppEventEmitter } from '../../../types';
describe('PlaylistEditCtrl', () => { describe('PlaylistEditCtrl', () => {
let ctx: any; let ctx: any;
...@@ -10,7 +12,12 @@ describe('PlaylistEditCtrl', () => { ...@@ -10,7 +12,12 @@ describe('PlaylistEditCtrl', () => {
}, },
}; };
ctx = new PlaylistEditCtrl(null, null, { current: { params: {} } }, navModelSrv); ctx = new PlaylistEditCtrl(
(null as unknown) as IScope & AppEventEmitter,
(null as unknown) as ILocationService,
{ current: { params: {} } },
navModelSrv
);
ctx.dashboardresult = [ ctx.dashboardresult = [
{ id: 2, title: 'dashboard: 2' }, { id: 2, title: 'dashboard: 2' },
......
...@@ -2,25 +2,25 @@ import { reduxTester } from '../../../../../test/core/redux/reduxTester'; ...@@ -2,25 +2,25 @@ import { reduxTester } from '../../../../../test/core/redux/reduxTester';
import { getTemplatingRootReducer } from '../../state/helpers'; import { getTemplatingRootReducer } from '../../state/helpers';
import { initDashboardTemplating } from '../../state/actions'; import { initDashboardTemplating } from '../../state/actions';
import { TemplatingState } from '../../state/reducers'; import { TemplatingState } from '../../state/reducers';
import { VariableHide, VariableSort, VariableRefresh, QueryVariableModel } from '../../variable'; import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../../variable';
import { import {
showOptions,
hideOptions, hideOptions,
showOptions,
toggleOption, toggleOption,
updateSearchQuery,
updateOptionsAndFilter,
toggleTag, toggleTag,
updateOptionsAndFilter,
updateSearchQuery,
} from './reducer'; } from './reducer';
import { import {
navigateOptions,
filterOrSearchOptions,
commitChangesToVariable, commitChangesToVariable,
toggleOptionByHighlight, filterOrSearchOptions,
navigateOptions,
toggleAndFetchTag, toggleAndFetchTag,
toggleOptionByHighlight,
} from './actions'; } from './actions';
import { NavigationKey } from '../types'; import { NavigationKey } from '../types';
import { toVariablePayload } from '../../state/types'; import { toVariablePayload } from '../../state/types';
import { setCurrentVariableValue, changeVariableProp } from '../../state/sharedReducer'; import { changeVariableProp, setCurrentVariableValue } from '../../state/sharedReducer';
import { variableAdapters } from '../../adapters'; import { variableAdapters } from '../../adapters';
import { createQueryVariableAdapter } from '../../query/adapter'; import { createQueryVariableAdapter } from '../../query/adapter';
...@@ -374,6 +374,8 @@ describe('options picker actions', () => { ...@@ -374,6 +374,8 @@ describe('options picker actions', () => {
const variable = createVariable({ options, includeAll: false, tags: [tag] }); const variable = createVariable({ options, includeAll: false, tags: [tag] });
datasource.metricFindQuery.mockReset(); datasource.metricFindQuery.mockReset();
// @ts-ignore couldn't wrap my head around this
// error TS2345: Argument of type '() => Promise<{ value: string; text: string; }[]>' is not assignable to parameter of type '() => Promise<never[]>'.
datasource.metricFindQuery.mockImplementation(() => Promise.resolve(values)); datasource.metricFindQuery.mockImplementation(() => Promise.resolve(values));
const tester = await reduxTester<{ templating: TemplatingState }>() const tester = await reduxTester<{ templating: TemplatingState }>()
......
...@@ -2,23 +2,23 @@ import { variableAdapters } from '../adapters'; ...@@ -2,23 +2,23 @@ import { variableAdapters } from '../adapters';
import { createQueryVariableAdapter } from './adapter'; import { createQueryVariableAdapter } from './adapter';
import { reduxTester } from '../../../../test/core/redux/reduxTester'; import { reduxTester } from '../../../../test/core/redux/reduxTester';
import { getTemplatingRootReducer } from '../state/helpers'; import { getTemplatingRootReducer } from '../state/helpers';
import { QueryVariableModel, VariableHide, VariableSort, VariableRefresh } from '../variable'; import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../variable';
import { toVariablePayload, ALL_VARIABLE_VALUE, ALL_VARIABLE_TEXT } from '../state/types'; import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, toVariablePayload } from '../state/types';
import { setCurrentVariableValue, changeVariableProp } from '../state/sharedReducer'; import { changeVariableProp, setCurrentVariableValue } from '../state/sharedReducer';
import { initDashboardTemplating } from '../state/actions'; import { initDashboardTemplating } from '../state/actions';
import { TemplatingState } from '../state/reducers'; import { TemplatingState } from '../state/reducers';
import { import {
updateQueryVariableOptions,
initQueryVariableEditor,
changeQueryVariableDataSource, changeQueryVariableDataSource,
changeQueryVariableQuery, changeQueryVariableQuery,
initQueryVariableEditor,
updateQueryVariableOptions,
} from './actions'; } from './actions';
import { updateVariableOptions, updateVariableTags } from './reducer'; import { updateVariableOptions, updateVariableTags } from './reducer';
import { import {
setIdInEditor,
removeVariableEditorError,
addVariableEditorError, addVariableEditorError,
changeVariableEditorExtended, changeVariableEditorExtended,
removeVariableEditorError,
setIdInEditor,
} from '../editor/reducer'; } from '../editor/reducer';
import DefaultVariableQueryEditor from '../DefaultVariableQueryEditor'; import DefaultVariableQueryEditor from '../DefaultVariableQueryEditor';
import { expect } from 'test/lib/common'; import { expect } from 'test/lib/common';
...@@ -163,7 +163,7 @@ describe('query actions', () => { ...@@ -163,7 +163,7 @@ describe('query actions', () => {
const tester = await reduxTester<{ templating: TemplatingState }>() const tester = await reduxTester<{ templating: TemplatingState }>()
.givenRootReducer(getTemplatingRootReducer()) .givenRootReducer(getTemplatingRootReducer())
.whenActionIsDispatched(initDashboardTemplating([variable])) .whenActionIsDispatched(initDashboardTemplating([variable]))
.whenActionIsDispatched(setIdInEditor({ id: variable.uuid })) .whenActionIsDispatched(setIdInEditor({ id: variable.uuid! }))
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); .whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true);
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE);
...@@ -185,12 +185,12 @@ describe('query actions', () => { ...@@ -185,12 +185,12 @@ describe('query actions', () => {
const variable = createVariable({ includeAll: true, useTags: false }); const variable = createVariable({ includeAll: true, useTags: false });
const error = { message: 'failed to fetch metrics' }; const error = { message: 'failed to fetch metrics' };
mocks[variable.datasource].metricFindQuery = jest.fn(() => Promise.reject(error)); mocks[variable.datasource!].metricFindQuery = jest.fn(() => Promise.reject(error));
const tester = await reduxTester<{ templating: TemplatingState }>() const tester = await reduxTester<{ templating: TemplatingState }>()
.givenRootReducer(getTemplatingRootReducer()) .givenRootReducer(getTemplatingRootReducer())
.whenActionIsDispatched(initDashboardTemplating([variable])) .whenActionIsDispatched(initDashboardTemplating([variable]))
.whenActionIsDispatched(setIdInEditor({ id: variable.uuid })) .whenActionIsDispatched(setIdInEditor({ id: variable.uuid! }))
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); .whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true);
tester.thenDispatchedActionPredicateShouldEqual(actions => { tester.thenDispatchedActionPredicateShouldEqual(actions => {
...@@ -241,7 +241,7 @@ describe('query actions', () => { ...@@ -241,7 +241,7 @@ describe('query actions', () => {
it('then correct actions are dispatched', async () => { it('then correct actions are dispatched', async () => {
const variable = createVariable({ includeAll: true, useTags: false }); const variable = createVariable({ includeAll: true, useTags: false });
const defaultMetricSource = { name: '', value: '', meta: {}, sort: '' }; const defaultMetricSource = { name: '', value: '', meta: {}, sort: '' };
const testMetricSource = { name: 'test', value: null as string, meta: {}, sort: '' }; const testMetricSource = { name: 'test', value: (null as unknown) as string, meta: {}, sort: '' };
const editor = {}; const editor = {};
mocks.datasourceSrv.getMetricSources = jest.fn().mockReturnValue([testMetricSource]); mocks.datasourceSrv.getMetricSources = jest.fn().mockReturnValue([testMetricSource]);
...@@ -521,7 +521,7 @@ function mockDatasourceMetrics(variable: QueryVariableModel, optionsMetrics: any ...@@ -521,7 +521,7 @@ function mockDatasourceMetrics(variable: QueryVariableModel, optionsMetrics: any
[variable.tagsQuery]: tagsMetrics, [variable.tagsQuery]: tagsMetrics,
}; };
const { metricFindQuery } = mocks[variable.datasource]; const { metricFindQuery } = mocks[variable.datasource!];
metricFindQuery.mockReset(); metricFindQuery.mockReset();
metricFindQuery.mockImplementation((query: string) => Promise.resolve(metrics[query] ?? [])); metricFindQuery.mockImplementation((query: string) => Promise.resolve(metrics[query] ?? []));
......
...@@ -5,7 +5,7 @@ import { act } from 'react-dom/test-utils'; ...@@ -5,7 +5,7 @@ import { act } from 'react-dom/test-utils';
import { DataSourceInstanceSettings } from '@grafana/data'; import { DataSourceInstanceSettings } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv'; import { TemplateSrv } from 'app/features/templating/template_srv';
import { CustomVariable } from 'app/features/templating/all'; import { CustomVariable } from 'app/features/templating/all';
import { QueryEditor, Props } from './QueryEditor'; import { Props, QueryEditor } from './QueryEditor';
import CloudWatchDatasource from '../datasource'; import CloudWatchDatasource from '../datasource';
const setup = () => { const setup = () => {
...@@ -70,9 +70,10 @@ describe('QueryEditor', () => { ...@@ -70,9 +70,10 @@ describe('QueryEditor', () => {
describe('should use correct default values', () => { describe('should use correct default values', () => {
it('when region is null is display default in the label', async () => { it('when region is null is display default in the label', async () => {
// @ts-ignore strict null error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
await act(async () => { await act(async () => {
const props = setup(); const props = setup();
props.query.region = null; props.query.region = (null as unknown) as string;
const wrapper = mount(<QueryEditor {...props} />); const wrapper = mount(<QueryEditor {...props} />);
expect( expect(
wrapper wrapper
...@@ -86,14 +87,15 @@ describe('QueryEditor', () => { ...@@ -86,14 +87,15 @@ describe('QueryEditor', () => {
}); });
it('should init props correctly', async () => { it('should init props correctly', async () => {
// @ts-ignore strict null error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
await act(async () => { await act(async () => {
const props = setup(); const props = setup();
props.query.namespace = null; props.query.namespace = (null as unknown) as string;
props.query.metricName = null; props.query.metricName = (null as unknown) as string;
props.query.expression = null; props.query.expression = (null as unknown) as string;
props.query.dimensions = null; props.query.dimensions = (null as unknown) as { [key: string]: string | string[] };
props.query.region = null; props.query.region = (null as unknown) as string;
props.query.statistics = null; props.query.statistics = (null as unknown) as string[];
const wrapper = mount(<QueryEditor {...props} />); const wrapper = mount(<QueryEditor {...props} />);
const { const {
query: { namespace, region, metricName, dimensions, statistics, expression }, query: { namespace, region, metricName, dimensions, statistics, expression },
......
...@@ -6,8 +6,8 @@ describe('SharedQueryRunner', () => { ...@@ -6,8 +6,8 @@ describe('SharedQueryRunner', () => {
expect(isSharedDashboardQuery('-- Dashboard --')).toBe(true); expect(isSharedDashboardQuery('-- Dashboard --')).toBe(true);
expect(isSharedDashboardQuery('')).toBe(false); expect(isSharedDashboardQuery('')).toBe(false);
expect(isSharedDashboardQuery(undefined)).toBe(false); expect(isSharedDashboardQuery((undefined as unknown) as string | DataSourceApi)).toBe(false);
expect(isSharedDashboardQuery(null)).toBe(false); expect(isSharedDashboardQuery((null as unknown) as string | DataSourceApi)).toBe(false);
const ds = { const ds = {
meta: { meta: {
...@@ -16,7 +16,7 @@ describe('SharedQueryRunner', () => { ...@@ -16,7 +16,7 @@ describe('SharedQueryRunner', () => {
} as DataSourceApi; } as DataSourceApi;
expect(isSharedDashboardQuery(ds)).toBe(true); expect(isSharedDashboardQuery(ds)).toBe(true);
ds.meta.name = 'something else'; ds.meta!.name = 'something else';
expect(isSharedDashboardQuery(ds)).toBe(false); expect(isSharedDashboardQuery(ds)).toBe(false);
}); });
}); });
...@@ -917,7 +917,12 @@ describe('ElasticResponse', () => { ...@@ -917,7 +917,12 @@ describe('ElasticResponse', () => {
expect(r._id).toEqual(response.responses[0].hits.hits[i]._id); expect(r._id).toEqual(response.responses[0].hits.hits[i]._id);
expect(r._type).toEqual(response.responses[0].hits.hits[i]._type); expect(r._type).toEqual(response.responses[0].hits.hits[i]._type);
expect(r._index).toEqual(response.responses[0].hits.hits[i]._index); expect(r._index).toEqual(response.responses[0].hits.hits[i]._index);
expect(r._source).toEqual(flatten(response.responses[0].hits.hits[i]._source, null)); expect(r._source).toEqual(
flatten(
response.responses[0].hits.hits[i]._source,
(null as unknown) as { delimiter?: any; maxDepth?: any; safe?: any }
)
);
} }
// Make a map from the histogram results // Make a map from the histogram results
...@@ -938,14 +943,14 @@ describe('ElasticResponse', () => { ...@@ -938,14 +943,14 @@ describe('ElasticResponse', () => {
const result = new ElasticResponse(targets, response).getLogs(undefined, 'level'); const result = new ElasticResponse(targets, response).getLogs(undefined, 'level');
const fieldCache = new FieldCache(result.data[0]); const fieldCache = new FieldCache(result.data[0]);
const field = fieldCache.getFieldByName('level'); const field = fieldCache.getFieldByName('level');
expect(field.values.toArray()).toEqual(['debug', 'error']); expect(field?.values.toArray()).toEqual(['debug', 'error']);
}); });
it('should re map levels field to new field', () => { it('should re map levels field to new field', () => {
const result = new ElasticResponse(targets, response).getLogs(undefined, 'fields.lvl'); const result = new ElasticResponse(targets, response).getLogs(undefined, 'fields.lvl');
const fieldCache = new FieldCache(result.data[0]); const fieldCache = new FieldCache(result.data[0]);
const field = fieldCache.getFieldByName('level'); const field = fieldCache.getFieldByName('level');
expect(field.values.toArray()).toEqual(['debug', 'info']); expect(field?.values.toArray()).toEqual(['debug', 'info']);
}); });
}); });
}); });
...@@ -135,7 +135,7 @@ describe('AppInsightsDatasource', () => { ...@@ -135,7 +135,7 @@ describe('AppInsightsDatasource', () => {
rawQueryString: queryString, rawQueryString: queryString,
timeColumn: 'timestamp', timeColumn: 'timestamp',
valueColumn: 'max', valueColumn: 'max',
segmentColumn: undefined as string, segmentColumn: (undefined as unknown) as string,
}, },
}, },
], ],
......
...@@ -5,6 +5,7 @@ import { InfluxDatasourceMock } from '../datasource.mock'; ...@@ -5,6 +5,7 @@ import { InfluxDatasourceMock } from '../datasource.mock';
import InfluxDatasource from '../datasource'; import InfluxDatasource from '../datasource';
import { InfluxQuery } from '../types'; import { InfluxQuery } from '../types';
import { ButtonCascader } from '@grafana/ui'; import { ButtonCascader } from '@grafana/ui';
import { KeyValuePair } from '../../../../features/explore/AdHocFilterField';
describe('pairsAreValid()', () => { describe('pairsAreValid()', () => {
describe('when all pairs are fully defined', () => { describe('when all pairs are fully defined', () => {
...@@ -34,7 +35,7 @@ describe('pairsAreValid()', () => { ...@@ -34,7 +35,7 @@ describe('pairsAreValid()', () => {
describe('when pairs are undefined', () => { describe('when pairs are undefined', () => {
it('should return true', () => { it('should return true', () => {
expect(pairsAreValid(undefined)).toBe(true); expect(pairsAreValid((undefined as unknown) as KeyValuePair[])).toBe(true);
}); });
}); });
......
...@@ -7,7 +7,7 @@ import { AdHocFilterField, KeyValuePair } from 'app/features/explore/AdHocFilter ...@@ -7,7 +7,7 @@ import { AdHocFilterField, KeyValuePair } from 'app/features/explore/AdHocFilter
import { TemplateSrv } from 'app/features/templating/template_srv'; import { TemplateSrv } from 'app/features/templating/template_srv';
import InfluxDatasource from '../datasource'; import InfluxDatasource from '../datasource';
import { InfluxQueryBuilder } from '../query_builder'; import { InfluxQueryBuilder } from '../query_builder';
import { InfluxQuery, InfluxOptions } from '../types'; import { InfluxOptions, InfluxQuery } from '../types';
export interface Props extends ExploreQueryFieldProps<InfluxDatasource, InfluxQuery, InfluxOptions> {} export interface Props extends ExploreQueryFieldProps<InfluxDatasource, InfluxQuery, InfluxOptions> {}
...@@ -49,7 +49,12 @@ function getChooserText({ measurement, field, error }: ChooserOptions): string { ...@@ -49,7 +49,12 @@ function getChooserText({ measurement, field, error }: ChooserOptions): string {
export class InfluxLogsQueryField extends React.PureComponent<Props, State> { export class InfluxLogsQueryField extends React.PureComponent<Props, State> {
templateSrv: TemplateSrv = new TemplateSrv(); templateSrv: TemplateSrv = new TemplateSrv();
state: State = { measurements: [], measurement: null, field: null, error: null }; state: State = {
measurements: [],
measurement: (null as unknown) as string,
field: (null as unknown) as string,
error: (null as unknown) as string,
};
async componentDidMount() { async componentDidMount() {
const { datasource } = this.props; const { datasource } = this.props;
......
...@@ -262,10 +262,10 @@ describe('InfluxQuery', () => { ...@@ -262,10 +262,10 @@ describe('InfluxQuery', () => {
); );
query.addGroupBy('tag(host)'); query.addGroupBy('tag(host)');
expect(query.target.groupBy.length).toBe(3); expect(query.target.groupBy?.length).toBe(3);
expect(query.target.groupBy[1].type).toBe('tag'); expect(query.target.groupBy![1].type).toBe('tag');
expect(query.target.groupBy[1].params[0]).toBe('host'); expect(query.target.groupBy![1].params![0]).toBe('host');
expect(query.target.groupBy[2].type).toBe('fill'); expect(query.target.groupBy![2].type).toBe('fill');
}); });
it('should add tag last if no fill', () => { it('should add tag last if no fill', () => {
...@@ -280,8 +280,8 @@ describe('InfluxQuery', () => { ...@@ -280,8 +280,8 @@ describe('InfluxQuery', () => {
); );
query.addGroupBy('tag(host)'); query.addGroupBy('tag(host)');
expect(query.target.groupBy.length).toBe(1); expect(query.target.groupBy?.length).toBe(1);
expect(query.target.groupBy[0].type).toBe('tag'); expect(query.target.groupBy![0].type).toBe('tag');
}); });
}); });
...@@ -298,8 +298,8 @@ describe('InfluxQuery', () => { ...@@ -298,8 +298,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'mean'); query.addSelectPart(query.selectModels[0], 'mean');
expect(query.target.select[0].length).toBe(2); expect(query.target.select![0].length).toBe(2);
expect(query.target.select[0][1].type).toBe('mean'); expect(query.target.select![0][1].type).toBe('mean');
}); });
it('should replace sum by mean', () => { it('should replace sum by mean', () => {
...@@ -314,8 +314,8 @@ describe('InfluxQuery', () => { ...@@ -314,8 +314,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'sum'); query.addSelectPart(query.selectModels[0], 'sum');
expect(query.target.select[0].length).toBe(2); expect(query.target.select![0].length).toBe(2);
expect(query.target.select[0][1].type).toBe('sum'); expect(query.target.select![0][1].type).toBe('sum');
}); });
it('should add math before alias', () => { it('should add math before alias', () => {
...@@ -330,8 +330,8 @@ describe('InfluxQuery', () => { ...@@ -330,8 +330,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'math'); query.addSelectPart(query.selectModels[0], 'math');
expect(query.target.select[0].length).toBe(4); expect(query.target.select![0].length).toBe(4);
expect(query.target.select[0][2].type).toBe('math'); expect(query.target.select![0][2].type).toBe('math');
}); });
it('should add math last', () => { it('should add math last', () => {
...@@ -346,8 +346,8 @@ describe('InfluxQuery', () => { ...@@ -346,8 +346,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'math'); query.addSelectPart(query.selectModels[0], 'math');
expect(query.target.select[0].length).toBe(3); expect(query.target.select![0].length).toBe(3);
expect(query.target.select[0][2].type).toBe('math'); expect(query.target.select![0][2].type).toBe('math');
}); });
it('should replace math', () => { it('should replace math', () => {
...@@ -362,8 +362,8 @@ describe('InfluxQuery', () => { ...@@ -362,8 +362,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'math'); query.addSelectPart(query.selectModels[0], 'math');
expect(query.target.select[0].length).toBe(3); expect(query.target.select![0].length).toBe(3);
expect(query.target.select[0][2].type).toBe('math'); expect(query.target.select![0][2].type).toBe('math');
}); });
it('should add math when one only query part', () => { it('should add math when one only query part', () => {
...@@ -378,8 +378,8 @@ describe('InfluxQuery', () => { ...@@ -378,8 +378,8 @@ describe('InfluxQuery', () => {
); );
query.addSelectPart(query.selectModels[0], 'math'); query.addSelectPart(query.selectModels[0], 'math');
expect(query.target.select[0].length).toBe(2); expect(query.target.select![0].length).toBe(2);
expect(query.target.select[0][1].type).toBe('math'); expect(query.target.select![0][1].type).toBe('math');
}); });
describe('when render adhoc filters', () => { describe('when render adhoc filters', () => {
......
import InputDatasource, { describeDataFrame } from './InputDatasource'; import InputDatasource, { describeDataFrame } from './InputDatasource';
import { InputQuery, InputOptions } from './types'; import { InputOptions, InputQuery } from './types';
import { readCSV, DataFrame, MutableDataFrame, DataSourceInstanceSettings, PluginMeta } from '@grafana/data'; import {
DataFrame,
DataFrameDTO,
DataSourceInstanceSettings,
MutableDataFrame,
PluginMeta,
readCSV,
} from '@grafana/data';
import { getQueryOptions } from 'test/helpers/getQueryOptions'; import { getQueryOptions } from 'test/helpers/getQueryOptions';
...@@ -35,7 +42,7 @@ describe('InputDatasource', () => { ...@@ -35,7 +42,7 @@ describe('InputDatasource', () => {
test('DataFrame descriptions', () => { test('DataFrame descriptions', () => {
expect(describeDataFrame([])).toEqual(''); expect(describeDataFrame([])).toEqual('');
expect(describeDataFrame(null)).toEqual(''); expect(describeDataFrame((null as unknown) as Array<DataFrameDTO | DataFrame>)).toEqual('');
expect( expect(
describeDataFrame([ describeDataFrame([
new MutableDataFrame({ new MutableDataFrame({
......
...@@ -80,6 +80,7 @@ describe('LokiExploreQueryEditor', () => { ...@@ -80,6 +80,7 @@ describe('LokiExploreQueryEditor', () => {
}); });
it('should render LokiQueryField with ExtraFieldElement when ExploreMode is set to Logs', async () => { it('should render LokiQueryField with ExtraFieldElement when ExploreMode is set to Logs', async () => {
// @ts-ignore strict null error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
await act(async () => { await act(async () => {
const wrapper = setup(mount); const wrapper = setup(mount);
expect(wrapper.find(LokiExploreExtraField).length).toBe(1); expect(wrapper.find(LokiExploreExtraField).length).toBe(1);
...@@ -87,6 +88,7 @@ describe('LokiExploreQueryEditor', () => { ...@@ -87,6 +88,7 @@ describe('LokiExploreQueryEditor', () => {
}); });
it('should render LokiQueryField with no ExtraFieldElement when ExploreMode is not Logs', async () => { it('should render LokiQueryField with no ExtraFieldElement when ExploreMode is not Logs', async () => {
// @ts-ignore strict null error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
await act(async () => { await act(async () => {
const wrapper = setup(mount, { exploreMode: ExploreMode.Metrics }); const wrapper = setup(mount, { exploreMode: ExploreMode.Metrics });
expect(wrapper.find(LokiExploreExtraField).length).toBe(0); expect(wrapper.find(LokiExploreExtraField).length).toBe(0);
......
import LokiDatasource, { RangeQueryOptions } from './datasource'; import LokiDatasource, { RangeQueryOptions } from './datasource';
import { LokiQuery, LokiResultType, LokiResponse, LokiLegacyStreamResponse } from './types'; import { LokiLegacyStreamResponse, LokiQuery, LokiResponse, LokiResultType } from './types';
import { getQueryOptions } from 'test/helpers/getQueryOptions'; import { getQueryOptions } from 'test/helpers/getQueryOptions';
import { import {
AnnotationQueryRequest, AnnotationQueryRequest,
DataSourceApi,
DataFrame, DataFrame,
DataSourceApi,
dateTime, dateTime,
TimeRange,
ExploreMode, ExploreMode,
FieldCache, FieldCache,
TimeRange,
} from '@grafana/data'; } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv'; import { TemplateSrv } from 'app/features/templating/template_srv';
import { CustomVariable } from 'app/features/templating/custom_variable'; import { CustomVariable } from 'app/features/templating/custom_variable';
...@@ -219,9 +219,9 @@ describe('LokiDatasource', () => { ...@@ -219,9 +219,9 @@ describe('LokiDatasource', () => {
const dataFrame = res.data[0] as DataFrame; const dataFrame = res.data[0] as DataFrame;
const fieldCache = new FieldCache(dataFrame); const fieldCache = new FieldCache(dataFrame);
expect(fieldCache.getFieldByName('line').values.get(0)).toBe('hello'); expect(fieldCache.getFieldByName('line')?.values.get(0)).toBe('hello');
expect(dataFrame.meta.limit).toBe(20); expect(dataFrame.meta?.limit).toBe(20);
expect(dataFrame.meta.searchWords).toEqual(['foo']); expect(dataFrame.meta?.searchWords).toEqual(['foo']);
}); });
}); });
...@@ -373,7 +373,7 @@ describe('LokiDatasource', () => { ...@@ -373,7 +373,7 @@ describe('LokiDatasource', () => {
}; };
// Odd timerange/interval combination that would lead to a float step // Odd timerange/interval combination that would lead to a float step
const options: RangeQueryOptions = { range, intervalMs: 2000 }; const options: RangeQueryOptions = { range, intervalMs: 2000 };
expect(Number.isInteger(ds.createRangeQuery(query, options).step)).toBeTruthy(); expect(Number.isInteger(ds.createRangeQuery(query, options).step!)).toBeTruthy();
}); });
}); });
...@@ -478,7 +478,7 @@ type LimitTestArgs = { ...@@ -478,7 +478,7 @@ type LimitTestArgs = {
function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templateSrvMock: any, testResp: any) { function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templateSrvMock: any, testResp: any) {
return ({ maxDataPoints, maxLines, expectedLimit }: LimitTestArgs) => { return ({ maxDataPoints, maxLines, expectedLimit }: LimitTestArgs) => {
let settings = instanceSettings; let settings = instanceSettings;
if (Number.isFinite(maxLines)) { if (Number.isFinite(maxLines!)) {
const customData = { ...(instanceSettings.jsonData || {}), maxLines: 20 }; const customData = { ...(instanceSettings.jsonData || {}), maxLines: 20 };
settings = { ...instanceSettings, jsonData: customData }; settings = { ...instanceSettings, jsonData: customData };
} }
...@@ -486,7 +486,7 @@ function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templa ...@@ -486,7 +486,7 @@ function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templa
datasourceRequestMock.mockImplementation(() => Promise.resolve(testResp)); datasourceRequestMock.mockImplementation(() => Promise.resolve(testResp));
const options = getQueryOptions<LokiQuery>({ targets: [{ expr: 'foo', refId: 'B', maxLines: maxDataPoints }] }); const options = getQueryOptions<LokiQuery>({ targets: [{ expr: 'foo', refId: 'B', maxLines: maxDataPoints }] });
if (Number.isFinite(maxDataPoints)) { if (Number.isFinite(maxDataPoints!)) {
options.maxDataPoints = maxDataPoints; options.maxDataPoints = maxDataPoints;
} else { } else {
// By default is 500 // By default is 500
......
import { Subject, Observable } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import * as rxJsWebSocket from 'rxjs/webSocket'; import * as rxJsWebSocket from 'rxjs/webSocket';
import { LiveStreams } from './live_streams'; import { LiveStreams } from './live_streams';
import { DataFrameView, Labels, formatLabels, DataFrame } from '@grafana/data'; import { DataFrame, DataFrameView, formatLabels, Labels } from '@grafana/data';
import { noop } from 'lodash'; import { noop } from 'lodash';
let fakeSocket: Subject<any>; let fakeSocket: Subject<any>;
...@@ -59,7 +59,7 @@ describe('Live Stream Tests', () => { ...@@ -59,7 +59,7 @@ describe('Live Stream Tests', () => {
stream.subscribe({ stream.subscribe({
next: val => { next: val => {
const test = tests.shift(); const test = tests.shift();
test(val); test!(val);
}, },
complete: () => done(), complete: () => done(),
}); });
......
import { FieldType, MutableDataFrame, CircularDataFrame } from '@grafana/data'; import { CircularDataFrame, FieldType, MutableDataFrame } from '@grafana/data';
import { LokiLegacyStreamResult, LokiStreamResult, LokiTailResponse } from './types'; import { LokiLegacyStreamResult, LokiStreamResult, LokiTailResponse } from './types';
import * as ResultTransformer from './result_transformer'; import * as ResultTransformer from './result_transformer';
...@@ -52,7 +52,7 @@ describe('loki result transformer', () => { ...@@ -52,7 +52,7 @@ describe('loki result transformer', () => {
const data = legacyStreamResult.map(stream => ResultTransformer.legacyLogStreamToDataFrame(stream)); const data = legacyStreamResult.map(stream => ResultTransformer.legacyLogStreamToDataFrame(stream));
expect(data.length).toBe(2); expect(data.length).toBe(2);
expect(data[0].fields[1].labels['foo']).toEqual('bar'); expect(data[0].fields[1].labels!['foo']).toEqual('bar');
expect(data[0].fields[0].values.get(0)).toEqual(legacyStreamResult[0].entries[0].ts); expect(data[0].fields[0].values.get(0)).toEqual(legacyStreamResult[0].entries[0].ts);
expect(data[0].fields[1].values.get(0)).toEqual(legacyStreamResult[0].entries[0].line); expect(data[0].fields[1].values.get(0)).toEqual(legacyStreamResult[0].entries[0].line);
expect(data[0].fields[2].values.get(0)).toEqual('2764544e18dbc3fcbeee21a573e8cd1b'); expect(data[0].fields[2].values.get(0)).toEqual('2764544e18dbc3fcbeee21a573e8cd1b');
...@@ -94,7 +94,7 @@ describe('loki result transformer', () => { ...@@ -94,7 +94,7 @@ describe('loki result transformer', () => {
const data = streamResult.map(stream => ResultTransformer.lokiStreamResultToDataFrame(stream)); const data = streamResult.map(stream => ResultTransformer.lokiStreamResultToDataFrame(stream));
expect(data.length).toBe(2); expect(data.length).toBe(2);
expect(data[0].fields[1].labels['foo']).toEqual('bar'); expect(data[0].fields[1].labels!['foo']).toEqual('bar');
expect(data[0].fields[0].values.get(0)).toEqual('2020-01-24T09:19:22.021Z'); expect(data[0].fields[0].values.get(0)).toEqual('2020-01-24T09:19:22.021Z');
expect(data[0].fields[1].values.get(0)).toEqual(streamResult[0].values[0][1]); expect(data[0].fields[1].values.get(0)).toEqual(streamResult[0].values[0][1]);
expect(data[0].fields[2].values.get(0)).toEqual('2b431b8a98b80b3b2c2f4cd2444ae6cb'); expect(data[0].fields[2].values.get(0)).toEqual('2b431b8a98b80b3b2c2f4cd2444ae6cb');
......
...@@ -79,6 +79,7 @@ describe('PromExploreQueryEditor', () => { ...@@ -79,6 +79,7 @@ describe('PromExploreQueryEditor', () => {
}); });
it('should render PromQueryField with ExtraFieldElement', async () => { it('should render PromQueryField with ExtraFieldElement', async () => {
// @ts-ignore strict null errpr TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
await act(async () => { await act(async () => {
const wrapper = setup(mount); const wrapper = setup(mount);
expect(wrapper.find(PromExploreExtraField).length).toBe(1); expect(wrapper.find(PromExploreExtraField).length).toBe(1);
......
import { getValueFromEventItem, promSettingsValidationEvents } from './PromSettings'; import { getValueFromEventItem, promSettingsValidationEvents } from './PromSettings';
import { EventsWithValidation } from '@grafana/ui'; import { EventsWithValidation } from '@grafana/ui';
import { SyntheticEvent } from 'react';
import { SelectableValue } from '@grafana/data';
describe('PromSettings', () => { describe('PromSettings', () => {
describe('getValueFromEventItem', () => { describe('getValueFromEventItem', () => {
describe('when called with undefined', () => { describe('when called with undefined', () => {
it('then it should return empty string', () => { it('then it should return empty string', () => {
const result = getValueFromEventItem(undefined); const result = getValueFromEventItem(
(undefined as unknown) as SyntheticEvent<HTMLInputElement> | SelectableValue<string>
);
expect(result).toEqual(''); expect(result).toEqual('');
}); });
}); });
......
...@@ -17,7 +17,7 @@ describe('Prometheus Result Transformer', () => { ...@@ -17,7 +17,7 @@ describe('Prometheus Result Transformer', () => {
status: 'success', status: 'success',
data: { data: {
resultType: '', resultType: '',
result: null as DataQueryResponseData[], result: (null as unknown) as DataQueryResponseData[],
}, },
}; };
const series = ctx.resultTransformer.transform({ data: response }, {}); const series = ctx.resultTransformer.transform({ data: response }, {});
...@@ -28,7 +28,7 @@ describe('Prometheus Result Transformer', () => { ...@@ -28,7 +28,7 @@ describe('Prometheus Result Transformer', () => {
status: 'success', status: 'success',
data: { data: {
resultType: '', resultType: '',
result: null as DataQueryResponseData[], result: (null as unknown) as DataQueryResponseData[],
}, },
}; };
const table = ctx.resultTransformer.transform({ data: response }, { format: 'table' }); const table = ctx.resultTransformer.transform({ data: response }, { format: 'table' });
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
echo -e "Collecting code stats (typescript errors & more)" echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=958 ERROR_COUNT_LIMIT=824
DIRECTIVES_LIMIT=172 DIRECTIVES_LIMIT=172
CONTROLLERS_LIMIT=139 CONTROLLERS_LIMIT=139
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment