datasource.test.ts 972 B

12345678910111213141516171819202122232425262728293031323334
  1. import InputDatasource from './datasource';
  2. import { InputQuery } 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 = {
  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. });