mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: fix type errors in tests (#63270)
* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
This commit is contained in:
@@ -60,7 +60,7 @@ describe('Apending DataFrame', () => {
|
||||
|
||||
// Make sure length survives a spread operator
|
||||
const keys = Object.keys(frame);
|
||||
const copy = { ...frame } as any;
|
||||
const copy = { ...frame } as MutableDataFrame;
|
||||
expect(keys).toContain('length');
|
||||
expect(copy.length).toEqual(frame.length);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FieldType } from '../types/dataFrame';
|
||||
import { DataFrame, FieldType } from '../types/dataFrame';
|
||||
|
||||
import { compareDataFrameStructures, compareArrayValues } from './frameComparisons';
|
||||
import { toDataFrame } from './processDataFrame';
|
||||
@@ -32,12 +32,12 @@ describe('test comparisons', () => {
|
||||
expect(compareDataFrameStructures(frameA, frameA)).toBeTruthy();
|
||||
expect(compareDataFrameStructures(frameA, { ...frameA })).toBeTruthy();
|
||||
expect(compareDataFrameStructures(frameA, frameB)).toBeFalsy();
|
||||
expect(compareDataFrameStructures(frameA, null as any)).toBeFalsy();
|
||||
expect(compareDataFrameStructures(undefined as any, frameA)).toBeFalsy();
|
||||
expect(compareDataFrameStructures(frameA, null as unknown as DataFrame)).toBeFalsy();
|
||||
expect(compareDataFrameStructures(undefined as unknown as DataFrame, frameA)).toBeFalsy();
|
||||
|
||||
expect(compareArrayValues([frameA], [frameA], compareDataFrameStructures)).toBeTruthy();
|
||||
expect(compareArrayValues([frameA], null as any, compareDataFrameStructures)).toBeFalsy();
|
||||
expect(compareArrayValues(null as any, [frameA], compareDataFrameStructures)).toBeFalsy();
|
||||
expect(compareArrayValues([frameA], null as unknown as DataFrame[], compareDataFrameStructures)).toBeFalsy();
|
||||
expect(compareArrayValues(null as unknown as DataFrame[], [frameA], compareDataFrameStructures)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('name change should be a structure change', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { systemDateFormats } from './formats';
|
||||
import { systemDateFormats, SystemDateFormatsState } from './formats';
|
||||
import { dateTimeParse } from './parser';
|
||||
|
||||
describe('dateTimeParse', () => {
|
||||
@@ -10,7 +10,7 @@ describe('dateTimeParse', () => {
|
||||
it('should be able to parse using default format', () => {
|
||||
systemDateFormats.update({
|
||||
fullDate: 'MMMM D, YYYY, h:mm:ss a',
|
||||
interval: {} as any,
|
||||
interval: {} as SystemDateFormatsState['interval'],
|
||||
useBrowserLocale: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('EventBus', () => {
|
||||
describe('Legacy emitter behavior', () => {
|
||||
it('Supports legacy events', () => {
|
||||
const bus = new EventBusSrv();
|
||||
const events: any = [];
|
||||
const events: LegacyEventPayload[] = [];
|
||||
const handler = (event: LegacyEventPayload) => {
|
||||
events.push(event);
|
||||
};
|
||||
@@ -88,8 +88,8 @@ describe('EventBus', () => {
|
||||
|
||||
it('Interoperability with legacy events', () => {
|
||||
const bus = new EventBusSrv();
|
||||
const legacyEvents: any = [];
|
||||
const newEvents: any = [];
|
||||
const legacyEvents: LegacyEventPayload[] = [];
|
||||
const newEvents: AlertSuccessEvent[] = [];
|
||||
|
||||
bus.on(legacyEvent, (event) => {
|
||||
legacyEvents.push(event);
|
||||
|
||||
@@ -17,7 +17,7 @@ function getDisplayProcessorFromConfig(config: FieldConfig, fieldType: FieldType
|
||||
});
|
||||
}
|
||||
|
||||
function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) {
|
||||
function assertSame(input: unknown, processors: DisplayProcessor[], match: DisplayValue) {
|
||||
processors.forEach((processor) => {
|
||||
const value = processor(input);
|
||||
for (const key of Object.keys(match)) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { merge } from 'lodash';
|
||||
import { toDataFrame } from '../dataframe/processDataFrame';
|
||||
import { createTheme } from '../themes';
|
||||
import { ReducerID } from '../transformations/fieldReducer';
|
||||
import { MappingType, SpecialValueMatch, ValueMapping } from '../types';
|
||||
import { FieldConfigPropertyItem, MappingType, SpecialValueMatch, ValueMapping } from '../types';
|
||||
|
||||
import { getDisplayProcessor } from './displayProcessor';
|
||||
import { getFieldDisplayValues, GetFieldDisplayValuesOptions } from './fieldDisplay';
|
||||
@@ -14,11 +14,15 @@ describe('FieldDisplay', () => {
|
||||
// Since FieldConfigEditors belong to grafana-ui we need to mock those here
|
||||
// as grafana-ui code cannot be imported in grafana-data.
|
||||
// TODO: figure out a way to share standard editors between data/ui tests
|
||||
const mappings = {
|
||||
const mappings: FieldConfigPropertyItem = {
|
||||
id: 'mappings', // Match field properties
|
||||
process: (value: any) => value,
|
||||
process: (value) => value,
|
||||
shouldApply: () => true,
|
||||
} as any;
|
||||
override: jest.fn(),
|
||||
editor: jest.fn(),
|
||||
name: 'Value mappings',
|
||||
path: 'mappings',
|
||||
};
|
||||
|
||||
standardFieldConfigEditorRegistry.setInit(() => {
|
||||
return [mappings];
|
||||
|
||||
@@ -31,36 +31,48 @@ import {
|
||||
} from './fieldOverrides';
|
||||
import { getFieldDisplayName } from './fieldState';
|
||||
|
||||
const property1: any = {
|
||||
const property1: FieldConfigPropertyItem = {
|
||||
id: 'custom.property1', // Match field properties
|
||||
path: 'property1', // Match field properties
|
||||
isCustom: true,
|
||||
process: (value: any) => value,
|
||||
process: (value) => value,
|
||||
shouldApply: () => true,
|
||||
override: jest.fn(),
|
||||
editor: jest.fn(),
|
||||
name: 'Property 1',
|
||||
};
|
||||
|
||||
const property2 = {
|
||||
const property2: FieldConfigPropertyItem = {
|
||||
id: 'custom.property2', // Match field properties
|
||||
path: 'property2', // Match field properties
|
||||
isCustom: true,
|
||||
process: (value: any) => value,
|
||||
process: (value) => value,
|
||||
shouldApply: () => true,
|
||||
override: jest.fn(),
|
||||
editor: jest.fn(),
|
||||
name: 'Property 2',
|
||||
};
|
||||
|
||||
const property3: any = {
|
||||
const property3: FieldConfigPropertyItem = {
|
||||
id: 'custom.property3.nested', // Match field properties
|
||||
path: 'property3.nested', // Match field properties
|
||||
isCustom: true,
|
||||
process: (value: any) => value,
|
||||
process: (value) => value,
|
||||
shouldApply: () => true,
|
||||
override: jest.fn(),
|
||||
editor: jest.fn(),
|
||||
name: 'Property 3',
|
||||
};
|
||||
|
||||
const shouldApplyFalse: any = {
|
||||
const shouldApplyFalse: FieldConfigPropertyItem = {
|
||||
id: 'custom.shouldApplyFalse', // Match field properties
|
||||
path: 'shouldApplyFalse', // Match field properties
|
||||
isCustom: true,
|
||||
process: (value: any) => value,
|
||||
process: (value) => value,
|
||||
shouldApply: () => false,
|
||||
override: jest.fn(),
|
||||
editor: jest.fn(),
|
||||
name: 'Should Apply False',
|
||||
};
|
||||
|
||||
export const customFieldRegistry: FieldConfigOptionsRegistry = new Registry<FieldConfigPropertyItem>(() => {
|
||||
@@ -68,9 +80,9 @@ export const customFieldRegistry: FieldConfigOptionsRegistry = new Registry<Fiel
|
||||
});
|
||||
|
||||
locationUtil.initialize({
|
||||
config: { appSubUrl: '/subUrl' } as any,
|
||||
getVariablesUrlParams: (() => {}) as any,
|
||||
getTimeRangeForUrl: (() => {}) as any,
|
||||
config: { appSubUrl: '/subUrl' } as GrafanaConfig,
|
||||
getVariablesUrlParams: jest.fn(),
|
||||
getTimeRangeForUrl: jest.fn(),
|
||||
});
|
||||
|
||||
describe('Global MinMax', () => {
|
||||
@@ -181,7 +193,7 @@ describe('applyFieldOverrides', () => {
|
||||
defaults: {},
|
||||
overrides: [],
|
||||
},
|
||||
replaceVariables: (value: any) => value,
|
||||
replaceVariables: (value) => value,
|
||||
theme: createTheme(),
|
||||
fieldConfigRegistry: new FieldConfigOptionsRegistry(),
|
||||
});
|
||||
@@ -300,7 +312,7 @@ describe('applyFieldOverrides', () => {
|
||||
});
|
||||
|
||||
it('getLinks should use applied field config', () => {
|
||||
const replaceVariablesCalls: any[] = [];
|
||||
const replaceVariablesCalls: ScopedVars[] = [];
|
||||
|
||||
const data = applyFieldOverrides({
|
||||
data: [f0], // the frame
|
||||
@@ -375,8 +387,8 @@ describe('setFieldConfigDefaults', () => {
|
||||
};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
@@ -410,8 +422,8 @@ describe('setFieldConfigDefaults', () => {
|
||||
};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
@@ -444,8 +456,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
@@ -467,8 +479,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
@@ -488,8 +500,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
@@ -513,8 +525,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
@@ -539,8 +551,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
@@ -553,8 +565,8 @@ describe('setDynamicConfigValue', () => {
|
||||
},
|
||||
{
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
data: [] as any,
|
||||
field: { type: FieldType.number } as any,
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -38,12 +38,12 @@ describe('getScaleCalculator', () => {
|
||||
|
||||
const theme = createTheme();
|
||||
const calc = getScaleCalculator(field, theme);
|
||||
expect(calc(true as any)).toEqual({
|
||||
expect(calc(true as unknown as number)).toEqual({
|
||||
percent: 1,
|
||||
color: theme.visualization.getColorByName('green'),
|
||||
threshold: undefined,
|
||||
});
|
||||
expect(calc(false as any)).toEqual({
|
||||
expect(calc(false as unknown as number)).toEqual({
|
||||
percent: 0,
|
||||
color: theme.visualization.getColorByName('red'),
|
||||
threshold: undefined,
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import React from 'react';
|
||||
|
||||
import { PanelOptionsEditorBuilder } from '..';
|
||||
import { identityOverrideProcessor, standardEditorsRegistry, standardFieldConfigEditorRegistry } from '../field';
|
||||
import { FieldConfigProperty } from '../types';
|
||||
import {
|
||||
identityOverrideProcessor,
|
||||
standardEditorsRegistry,
|
||||
StandardEditorsRegistryItem,
|
||||
standardFieldConfigEditorRegistry,
|
||||
} from '../field';
|
||||
import { FieldConfigProperty, FieldConfigPropertyItem } from '../types';
|
||||
|
||||
import { PanelPlugin } from './PanelPlugin';
|
||||
|
||||
@@ -19,14 +24,14 @@ describe('PanelPlugin', () => {
|
||||
id: FieldConfigProperty.Max,
|
||||
path: 'max',
|
||||
},
|
||||
] as any;
|
||||
] as FieldConfigPropertyItem[];
|
||||
});
|
||||
standardEditorsRegistry.setInit(() => {
|
||||
return [
|
||||
{
|
||||
id: 'number',
|
||||
},
|
||||
] as any;
|
||||
] as StandardEditorsRegistryItem[];
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,7 +207,7 @@ describe('PanelPlugin', () => {
|
||||
name: 'Option editor',
|
||||
description: 'Option editor description',
|
||||
defaultValue: 10,
|
||||
} as any);
|
||||
} as FieldConfigPropertyItem);
|
||||
},
|
||||
});
|
||||
expect(() => panel.fieldConfigRegistry).toThrowErrorMatchingInlineSnapshot(
|
||||
|
||||
@@ -398,12 +398,12 @@ describe('restoreCustomOverrideRules', () => {
|
||||
});
|
||||
|
||||
interface ScenarioOptions {
|
||||
defaults?: FieldConfig<any>;
|
||||
defaults?: FieldConfig;
|
||||
overrides?: ConfigOverrideRule[];
|
||||
disabledStandardOptions?: FieldConfigProperty[];
|
||||
standardOptions?: Partial<Record<FieldConfigProperty, StandardOptionConfig>>;
|
||||
plugin?: PanelPlugin;
|
||||
options?: any;
|
||||
options?: Record<string, unknown>;
|
||||
isAfterPluginChange?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -455,7 +455,7 @@ describe('Labels as Columns', () => {
|
||||
});
|
||||
|
||||
function toSimpleObject(frame: DataFrame) {
|
||||
const obj: any = {};
|
||||
const obj: Record<string, unknown> = {};
|
||||
for (const field of frame.fields) {
|
||||
obj[field.name] = field.values.toArray();
|
||||
}
|
||||
|
||||
@@ -585,18 +585,18 @@ describe('Merge multiple to single', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const createField = (name: string, type: FieldType, values: any[], config = {}, display?: DisplayProcessor): Field => {
|
||||
const createField = (
|
||||
name: string,
|
||||
type: FieldType,
|
||||
values: unknown[],
|
||||
config = {},
|
||||
display?: DisplayProcessor
|
||||
): Field => {
|
||||
return { name, type, values: new ArrayVector(values), config, labels: undefined, display };
|
||||
};
|
||||
|
||||
const unwrap = (fields: Field[]): Field[] => {
|
||||
return fields.map((field) =>
|
||||
createField(
|
||||
field.name,
|
||||
field.type,
|
||||
field.values.toArray().map((value: any) => value),
|
||||
field.config,
|
||||
field.display
|
||||
)
|
||||
createField(field.name, field.type, field.values.toArray(), field.config, field.display)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -261,8 +261,8 @@ describe('Reducer Transformer', () => {
|
||||
expect(frames[0].length).toEqual(1);
|
||||
expect(frames[1].length).toEqual(1);
|
||||
|
||||
const view0 = new DataFrameView<any>(frames[0]);
|
||||
const view1 = new DataFrameView<any>(frames[1]);
|
||||
const view0 = new DataFrameView(frames[0]);
|
||||
const view1 = new DataFrameView(frames[1]);
|
||||
expect({ ...view0.get(0) }).toMatchInlineSnapshot(`
|
||||
{
|
||||
"temperature": 6,
|
||||
|
||||
@@ -245,17 +245,10 @@ describe('Series to rows', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const createField = (name: string, type: FieldType, values: any[], config = {}): Field => {
|
||||
const createField = (name: string, type: FieldType, values: unknown[], config = {}): Field => {
|
||||
return { name, type, values: new ArrayVector(values), config, labels: undefined };
|
||||
};
|
||||
|
||||
const unwrap = (fields: Field[]): Field[] => {
|
||||
return fields.map((field) =>
|
||||
createField(
|
||||
field.name,
|
||||
field.type,
|
||||
field.values.toArray().map((value: any) => value),
|
||||
field.config
|
||||
)
|
||||
);
|
||||
return fields.map((field) => createField(field.name, field.type, field.values.toArray(), field.config));
|
||||
};
|
||||
|
||||
@@ -135,12 +135,12 @@ describe('Format value with value mappings', () => {
|
||||
|
||||
it('should return match result for undefined value', () => {
|
||||
const value = undefined;
|
||||
expect(getValueMappingResult(testSet1, value as any)).toEqual({ text: 'it is null' });
|
||||
expect(getValueMappingResult(testSet1, value)).toEqual({ text: 'it is null' });
|
||||
});
|
||||
|
||||
it('should return match result for nan value', () => {
|
||||
const value = Number.NaN;
|
||||
expect(getValueMappingResult(testSet1, value as any)).toEqual({ text: 'it is nan' });
|
||||
expect(getValueMappingResult(testSet1, value)).toEqual({ text: 'it is nan' });
|
||||
});
|
||||
|
||||
it('should return range mapping that matches first', () => {
|
||||
|
||||
Reference in New Issue
Block a user