grafana/public/app/core/services/bridge_srv.test.ts
Torkel Ödegaard 8f78b0e7bc
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors

* Added new limit

* Fixed ts issue

* fixed tests

* trying to fix type inference

* Fixing more ts errors

* Revert tsconfig option

* Fix

* Fixed code

* More fixes

* fix tests

* Updated snapshot

* Chore: More ts strict null fixes

* More fixes in some really messed up azure config components

* More fixes, current count: 441

* 419

* More fixes

* Fixed invalid initial state in explore

* Fixing tests

* Fixed tests

* Explore fix

* More fixes

* Progress

* Sub 300

* Now at 218

* Progress

* Update

* Progress

* Updated tests

* at 159

* fixed tests

* Progress

* YAy blow 100! at 94

* 10,9,8,7,6,5,4,3,2,1... lift off

* Fixed tests

* Fixed more type errors

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 12:46:59 +02:00

77 lines
2.0 KiB
TypeScript

import { UrlQueryMap } from '@grafana/data';
import { findTemplateVarChanges } from './bridge_srv';
describe('when checking template variables', () => {
it('detect adding/removing a variable', () => {
const a: UrlQueryMap = {};
const b: UrlQueryMap = {
'var-xyz': 'hello',
aaa: 'ignore me',
};
expect(findTemplateVarChanges(b, a)).toEqual({ 'var-xyz': 'hello' });
expect(findTemplateVarChanges(a, b)).toEqual({ 'var-xyz': '' });
});
it('then should ignore equal values', () => {
const a: UrlQueryMap = {
'var-xyz': 'hello',
bbb: 'ignore me',
};
const b: UrlQueryMap = {
'var-xyz': 'hello',
aaa: 'ignore me',
};
expect(findTemplateVarChanges(b, a)).toBeUndefined();
expect(findTemplateVarChanges(a, b)).toBeUndefined();
});
it('then should ignore equal values with empty values', () => {
const a: UrlQueryMap = {
'var-xyz': '',
bbb: 'ignore me',
};
const b: UrlQueryMap = {
'var-xyz': '',
aaa: 'ignore me',
};
expect(findTemplateVarChanges(b, a)).toBeUndefined();
expect(findTemplateVarChanges(a, b)).toBeUndefined();
});
it('then should ignore empty array values', () => {
const a: UrlQueryMap = {
'var-adhoc': [],
};
const b: UrlQueryMap = {};
expect(findTemplateVarChanges(b, a)).toBeUndefined();
expect(findTemplateVarChanges(a, b)).toBeUndefined();
});
it('Should handle array values with one value same as just value', () => {
const a: UrlQueryMap = {
'var-test': ['test'],
};
const b: UrlQueryMap = {
'var-test': 'test',
};
expect(findTemplateVarChanges(b, a)).toBeUndefined();
expect(findTemplateVarChanges(a, b)).toBeUndefined();
});
it('Should detect change in array value and return array with single value', () => {
const a: UrlQueryMap = {
'var-test': ['test'],
};
const b: UrlQueryMap = {
'var-test': 'asd',
};
expect(findTemplateVarChanges(a, b)!['var-test']).toEqual(['test']);
});
});