-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
query.test.ts
52 lines (41 loc) · 1.82 KB
/
query.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { DataQuery } from '@grafana/data';
import { getNextRefIdChar, queryIsEmpty } from './query';
export interface TestQuery extends DataQuery {
name?: string;
}
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');
});
});
describe('queryIsEmpty', () => {
it('should return true if query only includes props that are defined in the DataQuery interface', () => {
const testQuery: DataQuery = { refId: 'A' };
expect(queryIsEmpty(testQuery)).toEqual(true);
});
it('should return true if query only includes props that are defined in the DataQuery interface and a label prop', () => {
const testQuery: DataQuery & { label: string } = { refId: 'A', label: '' };
expect(queryIsEmpty(testQuery)).toEqual(true);
});
it('should return false if query only includes props that are not defined in the DataQuery interface', () => {
const testQuery: TestQuery = { refId: 'A', name: 'test' };
expect(queryIsEmpty(testQuery)).toEqual(false);
});
});