123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import { EventBusSrv, FieldType, getDefaultTimeRange, LoadingState, toDataFrame } from '@grafana/data';
- import { getStandardEditorContext } from './getVisualizationOptions';
- describe('getStandardEditorContext', () => {
- it('defaults the series data to an empty array', () => {
- const editorContext = getStandardEditorContext({
- data: undefined,
- replaceVariables: jest.fn(),
- options: {},
- eventBus: new EventBusSrv(),
- instanceState: {},
- });
- expect(editorContext.data).toEqual([]);
- });
- it('returns suggestions for empty data', () => {
- const editorContext = getStandardEditorContext({
- data: undefined,
- replaceVariables: jest.fn(),
- options: {},
- eventBus: new EventBusSrv(),
- instanceState: {},
- });
- expect(editorContext.getSuggestions).toBeDefined();
- expect(editorContext.getSuggestions?.()).toEqual([
- {
- documentation: 'Name of the series',
- label: 'Name',
- origin: 'series',
- value: '__series.name',
- },
- {
- documentation: 'Field name of the clicked datapoint (in ms epoch)',
- label: 'Name',
- origin: 'field',
- value: '__field.name',
- },
- {
- documentation: 'Adds current variables',
- label: 'All variables',
- origin: 'template',
- value: '__all_variables',
- },
- {
- documentation: 'Adds current time range',
- label: 'Time range',
- origin: 'built-in',
- value: '__url_time_range',
- },
- {
- documentation: "Adds current time range's from value",
- label: 'Time range: from',
- origin: 'built-in',
- value: '__from',
- },
- {
- documentation: "Adds current time range's to value",
- label: 'Time range: to',
- origin: 'built-in',
- value: '__to',
- },
- ]);
- });
- it('returns suggestions for non-empty data', () => {
- const series = [
- toDataFrame({
- fields: [
- { name: 'time', type: FieldType.time },
- { name: 'score', type: FieldType.number },
- ],
- }),
- ];
- const panelData = {
- series,
- timeRange: getDefaultTimeRange(),
- state: LoadingState.Done,
- };
- const editorContext = getStandardEditorContext({
- data: panelData,
- replaceVariables: jest.fn(),
- options: {},
- eventBus: new EventBusSrv(),
- instanceState: {},
- });
- expect(editorContext.getSuggestions).toBeDefined();
- expect(editorContext.getSuggestions?.()).toEqual([
- {
- documentation: 'Name of the series',
- label: 'Name',
- origin: 'series',
- value: '__series.name',
- },
- {
- documentation: 'Field name of the clicked datapoint (in ms epoch)',
- label: 'Name',
- origin: 'field',
- value: '__field.name',
- },
- {
- documentation: 'Formatted value for time on the same row',
- label: 'time',
- origin: 'fields',
- value: '__data.fields.time',
- },
- {
- documentation: 'Formatted value for score on the same row',
- label: 'score',
- origin: 'fields',
- value: '__data.fields.score',
- },
- {
- documentation: 'Enter the field order',
- label: 'Select by index',
- origin: 'fields',
- value: '__data.fields[0]',
- },
- {
- documentation: 'the numeric field value',
- label: 'Show numeric value',
- origin: 'fields',
- value: '__data.fields.score.numeric',
- },
- {
- documentation: 'the text value',
- label: 'Show text value',
- origin: 'fields',
- value: '__data.fields.score.text',
- },
- {
- documentation: 'Adds current variables',
- label: 'All variables',
- origin: 'template',
- value: '__all_variables',
- },
- {
- documentation: 'Adds current time range',
- label: 'Time range',
- origin: 'built-in',
- value: '__url_time_range',
- },
- {
- documentation: "Adds current time range's from value",
- label: 'Time range: from',
- origin: 'built-in',
- value: '__from',
- },
- {
- documentation: "Adds current time range's to value",
- label: 'Time range: to',
- origin: 'built-in',
- value: '__to',
- },
- ]);
- });
- });
|