queuesTable.spec.tsx 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 'messaging.destination.name': 'celery.backend_cleanup',
  22. 'count()': 2,
  23. 'count_op(queue.publish)': 0,
  24. 'count_op(queue.process)': 2,
  25. 'sum(span.duration)': 6,
  26. 'avg(span.duration)': 3,
  27. 'avg_if(span.duration,span.op,queue.publish)': 0,
  28. 'avg_if(span.duration,span.op,queue.process)': 3,
  29. 'avg(messaging.message.receive.latency)': 20,
  30. },
  31. ],
  32. meta: {
  33. fields: {
  34. 'count()': 'integer',
  35. 'count_op(queue.publish)': 'integer',
  36. 'count_op(queue.process)': 'integer',
  37. 'sum(span.duration)': 'duration',
  38. 'avg(span.duration)': 'duration',
  39. 'avg_if(span.duration,span.op,queue.publish)': 'duration',
  40. 'avg_if(span.duration,span.op,queue.process)': 'duration',
  41. 'avg(messaging.message.receive.latency)': 'duration',
  42. },
  43. },
  44. },
  45. });
  46. });
  47. it('renders', async () => {
  48. render(<QueuesTable />);
  49. expect(screen.getByRole('table', {name: 'Queues'})).toBeInTheDocument();
  50. expect(screen.getByRole('columnheader', {name: 'Destination'})).toBeInTheDocument();
  51. expect(
  52. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  53. ).toBeInTheDocument();
  54. expect(
  55. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  56. ).toBeInTheDocument();
  57. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  58. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  59. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  60. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  61. expect(eventsMock).toHaveBeenCalledWith(
  62. '/organizations/org-slug/events/',
  63. expect.objectContaining({
  64. query: expect.objectContaining({
  65. field: [
  66. 'messaging.destination.name',
  67. 'count()',
  68. 'count_op(queue.publish)',
  69. 'count_op(queue.process)',
  70. 'sum(span.duration)',
  71. 'avg(span.duration)',
  72. 'avg_if(span.duration,span.op,queue.publish)',
  73. 'avg_if(span.duration,span.op,queue.process)',
  74. 'avg(messaging.message.receive.latency)',
  75. ],
  76. dataset: 'spansMetrics',
  77. }),
  78. })
  79. );
  80. await screen.findByText('celery.backend_cleanup');
  81. expect(screen.getByRole('cell', {name: '3.00ms'})).toBeInTheDocument();
  82. expect(screen.getByRole('cell', {name: '2'})).toBeInTheDocument();
  83. expect(screen.getByRole('cell', {name: '6.00ms'})).toBeInTheDocument();
  84. expect(screen.getByRole('cell', {name: '20.00ms'})).toBeInTheDocument();
  85. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  86. });
  87. });