grafana/public/app/core/utils/query.test.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

32 lines
1.0 KiB
TypeScript

import { DataQuery } from '@grafana/data';
import { getNextRefIdChar } from './query';
function dataQueryHelper(ids: string[]): DataQuery[] {
return ids.map((letter) => {
return { refId: letter };
});
}
const singleDataQuery: DataQuery[] = dataQueryHelper('ABCDE'.split(''));
const outOfOrderDataQuery: DataQuery[] = dataQueryHelper('ABD'.split(''));
const singleExtendedDataQuery: DataQuery[] = dataQueryHelper('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
describe('Get next refId char', () => {
it('should return next char', () => {
expect(getNextRefIdChar(singleDataQuery)).toEqual('F');
});
it('should get first char', () => {
expect(getNextRefIdChar([])).toEqual('A');
});
it('should get the first avaliable character if a query has been deleted out of order', () => {
expect(getNextRefIdChar(outOfOrderDataQuery)).toEqual('C');
});
it('should append a new char and start from AA when Z is reached', () => {
expect(getNextRefIdChar(singleExtendedDataQuery)).toEqual('AA');
});
});