2019-07-01 12:00:29 -07:00
|
|
|
import InputDatasource, { describeDataFrame } from './InputDatasource';
|
2019-05-02 21:56:54 -07:00
|
|
|
import { InputQuery, InputOptions } from './types';
|
2019-09-01 05:44:22 -07:00
|
|
|
import { readCSV, DataFrame, MutableDataFrame } from '@grafana/data';
|
2019-07-05 23:05:53 -07:00
|
|
|
import { DataSourceInstanceSettings, PluginMeta } from '@grafana/ui';
|
2019-04-12 10:13:36 -07:00
|
|
|
import { getQueryOptions } from 'test/helpers/getQueryOptions';
|
|
|
|
|
|
|
|
|
|
describe('InputDatasource', () => {
|
|
|
|
|
const data = readCSV('a,b,c\n1,2,3\n4,5,6');
|
2019-05-02 21:56:54 -07:00
|
|
|
const instanceSettings: DataSourceInstanceSettings<InputOptions> = {
|
2019-04-12 10:13:36 -07:00
|
|
|
id: 1,
|
|
|
|
|
type: 'x',
|
|
|
|
|
name: 'xxx',
|
|
|
|
|
meta: {} as PluginMeta,
|
|
|
|
|
jsonData: {
|
|
|
|
|
data,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe('when querying', () => {
|
|
|
|
|
test('should return the saved data with a query', () => {
|
|
|
|
|
const ds = new InputDatasource(instanceSettings);
|
|
|
|
|
const options = getQueryOptions<InputQuery>({
|
|
|
|
|
targets: [{ refId: 'Z' }],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return ds.query(options).then(rsp => {
|
|
|
|
|
expect(rsp.data.length).toBe(1);
|
|
|
|
|
|
2019-08-15 09:18:51 -07:00
|
|
|
const series: DataFrame = rsp.data[0];
|
2019-04-12 10:13:36 -07:00
|
|
|
expect(series.refId).toBe('Z');
|
2019-08-15 09:18:51 -07:00
|
|
|
expect(series.fields[0].values).toEqual(data[0].fields[0].values);
|
2019-04-12 10:13:36 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-05-14 22:20:27 -07:00
|
|
|
|
2019-07-01 12:00:29 -07:00
|
|
|
test('DataFrame descriptions', () => {
|
|
|
|
|
expect(describeDataFrame([])).toEqual('');
|
|
|
|
|
expect(describeDataFrame(null)).toEqual('');
|
2019-05-14 22:20:27 -07:00
|
|
|
expect(
|
2019-07-01 12:00:29 -07:00
|
|
|
describeDataFrame([
|
2019-09-01 05:44:22 -07:00
|
|
|
new MutableDataFrame({
|
2019-05-14 22:20:27 -07:00
|
|
|
name: 'x',
|
|
|
|
|
fields: [{ name: 'a' }],
|
2019-08-15 09:18:51 -07:00
|
|
|
}),
|
2019-05-14 22:20:27 -07:00
|
|
|
])
|
|
|
|
|
).toEqual('1 Fields, 0 Rows');
|
|
|
|
|
});
|
2019-04-12 10:13:36 -07:00
|
|
|
});
|