customMetricsEventData.spec.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import type {MetricsSummary} from 'sentry/components/events/interfaces/spans/types';
  4. import {CustomMetricsEventData} from 'sentry/views/ddm/customMetricsEventData';
  5. describe('CustomMetricsEventData', () => {
  6. it('renders empty (no feature flag)', () => {
  7. const metricsSummary: MetricsSummary = {
  8. 'd:custom/my.metric@second': [
  9. {
  10. count: 2,
  11. min: 1,
  12. max: 2,
  13. sum: 3,
  14. tags: {
  15. foo: 'bar',
  16. },
  17. },
  18. ],
  19. };
  20. const {container} = render(
  21. <CustomMetricsEventData
  22. metricsSummary={metricsSummary}
  23. startTimestamp={1706189398.176}
  24. />
  25. );
  26. expect(container).toBeEmptyDOMElement();
  27. });
  28. it('renders empty (no data)', () => {
  29. const organization = OrganizationFixture({features: ['ddm-ui']});
  30. const {container} = render(
  31. <CustomMetricsEventData metricsSummary={{}} startTimestamp={1706189398.176} />,
  32. {
  33. organization,
  34. }
  35. );
  36. expect(container).toBeEmptyDOMElement();
  37. });
  38. it('renders (all information)', () => {
  39. const organization = OrganizationFixture({features: ['ddm-ui']});
  40. const metricsSummary: MetricsSummary = {
  41. 'd:custom/my.metric@second': [
  42. {
  43. count: 2,
  44. min: 1,
  45. max: 2,
  46. sum: 3,
  47. tags: {
  48. foo: 'bar',
  49. },
  50. },
  51. ],
  52. };
  53. render(
  54. <CustomMetricsEventData
  55. metricsSummary={metricsSummary}
  56. startTimestamp={1706189398.176}
  57. />,
  58. {
  59. organization,
  60. }
  61. );
  62. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  63. expect(screen.getByText('Name')).toBeInTheDocument();
  64. expect(screen.getByText('my.metric')).toBeInTheDocument();
  65. expect(screen.getByRole('button', {name: 'Open in Metrics'})).toBeInTheDocument();
  66. expect(screen.getByText('Stats')).toBeInTheDocument();
  67. expect(screen.getByText(/Type: distribution/)).toBeInTheDocument();
  68. expect(screen.getByText(/Count: 2/)).toBeInTheDocument();
  69. expect(screen.getByText(/Min: 1s/)).toBeInTheDocument();
  70. expect(screen.getByText(/Max: 2s/)).toBeInTheDocument();
  71. expect(screen.getByText(/Sum: 3s/)).toBeInTheDocument();
  72. expect(screen.getByText(/Avg: 1\.5s/)).toBeInTheDocument();
  73. expect(screen.getByText('Tags')).toBeInTheDocument();
  74. expect(screen.getByText('foo')).toBeInTheDocument();
  75. expect(screen.getByRole('link', {name: 'bar'})).toBeInTheDocument();
  76. });
  77. it('renders (count === 1)', () => {
  78. const organization = OrganizationFixture({features: ['ddm-ui']});
  79. const metricsSummary: MetricsSummary = {
  80. 'd:custom/my.metric@second': [
  81. {
  82. count: 1,
  83. min: 2,
  84. max: 2,
  85. sum: 2,
  86. tags: {
  87. foo: 'bar',
  88. },
  89. },
  90. ],
  91. };
  92. render(
  93. <CustomMetricsEventData
  94. metricsSummary={metricsSummary}
  95. startTimestamp={1706189398.176}
  96. />,
  97. {
  98. organization,
  99. }
  100. );
  101. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  102. expect(screen.getByText('Name')).toBeInTheDocument();
  103. expect(screen.getByText('my.metric')).toBeInTheDocument();
  104. expect(screen.getByRole('button', {name: 'Open in Metrics'})).toBeInTheDocument();
  105. expect(screen.getByText('Stats')).toBeInTheDocument();
  106. expect(screen.getByText(/Type: distribution/)).toBeInTheDocument();
  107. expect(screen.getByText(/Value: 2s/)).toBeInTheDocument();
  108. expect(screen.getByText('Tags')).toBeInTheDocument();
  109. expect(screen.getByText('foo')).toBeInTheDocument();
  110. expect(screen.getByRole('link', {name: 'bar'})).toBeInTheDocument();
  111. });
  112. it('renders (counter metric)', () => {
  113. const organization = OrganizationFixture({features: ['ddm-ui']});
  114. const metricsSummary: MetricsSummary = {
  115. 'c:custom/my.metric@second': [
  116. {
  117. count: 1,
  118. min: 1,
  119. max: 1,
  120. sum: 1,
  121. tags: {
  122. foo: 'bar',
  123. },
  124. },
  125. ],
  126. };
  127. render(
  128. <CustomMetricsEventData
  129. metricsSummary={metricsSummary}
  130. startTimestamp={1706189398.176}
  131. />,
  132. {
  133. organization,
  134. }
  135. );
  136. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  137. expect(screen.getByText('Name')).toBeInTheDocument();
  138. expect(screen.getByText('my.metric')).toBeInTheDocument();
  139. expect(screen.getByRole('button', {name: 'Open in Metrics'})).toBeInTheDocument();
  140. expect(screen.getByText('Stats')).toBeInTheDocument();
  141. expect(screen.getByText(/Type: counter/)).toBeInTheDocument();
  142. expect(screen.getByText(/Count: 1/)).toBeInTheDocument();
  143. expect(screen.getByText('Tags')).toBeInTheDocument();
  144. expect(screen.getByText('foo')).toBeInTheDocument();
  145. expect(screen.getByRole('link', {name: 'bar'})).toBeInTheDocument();
  146. });
  147. it('renders (no tags)', () => {
  148. const organization = OrganizationFixture({features: ['ddm-ui']});
  149. const metricsSummary: MetricsSummary = {
  150. 'c:custom/my.metric@second': [
  151. {
  152. count: 1,
  153. min: 1,
  154. max: 1,
  155. sum: 1,
  156. tags: null,
  157. },
  158. ],
  159. };
  160. render(
  161. <CustomMetricsEventData
  162. metricsSummary={metricsSummary}
  163. startTimestamp={1706189398.176}
  164. />,
  165. {
  166. organization,
  167. }
  168. );
  169. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  170. expect(screen.getByText('Name')).toBeInTheDocument();
  171. expect(screen.getByText('my.metric')).toBeInTheDocument();
  172. expect(screen.getByRole('button', {name: 'Open in Metrics'})).toBeInTheDocument();
  173. expect(screen.getByText('Stats')).toBeInTheDocument();
  174. expect(screen.getByText(/Type: counter/)).toBeInTheDocument();
  175. expect(screen.getByText(/Count: 1/)).toBeInTheDocument();
  176. expect(screen.queryByText('Tags')).not.toBeInTheDocument();
  177. });
  178. it('renders (empty tags)', () => {
  179. const organization = OrganizationFixture({features: ['ddm-ui']});
  180. const metricsSummary: MetricsSummary = {
  181. 'c:custom/my.metric@second': [
  182. {
  183. count: 1,
  184. min: 1,
  185. max: 1,
  186. sum: 1,
  187. tags: {},
  188. },
  189. ],
  190. };
  191. render(
  192. <CustomMetricsEventData
  193. metricsSummary={metricsSummary}
  194. startTimestamp={1706189398.176}
  195. />,
  196. {
  197. organization,
  198. }
  199. );
  200. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  201. expect(screen.getByText('Name')).toBeInTheDocument();
  202. expect(screen.getByText('my.metric')).toBeInTheDocument();
  203. expect(screen.getByRole('button', {name: 'Open in Metrics'})).toBeInTheDocument();
  204. expect(screen.getByText('Stats')).toBeInTheDocument();
  205. expect(screen.getByText(/Type: counter/)).toBeInTheDocument();
  206. expect(screen.getByText(/Count: 1/)).toBeInTheDocument();
  207. expect(screen.queryByText('Tags')).not.toBeInTheDocument();
  208. });
  209. it('renders (multiple)', () => {
  210. const organization = OrganizationFixture({features: ['ddm-ui']});
  211. const metricsSummary: MetricsSummary = {
  212. 'd:custom/my.distribution@second': [
  213. {
  214. count: 2,
  215. min: 1,
  216. max: 2,
  217. sum: 3,
  218. tags: {
  219. foo: 'bar',
  220. },
  221. },
  222. {
  223. count: 1,
  224. min: 1,
  225. max: 1,
  226. sum: 1,
  227. tags: null,
  228. },
  229. ],
  230. 'c:custom/my.counter@second': [
  231. {
  232. count: 2,
  233. min: 1,
  234. max: 2,
  235. sum: 3,
  236. tags: {
  237. foo: 'bar',
  238. },
  239. },
  240. ],
  241. };
  242. render(
  243. <CustomMetricsEventData
  244. metricsSummary={metricsSummary}
  245. startTimestamp={1706189398.176}
  246. />,
  247. {
  248. organization,
  249. }
  250. );
  251. expect(screen.getByText('Emitted Metrics')).toBeInTheDocument();
  252. expect(screen.getAllByText('Name')).toHaveLength(3);
  253. expect(screen.getAllByText('my.distribution')).toHaveLength(2);
  254. expect(screen.getAllByText('my.counter')).toHaveLength(1);
  255. });
  256. });