traceTimeline.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  7. import {TraceTimeline} from './traceTimeline';
  8. import type {TraceEventResponse} from './useTraceTimelineEvents';
  9. jest.mock('sentry/utils/routeAnalytics/useRouteAnalyticsParams');
  10. describe('TraceTimeline', () => {
  11. const organization = OrganizationFixture({features: ['issues-trace-timeline']});
  12. const event = EventFixture({
  13. contexts: {
  14. trace: {
  15. trace_id: '123',
  16. },
  17. },
  18. });
  19. const project = ProjectFixture();
  20. const issuePlatformBody: TraceEventResponse = {
  21. data: [
  22. {
  23. timestamp: '2024-01-24T09:09:03+00:00',
  24. 'issue.id': 1000,
  25. project: project.slug,
  26. 'project.name': project.name,
  27. title: 'Slow DB Query',
  28. id: 'abc',
  29. issue: 'SENTRY-ABC1',
  30. transaction: '/api/slow/',
  31. },
  32. ],
  33. meta: {fields: {}, units: {}},
  34. };
  35. const discoverBody: TraceEventResponse = {
  36. data: [
  37. {
  38. timestamp: '2024-01-23T22:11:42+00:00',
  39. 'issue.id': 4909507143,
  40. project: project.slug,
  41. 'project.name': project.name,
  42. title: 'AttributeError: Something Failed',
  43. id: event.id,
  44. issue: 'SENTRY-2EYS',
  45. transaction: 'important.task',
  46. 'event.type': 'error',
  47. 'stack.function': ['important.task', 'task.run'],
  48. },
  49. ],
  50. meta: {fields: {}, units: {}},
  51. };
  52. beforeEach(() => {
  53. ProjectsStore.loadInitialData([project]);
  54. jest.clearAllMocks();
  55. });
  56. it('renders items and highlights the current event', async () => {
  57. MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/events/`,
  59. body: issuePlatformBody,
  60. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  61. });
  62. MockApiClient.addMockResponse({
  63. url: `/organizations/${organization.slug}/events/`,
  64. body: discoverBody,
  65. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  66. });
  67. render(<TraceTimeline event={event} />, {organization});
  68. expect(await screen.findByLabelText('Current Event')).toBeInTheDocument();
  69. await userEvent.hover(screen.getByTestId('trace-timeline-tooltip-1'));
  70. expect(await screen.findByText('You are here')).toBeInTheDocument();
  71. expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
  72. trace_timeline_status: 'shown',
  73. });
  74. });
  75. it('displays nothing if the only event is the current event', async () => {
  76. MockApiClient.addMockResponse({
  77. url: `/organizations/${organization.slug}/events/`,
  78. body: {
  79. data: [],
  80. meta: {fields: {}, units: {}},
  81. },
  82. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  83. });
  84. MockApiClient.addMockResponse({
  85. url: `/organizations/${organization.slug}/events/`,
  86. body: discoverBody,
  87. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  88. });
  89. render(<TraceTimeline event={event} />, {organization});
  90. expect(await screen.findByTestId('trace-timeline-empty')).toBeInTheDocument();
  91. expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
  92. trace_timeline_status: 'empty',
  93. });
  94. });
  95. it('displays nothing if there are no events', async () => {
  96. MockApiClient.addMockResponse({
  97. url: `/organizations/${organization.slug}/events/`,
  98. body: {
  99. data: [],
  100. meta: {fields: {}, units: {}},
  101. },
  102. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  103. });
  104. MockApiClient.addMockResponse({
  105. url: `/organizations/${organization.slug}/events/`,
  106. body: {
  107. data: [],
  108. meta: {fields: {}, units: {}},
  109. },
  110. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  111. });
  112. render(<TraceTimeline event={event} />, {organization});
  113. expect(await screen.findByTestId('trace-timeline-empty')).toBeInTheDocument();
  114. expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
  115. trace_timeline_status: 'empty',
  116. });
  117. });
  118. it('shows seconds for very short timelines', async () => {
  119. MockApiClient.addMockResponse({
  120. url: `/organizations/${organization.slug}/events/`,
  121. body: issuePlatformBody,
  122. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  123. });
  124. MockApiClient.addMockResponse({
  125. url: `/organizations/${organization.slug}/events/`,
  126. body: {
  127. data: [],
  128. meta: {fields: {}, units: {}},
  129. },
  130. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  131. });
  132. render(<TraceTimeline event={event} />, {organization});
  133. // Checking for the presence of seconds
  134. expect(await screen.findAllByText(/\d{1,2}:\d{2}:\d{2} (AM|PM)/)).toHaveLength(5);
  135. });
  136. });