queuesTable.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import useOrganization from 'sentry/utils/useOrganization';
  4. import {QueuesTable} from 'sentry/views/performance/queues/queuesTable';
  5. jest.mock('sentry/utils/useOrganization');
  6. describe('queuesTable', () => {
  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. 'avg_if(span.self_time,span.op,queue.task.celery)': 3,
  23. 'sum(span.self_time)': 6,
  24. 'count_op(queue.submit.celery)': 0,
  25. 'count_op(queue.task.celery)': 2,
  26. 'avg_if(span.self_time,span.op,queue.submit.celery)': 0,
  27. 'count()': 2,
  28. 'avg(span.self_time)': 3,
  29. },
  30. ],
  31. meta: {
  32. fields: {
  33. 'avg_if(span.self_time,span.op,queue.task.celery)': 'duration',
  34. 'count_op(queue.submit.celery)': 'integer',
  35. 'avg_if(span.self_time,span.op,queue.submit.celery)': 'duration',
  36. 'count_op(queue.task.celery)': 'integer',
  37. 'sum(span.self_time)': 'duration',
  38. 'count()': 'integer',
  39. 'avg(span.self_time)': 'duration',
  40. },
  41. },
  42. },
  43. });
  44. });
  45. it('renders', async () => {
  46. render(<QueuesTable />);
  47. expect(screen.getByRole('table', {name: 'Queues'})).toBeInTheDocument();
  48. expect(screen.getByRole('columnheader', {name: 'Destination'})).toBeInTheDocument();
  49. expect(
  50. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  51. ).toBeInTheDocument();
  52. expect(
  53. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  54. ).toBeInTheDocument();
  55. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  56. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  57. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  58. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  59. expect(eventsMock).toHaveBeenCalledWith(
  60. '/organizations/org-slug/events/',
  61. expect.objectContaining({
  62. query: expect.objectContaining({
  63. field: [
  64. 'transaction',
  65. 'count()',
  66. 'count_op(queue.submit.celery)',
  67. 'count_op(queue.task.celery)',
  68. 'sum(span.self_time)',
  69. 'avg(span.self_time)',
  70. 'avg_if(span.self_time,span.op,queue.submit.celery)',
  71. 'avg_if(span.self_time,span.op,queue.task.celery)',
  72. ],
  73. dataset: 'spansMetrics',
  74. }),
  75. })
  76. );
  77. await screen.findByText('celery.backend_cleanup');
  78. expect(screen.getByText('3.00ms')).toBeInTheDocument();
  79. expect(screen.getByText(2)).toBeInTheDocument();
  80. expect(screen.getByText('6.00ms')).toBeInTheDocument();
  81. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  82. });
  83. });