Files
grafana/public/app/plugins/datasource/input/InputDatasource.test.ts
Ryan McKinley c777301535 DataFrame: split DataFrameHelper into MutableDataFrame and FieldCache (#18795)
* add appending utility

* add appending utility

* update comment

* rename to mutable

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* turn DataFrameHelper into FieldCache

* guess time from name

* graph the numbers

* return the timeField, not just the index

* just warn on duplicate field names

* only use a parser if the input is a string

* append init all fields to the same length

* typo

* only parse string if value is a string

* DataFrame: test fixes

* Switch to null for missing values

* Fixed tests
2019-09-01 14:44:22 +02:00

49 lines
1.4 KiB
TypeScript

import InputDatasource, { describeDataFrame } from './InputDatasource';
import { InputQuery, InputOptions } from './types';
import { readCSV, DataFrame, MutableDataFrame } from '@grafana/data';
import { DataSourceInstanceSettings, PluginMeta } from '@grafana/ui';
import { getQueryOptions } from 'test/helpers/getQueryOptions';
describe('InputDatasource', () => {
const data = readCSV('a,b,c\n1,2,3\n4,5,6');
const instanceSettings: DataSourceInstanceSettings<InputOptions> = {
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);
const series: DataFrame = rsp.data[0];
expect(series.refId).toBe('Z');
expect(series.fields[0].values).toEqual(data[0].fields[0].values);
});
});
});
test('DataFrame descriptions', () => {
expect(describeDataFrame([])).toEqual('');
expect(describeDataFrame(null)).toEqual('');
expect(
describeDataFrame([
new MutableDataFrame({
name: 'x',
fields: [{ name: 'a' }],
}),
])
).toEqual('1 Fields, 0 Rows');
});
});