transactionsTable.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import useOrganization from 'sentry/utils/useOrganization';
  4. import {TransactionsTable} from 'sentry/views/performance/queues/destinationSummary/transactionsTable';
  5. jest.mock('sentry/utils/useOrganization');
  6. describe('transactionsTable', () => {
  7. const organization = OrganizationFixture();
  8. jest.mocked(useOrganization).mockReturnValue(organization);
  9. let eventsMock;
  10. const pageLinks =
  11. '<https://sentry.io/fake/previous>; rel="previous"; results="false"; cursor="0:0:1", ' +
  12. '<https://sentry.io/fake/next>; rel="next"; results="true"; cursor="0:20:0"';
  13. beforeEach(() => {
  14. eventsMock = MockApiClient.addMockResponse({
  15. url: `/organizations/${organization.slug}/events/`,
  16. headers: {Link: pageLinks},
  17. method: 'GET',
  18. body: {
  19. data: [
  20. {
  21. transaction: 'celery.backend_cleanup',
  22. 'span.op': 'queue.process',
  23. 'count()': 2,
  24. 'count_op(queue.publish)': 0,
  25. 'count_op(queue.process)': 2,
  26. 'sum(span.duration)': 6,
  27. 'avg(span.duration)': 3,
  28. 'avg_if(span.duration,span.op,queue.publish)': 0,
  29. 'avg_if(span.duration,span.op,queue.process)': 3,
  30. 'avg(messaging.message.receive.latency)': 20,
  31. },
  32. ],
  33. meta: {
  34. fields: {
  35. 'count()': 'integer',
  36. 'count_op(queue.publish)': 'integer',
  37. 'count_op(queue.process)': 'integer',
  38. 'sum(span.duration)': 'duration',
  39. 'avg(span.duration)': 'duration',
  40. 'avg_if(span.duration,span.op,queue.publish)': 'duration',
  41. 'avg_if(span.duration,span.op,queue.process)': 'duration',
  42. 'avg(messaging.message.receive.latency)': 'duration',
  43. },
  44. },
  45. },
  46. });
  47. });
  48. it('renders', async () => {
  49. render(<TransactionsTable />);
  50. expect(screen.getByRole('table', {name: 'Transactions'})).toBeInTheDocument();
  51. expect(screen.getByRole('columnheader', {name: 'Transactions'})).toBeInTheDocument();
  52. expect(screen.getByRole('columnheader', {name: 'Type'})).toBeInTheDocument();
  53. expect(
  54. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  55. ).toBeInTheDocument();
  56. expect(
  57. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  58. ).toBeInTheDocument();
  59. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  60. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  61. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  62. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  63. expect(eventsMock).toHaveBeenCalledWith(
  64. '/organizations/org-slug/events/',
  65. expect.objectContaining({
  66. query: expect.objectContaining({
  67. field: [
  68. 'transaction',
  69. 'span.op',
  70. 'count()',
  71. 'count_op(queue.publish)',
  72. 'count_op(queue.process)',
  73. 'sum(span.duration)',
  74. 'avg(span.duration)',
  75. 'avg_if(span.duration,span.op,queue.publish)',
  76. 'avg_if(span.duration,span.op,queue.process)',
  77. 'avg(messaging.message.receive.latency)',
  78. ],
  79. dataset: 'spansMetrics',
  80. }),
  81. })
  82. );
  83. await screen.findByText('celery.backend_cleanup');
  84. expect(screen.getByRole('cell', {name: '3.00ms'})).toBeInTheDocument();
  85. expect(screen.getByRole('cell', {name: '2'})).toBeInTheDocument();
  86. expect(screen.getByRole('cell', {name: '6.00ms'})).toBeInTheDocument();
  87. expect(screen.getByRole('cell', {name: '20.00ms'})).toBeInTheDocument();
  88. expect(screen.getByRole('cell', {name: 'Consumer'})).toBeInTheDocument();
  89. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  90. });
  91. });