mergeBuckets.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {MonitorBucketData} from 'sentry/views/monitors/components/overviewTimeline/types';
  2. import {CheckInStatus} from 'sentry/views/monitors/types';
  3. import {mergeBuckets} from './mergeBuckets';
  4. type StatusCounts = [ok: number, missed: number, timeout: number, error: number];
  5. function generateEnvMapping(name: string, counts: StatusCounts) {
  6. const [ok, missed, timeout, error] = counts;
  7. return {
  8. [name]: {ok, timeout, error, missed},
  9. };
  10. }
  11. function generateJobRun(envName: string, jobStatus: CheckInStatus) {
  12. const sortedStatuses = [
  13. CheckInStatus.OK,
  14. CheckInStatus.MISSED,
  15. CheckInStatus.TIMEOUT,
  16. CheckInStatus.ERROR,
  17. CheckInStatus.IN_PROGRESS,
  18. ];
  19. const counts: StatusCounts = [0, 0, 0, 0];
  20. counts[sortedStatuses.indexOf(jobStatus)] = 1;
  21. return generateEnvMapping(envName, counts);
  22. }
  23. describe('mergeBuckets', function () {
  24. it('does not generate ticks less than 3px width', function () {
  25. const bucketData: MonitorBucketData = [
  26. [1, generateJobRun('prod', CheckInStatus.OK)],
  27. [2, generateJobRun('prod', CheckInStatus.OK)],
  28. [3, generateJobRun('prod', CheckInStatus.OK)],
  29. [4, {}],
  30. [5, generateJobRun('prod', CheckInStatus.OK)],
  31. [6, generateJobRun('prod', CheckInStatus.OK)],
  32. [7, generateJobRun('prod', CheckInStatus.OK)],
  33. [8, generateJobRun('prod', CheckInStatus.OK)],
  34. ];
  35. const mergedData = mergeBuckets(bucketData);
  36. const expectedMerged = [
  37. {
  38. startTs: 1,
  39. endTs: 8,
  40. width: 8,
  41. roundedLeft: true,
  42. roundedRight: true,
  43. envMapping: generateEnvMapping('prod', [7, 0, 0, 0]),
  44. },
  45. ];
  46. expect(mergedData).toEqual(expectedMerged);
  47. });
  48. it('generates adjacent ticks without border radius', function () {
  49. const bucketData: MonitorBucketData = [
  50. [1, generateJobRun('prod', CheckInStatus.OK)],
  51. [2, generateJobRun('prod', CheckInStatus.OK)],
  52. [3, generateJobRun('prod', CheckInStatus.OK)],
  53. [4, generateJobRun('prod', CheckInStatus.OK)],
  54. [5, generateJobRun('prod', CheckInStatus.MISSED)],
  55. [6, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  56. [7, generateJobRun('prod', CheckInStatus.MISSED)],
  57. [8, generateJobRun('prod', CheckInStatus.MISSED)],
  58. ];
  59. const mergedData = mergeBuckets(bucketData);
  60. const expectedMerged = [
  61. {
  62. startTs: 1,
  63. endTs: 4,
  64. width: 4,
  65. roundedLeft: true,
  66. roundedRight: false,
  67. envMapping: generateEnvMapping('prod', [4, 0, 0, 0]),
  68. },
  69. {
  70. startTs: 5,
  71. endTs: 8,
  72. width: 4,
  73. roundedLeft: false,
  74. roundedRight: true,
  75. envMapping: generateEnvMapping('prod', [0, 3, 1, 0]),
  76. },
  77. ];
  78. expect(mergedData).toEqual(expectedMerged);
  79. });
  80. it('does not generate a separate tick if the next generated tick would be the same status', function () {
  81. const bucketData: MonitorBucketData = [
  82. [1, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  83. [2, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  84. [3, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  85. [4, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  86. [5, generateJobRun('prod', CheckInStatus.MISSED)],
  87. [6, generateJobRun('prod', CheckInStatus.OK)],
  88. [7, generateJobRun('prod', CheckInStatus.MISSED)],
  89. [8, generateJobRun('prod', CheckInStatus.TIMEOUT)],
  90. ];
  91. const mergedData = mergeBuckets(bucketData);
  92. const expectedMerged = [
  93. {
  94. startTs: 1,
  95. endTs: 8,
  96. width: 8,
  97. roundedLeft: true,
  98. roundedRight: true,
  99. envMapping: generateEnvMapping('prod', [1, 2, 5, 0]),
  100. },
  101. ];
  102. expect(mergedData).toEqual(expectedMerged);
  103. });
  104. });