data_processor.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { DataProcessor } from '../data_processor';
  2. import { getProcessedDataFrame } 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 = getProcessedDataFrame([
  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' }, // first
  35. { name: 'v2' }, // second
  36. { name: 'string' }, // skip
  37. { name: 'time' }, // Time is last column
  38. ],
  39. rows: [[0.1, 1.1, 'a', 1001], [0.2, 2.2, 'b', 1002], [0.3, 3.3, 'c', 1003]],
  40. },
  41. ]);
  42. it('Should return a new series for each field', () => {
  43. panel.xaxis.mode = 'series';
  44. const series = processor.getSeriesList({ dataList });
  45. expect(series.length).toEqual(5);
  46. expect(series).toMatchSnapshot();
  47. });
  48. it('Should return single histogram', () => {
  49. panel.xaxis.mode = 'histogram';
  50. const series = processor.getSeriesList({ dataList });
  51. expect(series.length).toEqual(1);
  52. expect(series).toMatchSnapshot();
  53. });
  54. });
  55. });