-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Templating: Fix error when response has data with empty array (#317)
- Loading branch information
1 parent
1796eff
commit 67b63ed
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { DataQueryResponse, DataSourceInstanceSettings, toDataFrame } from '@grafana/data'; | ||
import { GitHubVariableQuery } from 'types'; | ||
import { of } from 'rxjs'; | ||
import { GithubDataSource } from 'DataSource'; | ||
|
||
describe('DataSource', () => { | ||
describe('metricFindQuery', () => { | ||
it('should return empty array if data in response is empty array', async () => { | ||
const ds = new GithubDataSource({} as DataSourceInstanceSettings); | ||
const query = {} as GitHubVariableQuery; | ||
|
||
jest.spyOn(ds, 'query').mockReturnValue(of({ data: [] })); | ||
const res = await ds.metricFindQuery(query, {}); | ||
expect(res).toEqual([]); | ||
}); | ||
|
||
it('should return empty array if no data in response', async () => { | ||
const ds = new GithubDataSource({} as DataSourceInstanceSettings); | ||
const query = {} as GitHubVariableQuery; | ||
|
||
jest.spyOn(ds, 'query').mockReturnValue(of({} as DataQueryResponse)); | ||
const res = await ds.metricFindQuery(query, {}); | ||
expect(res).toEqual([]); | ||
}); | ||
|
||
it('should return array with values if response has data', async () => { | ||
const ds = new GithubDataSource({} as DataSourceInstanceSettings); | ||
const query = { key: 'test', field: 'test' } as GitHubVariableQuery; | ||
|
||
jest.spyOn(ds, 'query').mockReturnValue( | ||
of({ | ||
data: [ | ||
toDataFrame({ | ||
fields: [{ name: 'test', values: ['value1', 'value2'] }], | ||
}), | ||
], | ||
} as DataQueryResponse) | ||
); | ||
const res = await ds.metricFindQuery(query, {}); | ||
expect(res).toEqual([ | ||
{ value: 'value1', text: 'value1' }, | ||
{ value: 'value2', text: 'value2' }, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters