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/features/variables/textbox/adapter.test.ts

84 lines
2.7 KiB

import { variableAdapters } from '../adapters';
import { createTextBoxVariableAdapter } from './adapter';
import { textboxBuilder } from '../shared/testing/builders';
import { VariableHide } from '../types';
variableAdapters.setInit(() => [createTextBoxVariableAdapter()]);
describe('createTextBoxVariableAdapter', () => {
describe('getSaveModel', () => {
describe('when called and query differs from the original query and not saving current as default', () => {
it('then the model should be correct', () => {
const text = textboxBuilder()
.withId('text')
.withName('text')
.withQuery('query')
.withOriginalQuery('original')
.withCurrent('query')
.withOptions('query')
.build();
const adapter = variableAdapters.get('textbox');
const result = adapter.getSaveModel(text, false);
expect(result).toEqual({
name: 'text',
query: 'original',
current: { selected: false, text: 'original', value: 'original' },
options: [{ selected: false, text: 'original', value: 'original' }],
type: 'textbox',
label: null,
hide: VariableHide.dontHide,
skipUrlSync: false,
error: null,
description: null,
});
});
});
describe('when called and query differs from the original query and saving current as default', () => {
it('then the model should be correct', () => {
const text = textboxBuilder()
.withId('text')
.withName('text')
.withQuery('query')
.withOriginalQuery('original')
.withCurrent('query')
.withOptions('query')
.build();
const adapter = variableAdapters.get('textbox');
const result = adapter.getSaveModel(text, true);
expect(result).toEqual({
name: 'text',
query: 'query',
current: { selected: true, text: 'query', value: 'query' },
options: [{ selected: false, text: 'query', value: 'query' }],
type: 'textbox',
label: null,
hide: VariableHide.dontHide,
skipUrlSync: false,
error: null,
description: null,
});
});
});
});
describe('beforeAdding', () => {
describe('when called', () => {
it('then originalQuery should be same added', () => {
const model = { name: 'text', query: 'a query' };
const adapter = variableAdapters.get('textbox');
const result = adapter.beforeAdding!(model);
expect(result).toEqual({ name: 'text', query: 'a query', originalQuery: 'a query' });
});
});
});
});