grafana/public/app/features/variables/textbox/adapter.test.ts
sam boyer 44956aea66
Incremental improvements to dashboard schema (#48977)
* Change default of style to dark

* Separate cursor into standalone def

* Docs on timepicker and templating fields

Also add what appear to be timepicker-related fields

* Separate out AnnotationQuery definition

* Add memberNames for DashboardCursorSync

* Add sketch of VariableModel for templating field

Also changes label field from frontend from null to optional.

* Use constraints to enforce non-empty panel type

Negation (!="")  was breaking openapi exporter

* Add types and fields for links

* Remove panelVersion fields

These weren't right anyway, and they revealed a bug in the CUE openapi
generator

* Remove null label value from test

* Narrow type and set bounds on month field

* Adapt Go dashboard schema to lineage changes
2022-05-17 12:11:09 +01:00

86 lines
2.7 KiB
TypeScript

import { variableAdapters } from '../adapters';
import { textboxBuilder } from '../shared/testing/builders';
import { VariableHide } from '../types';
import { createTextBoxVariableAdapter } from './adapter';
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')
.withRootStateKey('key')
.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',
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')
.withRootStateKey('key')
.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',
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' });
});
});
});
});