processTimeSeries.test.ts 1.0 KB

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