data_processor.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { DataProcessor } from '../data_processor';
  2. import { getProcessedDataFrames } from 'app/features/dashboard/state/PanelQueryState';
  3. describe('Graph DataProcessor', () => {
  4. const panel: any = {
  5. xaxis: { mode: 'series' },
  6. aliasColors: {},
  7. };
  8. const processor = new DataProcessor(panel);
  9. describe('getTimeSeries from LegacyResponseData', () => {
  10. // Try each type of data
  11. const dataList = getProcessedDataFrames([
  12. {
  13. alias: 'First (time_series)',
  14. datapoints: [[1, 1001], [2, 1002], [3, 1003]],
  15. unit: 'watt',
  16. },
  17. {
  18. name: 'table_data',
  19. columns: [
  20. { text: 'time' },
  21. { text: 'v1', unit: 'ohm' },
  22. { text: 'v2' }, // no unit
  23. { text: 'string' }, // skipped
  24. ],
  25. rows: [
  26. [1001, 0.1, 1.1, 'a'], // a
  27. [1002, 0.2, 2.2, 'b'], // b
  28. [1003, 0.3, 3.3, 'c'], // c
  29. ],
  30. },
  31. {
  32. name: 'series',
  33. fields: [
  34. { name: 'v1', values: [0.1, 0.2, 0.3] }, // first
  35. { name: 'v2', values: [1.1, 2.2, 3.3] }, // second
  36. { name: 'string', values: ['a', 'b', 'c'] }, // skip
  37. { name: 'time', values: [1001, 1002, 1003] }, // Time is last column
  38. ],
  39. },
  40. ]);
  41. it('Should return a new series for each field', () => {
  42. panel.xaxis.mode = 'series';
  43. const series = processor.getSeriesList({ dataList });
  44. expect(series.length).toEqual(5);
  45. expect(series).toMatchSnapshot();
  46. });
  47. it('Should return single histogram', () => {
  48. panel.xaxis.mode = 'histogram';
  49. const series = processor.getSeriesList({ dataList });
  50. expect(series.length).toEqual(1);
  51. expect(series).toMatchSnapshot();
  52. });
  53. });
  54. });