messageConsumerSamplesPanel.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {MessageConsumerSamplesPanel} from 'sentry/views/performance/queues/messageConsumerSamplesPanel';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('messageConsumerSamplesPanel', () => {
  11. const organization = OrganizationFixture();
  12. let eventsRequestMock, eventsStatsRequestMock;
  13. jest.mocked(usePageFilters).mockReturnValue({
  14. isReady: true,
  15. desyncedFilters: new Set(),
  16. pinnedFilters: new Set(),
  17. shouldPersist: true,
  18. selection: {
  19. datetime: {
  20. period: '10d',
  21. start: null,
  22. end: null,
  23. utc: false,
  24. },
  25. environments: [],
  26. projects: [],
  27. },
  28. });
  29. jest.mocked(useLocation).mockReturnValue({
  30. pathname: '',
  31. search: '',
  32. query: {transaction: 'sentry.tasks.store.save_event', destination: 'event-queue'},
  33. hash: '',
  34. state: undefined,
  35. action: 'PUSH',
  36. key: '',
  37. });
  38. jest.mocked(useOrganization).mockReturnValue(organization);
  39. beforeEach(() => {
  40. eventsStatsRequestMock = MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/events-stats/`,
  42. method: 'GET',
  43. body: {
  44. data: [[1699907700, [{count: 7810}]]],
  45. meta: {},
  46. },
  47. });
  48. eventsRequestMock = MockApiClient.addMockResponse({
  49. url: `/organizations/${organization.slug}/events/`,
  50. method: 'GET',
  51. body: {
  52. data: [],
  53. meta: {},
  54. },
  55. });
  56. });
  57. afterAll(() => {
  58. jest.resetAllMocks();
  59. });
  60. it('renders', () => {
  61. render(<MessageConsumerSamplesPanel />);
  62. expect(eventsStatsRequestMock).toHaveBeenCalled();
  63. expect(eventsRequestMock).toHaveBeenCalledWith(
  64. `/organizations/${organization.slug}/events/`,
  65. expect.objectContaining({
  66. method: 'GET',
  67. query: expect.objectContaining({
  68. dataset: 'spansMetrics',
  69. environment: [],
  70. field: [
  71. 'count()',
  72. 'count_op(queue.submit.celery)',
  73. 'count_op(queue.task.celery)',
  74. 'sum(span.self_time)',
  75. 'avg(span.self_time)',
  76. 'avg_if(span.self_time,span.op,queue.submit.celery)',
  77. 'avg_if(span.self_time,span.op,queue.task.celery)',
  78. ],
  79. per_page: 10,
  80. project: [],
  81. // TODO: This query filters on transaction twice because `destination` is not an implemented tag yet, and `transaction` is being used as a substitute.
  82. // Update this test to check for filtering on `destination` when available.
  83. query:
  84. 'span.op:[queue.task.celery,queue.submit.celery] transaction:event-queue transaction:sentry.tasks.store.save_event',
  85. statsPeriod: '10d',
  86. }),
  87. })
  88. );
  89. expect(screen.getByRole('table', {name: 'Span Samples'})).toBeInTheDocument();
  90. });
  91. });