processTimeSeries.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { toTableData } from './processTimeSeries';
  2. describe('toTableData', () => {
  3. it('converts timeseries to table skipping nulls', () => {
  4. const input1 = {
  5. target: 'Field Name',
  6. datapoints: [[100, 1], [200, 2]],
  7. };
  8. const input2 = {
  9. // without target
  10. target: '',
  11. datapoints: [[100, 1], [200, 2]],
  12. };
  13. const data = toTableData([null, input1, input2, null, null]);
  14. expect(data.length).toBe(2);
  15. expect(data[0].columns[0].text).toBe(input1.target);
  16. expect(data[0].rows).toBe(input1.datapoints);
  17. // Default name
  18. expect(data[1].columns[0].text).toEqual('Value');
  19. });
  20. it('keeps tableData unchanged', () => {
  21. const input = {
  22. columns: [{ text: 'A' }, { text: 'B' }, { text: 'C' }],
  23. rows: [[100, 'A', 1], [200, 'B', 2], [300, 'C', 3]],
  24. };
  25. const data = toTableData([null, input, null, null]);
  26. expect(data.length).toBe(1);
  27. expect(data[0]).toBe(input);
  28. });
  29. it('supports null values OK', () => {
  30. expect(toTableData([null, null, null, null])).toEqual([]);
  31. expect(toTableData(undefined)).toEqual([]);
  32. expect(toTableData((null as unknown) as any[])).toEqual([]);
  33. expect(toTableData([])).toEqual([]);
  34. });
  35. });