determineSeriesConfidence.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {determineSeriesConfidence} from 'sentry/views/alerts/rules/metric/utils/determineSeriesConfidence';
  2. describe('determineSeriesConfidence', () => {
  3. it('equal null if no data', () => {
  4. const confidence = determineSeriesConfidence({
  5. data: [],
  6. });
  7. expect(confidence).toBeNull();
  8. });
  9. it('equal null if no confidence found', () => {
  10. const confidence = determineSeriesConfidence({
  11. data: [
  12. [100, [{count: 100}]],
  13. [200, [{count: 200}]],
  14. ],
  15. });
  16. expect(confidence).toBeNull();
  17. });
  18. it('equal null if confidence is empty', () => {
  19. const confidence = determineSeriesConfidence({
  20. data: [
  21. [100, [{count: 100}]],
  22. [200, [{count: 200}]],
  23. ],
  24. confidence: [],
  25. });
  26. expect(confidence).toBeNull();
  27. });
  28. it('equal null if all confidence null', () => {
  29. const confidence = determineSeriesConfidence({
  30. data: [
  31. [100, [{count: 100}]],
  32. [200, [{count: 200}]],
  33. ],
  34. confidence: [
  35. [100, [{count: null}]],
  36. [200, [{count: null}]],
  37. ],
  38. });
  39. expect(confidence).toBeNull();
  40. });
  41. it('equal high if all confidence high', () => {
  42. const confidence = determineSeriesConfidence({
  43. data: [
  44. [100, [{count: 100}]],
  45. [200, [{count: 200}]],
  46. ],
  47. confidence: [
  48. [100, [{count: 'high'}]],
  49. [200, [{count: 'high'}]],
  50. ],
  51. });
  52. expect(confidence).toBe('high');
  53. });
  54. it('equal high if all confidence high or null', () => {
  55. const confidence = determineSeriesConfidence({
  56. data: [
  57. [100, [{count: 100}]],
  58. [200, [{count: 200}]],
  59. ],
  60. confidence: [
  61. [100, [{count: 'high'}]],
  62. [200, [{count: null}]],
  63. ],
  64. });
  65. expect(confidence).toBe('high');
  66. });
  67. it('equal high if <25% is low', () => {
  68. const confidence = determineSeriesConfidence({
  69. data: [
  70. [100, [{count: 100}]],
  71. [200, [{count: 200}]],
  72. [300, [{count: 300}]],
  73. [400, [{count: 400}]],
  74. [500, [{count: 500}]],
  75. [600, [{count: 600}]],
  76. [700, [{count: 700}]],
  77. ],
  78. confidence: [
  79. [100, [{count: 'high'}]],
  80. [200, [{count: 'high'}]],
  81. [300, [{count: 'high'}]],
  82. [400, [{count: 'high'}]],
  83. [500, [{count: 'low'}]],
  84. [600, [{count: 'high'}]],
  85. [700, [{count: null}]],
  86. ],
  87. });
  88. expect(confidence).toBe('high');
  89. });
  90. it('equal low if >25% is low', () => {
  91. const confidence = determineSeriesConfidence({
  92. data: [
  93. [100, [{count: 100}]],
  94. [200, [{count: 200}]],
  95. [300, [{count: 300}]],
  96. [400, [{count: 400}]],
  97. [500, [{count: 500}]],
  98. ],
  99. confidence: [
  100. [100, [{count: 'high'}]],
  101. [200, [{count: null}]],
  102. [300, [{count: null}]],
  103. [400, [{count: 'low'}]],
  104. [500, [{count: 'low'}]],
  105. ],
  106. });
  107. expect(confidence).toBe('low');
  108. });
  109. it('equal low if all low', () => {
  110. const confidence = determineSeriesConfidence({
  111. data: [
  112. [100, [{count: 100}]],
  113. [200, [{count: 200}]],
  114. [300, [{count: 300}]],
  115. [400, [{count: 400}]],
  116. [500, [{count: 500}]],
  117. ],
  118. confidence: [
  119. [100, [{count: 'low'}]],
  120. [200, [{count: 'low'}]],
  121. [300, [{count: 'low'}]],
  122. [400, [{count: 'low'}]],
  123. [500, [{count: 'low'}]],
  124. ],
  125. });
  126. expect(confidence).toBe('low');
  127. });
  128. it('equals low if any in bucket is low', () => {
  129. const confidence = determineSeriesConfidence({
  130. data: [[200, [{count: 100}]]],
  131. confidence: [
  132. [100, [{count: 'high'}, {count: 'low'}, {count: null}]],
  133. [200, [{count: null}, {count: 'low'}, {count: 'high'}]],
  134. ],
  135. });
  136. expect(confidence).toBe('low');
  137. });
  138. it('equals high if no lows in bucket', () => {
  139. const confidence = determineSeriesConfidence({
  140. data: [[200, [{count: 100}]]],
  141. confidence: [
  142. [100, [{count: 'high'}, {count: 'high'}, {count: null}]],
  143. [200, [{count: null}, {count: null}, {count: 'high'}]],
  144. ],
  145. });
  146. expect(confidence).toBe('high');
  147. });
  148. });