spanMetricsTable.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.organization.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.self_time)': 1236071121.5044901,
  26. 'avg(span.duration)': 30900.700924083318,
  27. },
  28. ],
  29. },
  30. });
  31. render(<SpanMetricsTable transactionName="Test Transaction" project={project} />);
  32. await waitFor(() =>
  33. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  34. );
  35. expect(mockRequest).toHaveBeenCalled();
  36. const {
  37. opHeader,
  38. descriptionHeader,
  39. throughputHeader,
  40. avgDurationHeader,
  41. timeSpentHeader,
  42. } = await findTableHeaders();
  43. expect(opHeader).toHaveTextContent('Span Operation');
  44. expect(descriptionHeader).toHaveTextContent('Span Description');
  45. expect(throughputHeader).toHaveTextContent('Throughput');
  46. expect(avgDurationHeader).toHaveTextContent('Avg Duration');
  47. expect(timeSpentHeader).toHaveTextContent('Time Spent');
  48. const {opCell, descriptionCell, throughputCell, avgDurationCell, timeSpentCell} =
  49. await findFirstRowCells();
  50. expect(opCell).toHaveTextContent('db');
  51. expect(descriptionCell).toHaveTextContent('SELECT thing FROM my_cool_db');
  52. expect(throughputCell).toHaveTextContent('4.45/s');
  53. expect(avgDurationCell).toHaveTextContent('30.90s');
  54. expect(timeSpentCell).toHaveTextContent('2.04wk');
  55. });
  56. it('should handle the case when there is no span grouping', async () => {
  57. const {organization, project} = initializeData();
  58. const mockRequest = MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/events/`,
  60. method: 'GET',
  61. body: {
  62. data: [
  63. {
  64. 'span.op': 'db',
  65. 'spm()': 5000,
  66. 'sum(span.self_time)': 12346071121.5044901,
  67. 'avg(span.duration)': 30900.700924083318,
  68. },
  69. ],
  70. },
  71. });
  72. render(<SpanMetricsTable transactionName="Test Transaction" project={project} />);
  73. await waitFor(() =>
  74. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  75. );
  76. expect(mockRequest).toHaveBeenCalled();
  77. const {opCell, descriptionCell} = await findFirstRowCells();
  78. expect(opCell).toHaveTextContent('db');
  79. expect(descriptionCell).toHaveTextContent('\u2014');
  80. });
  81. });
  82. async function findTableHeaders() {
  83. const tableHeaders = await screen.findAllByTestId('grid-head-cell');
  84. const [
  85. opHeader,
  86. descriptionHeader,
  87. throughputHeader,
  88. avgDurationHeader,
  89. timeSpentHeader,
  90. ] = tableHeaders;
  91. return {
  92. opHeader,
  93. descriptionHeader,
  94. throughputHeader,
  95. avgDurationHeader,
  96. timeSpentHeader,
  97. };
  98. }
  99. async function findFirstRowCells() {
  100. const bodyCells = await screen.findAllByTestId('grid-body-cell');
  101. const [opCell, descriptionCell, throughputCell, avgDurationCell, timeSpentCell] =
  102. bodyCells;
  103. return {
  104. opCell,
  105. descriptionCell,
  106. throughputCell,
  107. avgDurationCell,
  108. timeSpentCell,
  109. };
  110. }