The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/prometheus/querybuilder/state.test.ts

34 lines
1.1 KiB

import { CoreApp } from '@grafana/data';
import { QueryEditorMode } from './shared/types';
import { changeEditorMode, getQueryWithDefaults } from './state';
describe('getQueryWithDefaults(', () => {
it('should set defaults', () => {
expect(getQueryWithDefaults({ refId: 'A' } as any, CoreApp.Dashboard)).toEqual({
editorMode: 'code',
expr: '',
legendFormat: '__auto',
range: true,
refId: 'A',
});
});
it('should set both range and instant to true when in Explore', () => {
expect(getQueryWithDefaults({ refId: 'A' } as any, CoreApp.Explore)).toEqual({
editorMode: 'code',
expr: '',
legendFormat: '__auto',
range: true,
instant: true,
refId: 'A',
});
});
it('Changing editor mode with blank query should change default', () => {
changeEditorMode({ refId: 'A', expr: '' }, QueryEditorMode.Code, (query) => {
expect(query.editorMode).toBe(QueryEditorMode.Code);
});
expect(getQueryWithDefaults({ refId: 'A' } as any, CoreApp.Dashboard).editorMode).toEqual(QueryEditorMode.Code);
});
});