mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 20:37:05 +08:00

* feat(loki-query-editor): create base editor component * feat(loki-query-editor): update editor to use loki query type * feat(loki-query-editor): add custom variable support to datasource * feat(loki-query-editor): prevent errors when no label is present * Add unit test for LokiMetricFindQuery * Update datasource test * Add component test * Add variable query migration support * feat(loki-query-editor): add migration support for older-format variables * Fix enum capitalization for consistency * Move attribute to the top of the class * Remove unnecessary from() * Update capitalization of new enum * Fix enum capitalization in component * feat(loki-query-editor): replace unnecessary class with class method
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { LokiVariableQuery, LokiVariableQueryType } from '../types';
|
|
|
|
import { migrateVariableQuery } from './variableQueryMigrations';
|
|
|
|
describe('Loki migrateVariableQuery()', () => {
|
|
it('Does not migrate LokiVariableQuery instances', () => {
|
|
const query: LokiVariableQuery = {
|
|
refId: 'test',
|
|
type: LokiVariableQueryType.LabelValues,
|
|
label: 'label',
|
|
stream: 'stream',
|
|
};
|
|
|
|
expect(migrateVariableQuery(query)).toBe(query);
|
|
expect(migrateVariableQuery(query)).toStrictEqual(query);
|
|
});
|
|
|
|
it('Migrates label_names() queries', () => {
|
|
const query = 'label_names()';
|
|
|
|
expect(migrateVariableQuery(query)).toStrictEqual({
|
|
refId: 'LokiVariableQueryEditor-VariableQuery',
|
|
type: LokiVariableQueryType.LabelNames,
|
|
});
|
|
});
|
|
|
|
it('Migrates label_values(label) queries', () => {
|
|
const query = 'label_values(label)';
|
|
|
|
expect(migrateVariableQuery(query)).toStrictEqual({
|
|
refId: 'LokiVariableQueryEditor-VariableQuery',
|
|
type: LokiVariableQueryType.LabelValues,
|
|
label: 'label',
|
|
stream: undefined,
|
|
});
|
|
});
|
|
|
|
it('Migrates label_values(log stream selector, label) queries', () => {
|
|
const query = 'label_values(log stream selector, label)';
|
|
|
|
expect(migrateVariableQuery(query)).toStrictEqual({
|
|
refId: 'LokiVariableQueryEditor-VariableQuery',
|
|
type: LokiVariableQueryType.LabelValues,
|
|
label: 'label',
|
|
stream: 'log stream selector',
|
|
});
|
|
});
|
|
});
|