zeroFillSeries.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import moment from 'moment';
  2. import {zeroFillSeries} from './zeroFillSeries';
  3. describe('zeroFillSeries', () => {
  4. test('Fills all missing entries with a zero', () => {
  5. const series = {
  6. seriesName: 'p50',
  7. data: [
  8. {
  9. name: '2023-03-21T00:00:00',
  10. value: 5,
  11. },
  12. {
  13. name: '2023-03-24T00:00:00',
  14. value: 4,
  15. },
  16. {
  17. name: '2023-03-25T00:00:00',
  18. value: 6,
  19. },
  20. ],
  21. };
  22. const newSeries = zeroFillSeries(series, moment.duration(1, 'day'));
  23. expect(newSeries.data).toEqual([
  24. {
  25. name: '2023-03-21T00:00:00',
  26. value: 5,
  27. },
  28. {
  29. name: '2023-03-22T00:00:00',
  30. value: 0,
  31. },
  32. {
  33. name: '2023-03-23T00:00:00',
  34. value: 0,
  35. },
  36. {
  37. name: '2023-03-24T00:00:00',
  38. value: 4,
  39. },
  40. {
  41. name: '2023-03-25T00:00:00',
  42. value: 6,
  43. },
  44. ]);
  45. });
  46. test('Fills all missing entries with a zero when given start and end timestamps', () => {
  47. const series = {
  48. seriesName: 'p50',
  49. data: [
  50. {
  51. name: '2023-03-21T00:00:00',
  52. value: 5,
  53. },
  54. {
  55. name: '2023-03-24T00:00:00',
  56. value: 4,
  57. },
  58. {
  59. name: '2023-03-25T00:00:00',
  60. value: 6,
  61. },
  62. ],
  63. };
  64. const newSeries = zeroFillSeries(
  65. series,
  66. moment.duration(12, 'hour'),
  67. moment('2023-03-19T00:00:00'),
  68. moment('2023-03-27T00:00:00')
  69. );
  70. expect(newSeries.data).toEqual([
  71. {
  72. name: '2023-03-19T00:00:00',
  73. value: 0,
  74. },
  75. {
  76. name: '2023-03-19T12:00:00',
  77. value: 0,
  78. },
  79. {
  80. name: '2023-03-20T00:00:00',
  81. value: 0,
  82. },
  83. {
  84. name: '2023-03-20T12:00:00',
  85. value: 0,
  86. },
  87. {
  88. name: '2023-03-21T00:00:00',
  89. value: 5,
  90. },
  91. {
  92. name: '2023-03-21T12:00:00',
  93. value: 0,
  94. },
  95. {
  96. name: '2023-03-22T00:00:00',
  97. value: 0,
  98. },
  99. {
  100. name: '2023-03-22T12:00:00',
  101. value: 0,
  102. },
  103. {
  104. name: '2023-03-23T00:00:00',
  105. value: 0,
  106. },
  107. {
  108. name: '2023-03-23T12:00:00',
  109. value: 0,
  110. },
  111. {
  112. name: '2023-03-24T00:00:00',
  113. value: 4,
  114. },
  115. {
  116. name: '2023-03-24T12:00:00',
  117. value: 0,
  118. },
  119. {
  120. name: '2023-03-25T00:00:00',
  121. value: 6,
  122. },
  123. {
  124. name: '2023-03-25T12:00:00',
  125. value: 0,
  126. },
  127. {
  128. name: '2023-03-26T00:00:00',
  129. value: 0,
  130. },
  131. {
  132. name: '2023-03-26T12:00:00',
  133. value: 0,
  134. },
  135. {
  136. name: '2023-03-27T00:00:00',
  137. value: 0,
  138. },
  139. ]);
  140. });
  141. });