spanMetricsTable.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 initialData = initializeData();
  15. const {organization, project, routerContext} = initialData;
  16. const mockRequest = MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/events/`,
  18. method: 'GET',
  19. body: {
  20. data: [
  21. {
  22. 'span.group': '',
  23. 'span.op': 'navigation',
  24. 'span.description': '',
  25. 'spm()': 4.448963396488444,
  26. 'sum(span.self_time)': 1236071121.5044901,
  27. 'avg(span.duration)': 30900.700924083318,
  28. },
  29. ],
  30. },
  31. });
  32. render(<SpanMetricsTable transactionName="Test Transaction" project={project} />, {
  33. context: routerContext,
  34. });
  35. await waitFor(() =>
  36. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  37. );
  38. expect(mockRequest).toHaveBeenCalled();
  39. const tableHeaders = await screen.findAllByTestId('grid-head-cell');
  40. const [opHeader, nameHeader, throughputHeader, avgDurationHeader, timeSpentHeader] =
  41. tableHeaders;
  42. expect(opHeader).toHaveTextContent('Span Operation');
  43. expect(nameHeader).toHaveTextContent('Span Name');
  44. expect(throughputHeader).toHaveTextContent('Throughput');
  45. expect(avgDurationHeader).toHaveTextContent('Avg Duration');
  46. expect(timeSpentHeader).toHaveTextContent('Time Spent');
  47. const bodyCells = await screen.findAllByTestId('grid-body-cell');
  48. const [opCell, nameCell, throughputCell, avgDurationCell, timeSpentCell] = bodyCells;
  49. expect(opCell).toHaveTextContent('navigation');
  50. expect(nameCell).toHaveTextContent('(unnamed span)');
  51. expect(throughputCell).toHaveTextContent('4.45/s');
  52. expect(avgDurationCell).toHaveTextContent('30.90s');
  53. expect(timeSpentCell).toHaveTextContent('2.04wk');
  54. });
  55. });