spanMetricsTable.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import {initializeData as _initializeData} from 'sentry-test/performance/initializePerformanceData';
  2. import {act, render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import SpanMetricsTable from 'sentry/views/performance/transactionSummary/transactionSpans/spanMetricsTable';
  5. const initializeData = () => {
  6. const data = _initializeData({
  7. features: ['performance-view'],
  8. });
  9. act(() => ProjectsStore.loadInitialData(data.projects));
  10. return data;
  11. };
  12. describe('SuspectSpansTable', () => {
  13. it('should render the table and rows of data', async () => {
  14. const {organization, project} = initializeData();
  15. const mockRequest = MockApiClient.addMockResponse({
  16. url: `/organizations/${organization.slug}/events/`,
  17. method: 'GET',
  18. body: {
  19. data: [
  20. {
  21. 'span.group': 'abc123',
  22. 'span.op': 'db',
  23. 'span.description': 'SELECT thing FROM my_cool_db',
  24. 'spm()': 4.448963396488444,
  25. 'sum(span.duration)': 1236071121.5044901,
  26. 'avg(span.duration)': 30900.700924083318,
  27. },
  28. ],
  29. },
  30. });
  31. render(
  32. <SpanMetricsTable transactionName="Test Transaction" project={project} query={''} />
  33. );
  34. await waitFor(() =>
  35. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  36. );
  37. expect(mockRequest).toHaveBeenCalled();
  38. const {
  39. opHeader,
  40. descriptionHeader,
  41. throughputHeader,
  42. avgDurationHeader,
  43. timeSpentHeader,
  44. } = await findTableHeaders();
  45. expect(opHeader).toHaveTextContent('Span Operation');
  46. expect(descriptionHeader).toHaveTextContent('Span Description');
  47. expect(throughputHeader).toHaveTextContent('Throughput');
  48. expect(avgDurationHeader).toHaveTextContent('Avg Duration');
  49. expect(timeSpentHeader).toHaveTextContent('Time Spent');
  50. const {opCell, descriptionCell, throughputCell, avgDurationCell, timeSpentCell} =
  51. await findFirstRowCells();
  52. expect(opCell).toHaveTextContent('db');
  53. expect(descriptionCell).toHaveTextContent('SELECT thing FROM my_cool_db');
  54. expect(throughputCell).toHaveTextContent('4.45/s');
  55. expect(avgDurationCell).toHaveTextContent('30.90s');
  56. expect(timeSpentCell).toHaveTextContent('2.04wk');
  57. });
  58. it('should handle the case when there is no span grouping', async () => {
  59. const {organization, project} = initializeData();
  60. const mockRequest = MockApiClient.addMockResponse({
  61. url: `/organizations/${organization.slug}/events/`,
  62. method: 'GET',
  63. body: {
  64. data: [
  65. {
  66. 'span.op': 'db',
  67. 'spm()': 5000,
  68. 'sum(span.self_time)': 12346071121.5044901,
  69. 'avg(span.duration)': 30900.700924083318,
  70. },
  71. ],
  72. },
  73. });
  74. render(
  75. <SpanMetricsTable transactionName="Test Transaction" project={project} query={''} />
  76. );
  77. await waitFor(() =>
  78. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  79. );
  80. expect(mockRequest).toHaveBeenCalled();
  81. const {opCell, descriptionCell} = await findFirstRowCells();
  82. expect(opCell).toHaveTextContent('db');
  83. expect(descriptionCell).toHaveTextContent('\u2014');
  84. });
  85. });
  86. async function findTableHeaders() {
  87. const tableHeaders = await screen.findAllByTestId('grid-head-cell');
  88. const [
  89. opHeader,
  90. descriptionHeader,
  91. throughputHeader,
  92. avgDurationHeader,
  93. timeSpentHeader,
  94. ] = tableHeaders;
  95. return {
  96. opHeader,
  97. descriptionHeader,
  98. throughputHeader,
  99. avgDurationHeader,
  100. timeSpentHeader,
  101. };
  102. }
  103. async function findFirstRowCells() {
  104. const bodyCells = await screen.findAllByTestId('grid-body-cell');
  105. const [opCell, descriptionCell, throughputCell, avgDurationCell, timeSpentCell] =
  106. bodyCells;
  107. return {
  108. opCell,
  109. descriptionCell,
  110. throughputCell,
  111. avgDurationCell,
  112. timeSpentCell,
  113. };
  114. }