spansTab.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  3. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  4. import {trackAnalytics} from 'sentry/utils/analytics';
  5. import {SpansTabContent} from 'sentry/views/explore/spans/spansTab';
  6. jest.mock('sentry/utils/analytics');
  7. describe('SpansTabContent', function () {
  8. const {organization, project, router} = initializeOrg({
  9. organization: {
  10. features: ['visibility-explore-rpc'],
  11. },
  12. });
  13. beforeEach(function () {
  14. // without this the `CompactSelect` component errors with a bunch of async updates
  15. jest.spyOn(console, 'error').mockImplementation();
  16. PageFiltersStore.init();
  17. PageFiltersStore.onInitializeUrlState(
  18. {
  19. projects: [project].map(p => parseInt(p.id, 10)),
  20. environments: [],
  21. datetime: {
  22. period: '7d',
  23. start: null,
  24. end: null,
  25. utc: null,
  26. },
  27. },
  28. new Set()
  29. );
  30. MockApiClient.addMockResponse({
  31. url: `/subscriptions/${organization.slug}/`,
  32. method: 'GET',
  33. body: {},
  34. });
  35. MockApiClient.addMockResponse({
  36. url: `/organizations/${organization.slug}/recent-searches/`,
  37. method: 'GET',
  38. body: {},
  39. });
  40. MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/spans/fields/`,
  42. method: 'GET',
  43. body: [],
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/events/`,
  47. method: 'GET',
  48. body: {},
  49. });
  50. MockApiClient.addMockResponse({
  51. url: `/organizations/${organization.slug}/events-stats/`,
  52. method: 'GET',
  53. body: {},
  54. });
  55. MockApiClient.addMockResponse({
  56. url: `/organizations/${organization.slug}/traces/`,
  57. method: 'GET',
  58. body: {},
  59. });
  60. });
  61. it('should fire analytics once per change', async function () {
  62. render(
  63. <SpansTabContent
  64. defaultPeriod="7d"
  65. maxPickableDays={7}
  66. relativeOptions={{
  67. '1h': 'Last hour',
  68. '24h': 'Last 24 hours',
  69. '7d': 'Last 7 days',
  70. }}
  71. />,
  72. {disableRouterMocks: true, router, organization}
  73. );
  74. await screen.findByText(/No spans found/);
  75. expect(trackAnalytics).toHaveBeenCalledTimes(1);
  76. expect(trackAnalytics).toHaveBeenCalledWith(
  77. 'trace.explorer.metadata',
  78. expect.objectContaining({
  79. result_mode: 'span samples',
  80. })
  81. );
  82. (trackAnalytics as jest.Mock).mockClear();
  83. await userEvent.click(await screen.findByText('Trace Samples'));
  84. await screen.findByText(/No trace results found/);
  85. expect(trackAnalytics).toHaveBeenCalledTimes(1);
  86. expect(trackAnalytics).toHaveBeenCalledWith(
  87. 'trace.explorer.metadata',
  88. expect.objectContaining({
  89. result_mode: 'trace samples',
  90. })
  91. );
  92. (trackAnalytics as jest.Mock).mockClear();
  93. await userEvent.click(
  94. within(screen.getByTestId('section-mode')).getByRole('radio', {name: 'Aggregates'})
  95. );
  96. await screen.findByText(/No spans found/);
  97. expect(trackAnalytics).toHaveBeenCalledTimes(1);
  98. expect(trackAnalytics).toHaveBeenCalledWith(
  99. 'trace.explorer.metadata',
  100. expect.objectContaining({
  101. result_mode: 'aggregates',
  102. })
  103. );
  104. });
  105. });