table.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {getTableData} from 'sentry/views/dashboards/metrics/table';
  2. const queries = [
  3. {
  4. name: 'a',
  5. mri: 'd:custom/sentry.event_manager.save@second',
  6. op: 'p50',
  7. groupBy: ['consumer_group', 'event_type'],
  8. },
  9. {
  10. name: 'b',
  11. mri: 'd:custom/sentry.event_manager.save_attachments@second',
  12. op: 'p90',
  13. groupBy: ['event_type'],
  14. },
  15. ];
  16. const data = [
  17. [
  18. {
  19. by: {
  20. consumer_group: '',
  21. event_type: '',
  22. },
  23. series: [],
  24. totals: 0.3751704159949441,
  25. },
  26. {
  27. by: {
  28. consumer_group: '',
  29. event_type: 'error',
  30. },
  31. series: [],
  32. totals: 0.13256912349970662,
  33. },
  34. {
  35. by: {
  36. consumer_group: 'ingest-occurrences-0',
  37. event_type: '',
  38. },
  39. series: [],
  40. totals: 0.11766651156358421,
  41. },
  42. {
  43. by: {
  44. consumer_group: '',
  45. event_type: 'transaction',
  46. },
  47. series: [],
  48. totals: 0.11107462100335397,
  49. },
  50. {
  51. by: {
  52. consumer_group: '',
  53. event_type: 'default',
  54. },
  55. series: [],
  56. totals: 0.10583872749703004,
  57. },
  58. {
  59. by: {
  60. consumer_group: '',
  61. event_type: 'csp',
  62. },
  63. series: [],
  64. totals: 0.1013268940441776,
  65. },
  66. {
  67. by: {
  68. consumer_group: '',
  69. event_type: 'nel',
  70. },
  71. series: [],
  72. totals: 0.06116106499985108,
  73. },
  74. ],
  75. [
  76. {
  77. by: {
  78. event_type: '',
  79. },
  80. series: [],
  81. totals: 0.000006055769335944205,
  82. },
  83. {
  84. by: {
  85. event_type: 'default',
  86. },
  87. series: [],
  88. totals: 0.000004693902155850083,
  89. },
  90. {
  91. by: {
  92. event_type: 'error',
  93. },
  94. series: [],
  95. totals: 0.0000046898378059268,
  96. },
  97. {
  98. by: {
  99. event_type: 'csp',
  100. },
  101. series: [],
  102. totals: 0.000004462950164452195,
  103. },
  104. {
  105. by: {
  106. event_type: 'nel',
  107. },
  108. series: [],
  109. totals: 0.000004437007009983063,
  110. },
  111. ],
  112. ];
  113. describe('getTableSeries', () => {
  114. it('should return table series', () => {
  115. // @ts-expect-error
  116. const result = getTableData({data, meta: []}, queries);
  117. expect(result.headers).toEqual([
  118. {order: undefined, label: 'consumer_group', name: 'consumer_group', type: 'tag'},
  119. {order: undefined, label: 'event_type', name: 'event_type', type: 'tag'},
  120. {
  121. order: undefined,
  122. label: 'p50(sentry.event_manager.save)',
  123. name: 'a',
  124. type: 'field',
  125. id: undefined,
  126. },
  127. {
  128. order: undefined,
  129. label: 'p90(sentry.event_manager.save_attachments)',
  130. name: 'b',
  131. type: 'field',
  132. id: undefined,
  133. },
  134. ]);
  135. expect(result.rows.length).toEqual(7);
  136. const ingestRow = result.rows[2];
  137. expect(ingestRow.a.value).toBeDefined();
  138. expect(ingestRow.b.value).toBeUndefined();
  139. const defaultRow = result.rows[5];
  140. expect(defaultRow.a.value).toBeDefined();
  141. expect(defaultRow.b.value).toBeDefined();
  142. });
  143. });