InputDatasource.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import InputDatasource, { describeDataFrame } from './InputDatasource';
  2. import { InputQuery, InputOptions } from './types';
  3. import { readCSV, DataSourceInstanceSettings, PluginMeta } from '@grafana/ui';
  4. import { getQueryOptions } from 'test/helpers/getQueryOptions';
  5. describe('InputDatasource', () => {
  6. const data = readCSV('a,b,c\n1,2,3\n4,5,6');
  7. const instanceSettings: DataSourceInstanceSettings<InputOptions> = {
  8. id: 1,
  9. type: 'x',
  10. name: 'xxx',
  11. meta: {} as PluginMeta,
  12. jsonData: {
  13. data,
  14. },
  15. };
  16. describe('when querying', () => {
  17. test('should return the saved data with a query', () => {
  18. const ds = new InputDatasource(instanceSettings);
  19. const options = getQueryOptions<InputQuery>({
  20. targets: [{ refId: 'Z' }],
  21. });
  22. return ds.query(options).then(rsp => {
  23. expect(rsp.data.length).toBe(1);
  24. const series = rsp.data[0];
  25. expect(series.refId).toBe('Z');
  26. expect(series.rows).toEqual(data[0].rows);
  27. });
  28. });
  29. });
  30. test('DataFrame descriptions', () => {
  31. expect(describeDataFrame([])).toEqual('');
  32. expect(describeDataFrame(null)).toEqual('');
  33. expect(
  34. describeDataFrame([
  35. {
  36. name: 'x',
  37. fields: [{ name: 'a' }],
  38. rows: [],
  39. },
  40. ])
  41. ).toEqual('1 Fields, 0 Rows');
  42. });
  43. });