query.test.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { DataQuery } from '@grafana/data';
  2. import { getNextRefIdChar } from './query';
  3. function dataQueryHelper(ids: string[]): DataQuery[] {
  4. return ids.map((letter) => {
  5. return { refId: letter };
  6. });
  7. }
  8. const singleDataQuery: DataQuery[] = dataQueryHelper('ABCDE'.split(''));
  9. const outOfOrderDataQuery: DataQuery[] = dataQueryHelper('ABD'.split(''));
  10. const singleExtendedDataQuery: DataQuery[] = dataQueryHelper('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
  11. describe('Get next refId char', () => {
  12. it('should return next char', () => {
  13. expect(getNextRefIdChar(singleDataQuery)).toEqual('F');
  14. });
  15. it('should get first char', () => {
  16. expect(getNextRefIdChar([])).toEqual('A');
  17. });
  18. it('should get the first avaliable character if a query has been deleted out of order', () => {
  19. expect(getNextRefIdChar(outOfOrderDataQuery)).toEqual('C');
  20. });
  21. it('should append a new char and start from AA when Z is reached', () => {
  22. expect(getNextRefIdChar(singleExtendedDataQuery)).toEqual('AA');
  23. });
  24. });