traceTimeline.spec.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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();
  12. const event = EventFixture({
  13. dateCreated: '2024-01-24T09:09:03+00:00',
  14. contexts: {
  15. trace: {
  16. trace_id: '123',
  17. },
  18. },
  19. });
  20. const project = ProjectFixture();
  21. const emptyBody: TraceEventResponse = {data: [], meta: {fields: {}, units: {}}};
  22. const issuePlatformBody: TraceEventResponse = {
  23. data: [
  24. {
  25. timestamp: '2024-01-24T09:09:03+00:00',
  26. 'issue.id': 1000,
  27. project: project.slug,
  28. 'project.name': project.name,
  29. title: 'Slow DB Query',
  30. id: 'abc',
  31. transaction: '/api/slow/',
  32. },
  33. ],
  34. meta: {fields: {}, units: {}},
  35. };
  36. const discoverBody: TraceEventResponse = {
  37. data: [
  38. {
  39. timestamp: '2024-01-23T22:11:42+00:00',
  40. 'issue.id': 4909507143,
  41. project: project.slug,
  42. 'project.name': project.name,
  43. title: 'AttributeError: Something Failed',
  44. id: event.id,
  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: emptyBody,
  79. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  80. });
  81. MockApiClient.addMockResponse({
  82. url: `/organizations/${organization.slug}/events/`,
  83. body: discoverBody,
  84. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  85. });
  86. render(<TraceTimeline event={event} />, {organization});
  87. expect(await screen.findByTestId('trace-timeline-empty')).toBeInTheDocument();
  88. expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
  89. trace_timeline_status: 'empty',
  90. });
  91. });
  92. it('displays nothing if there are no events', async () => {
  93. MockApiClient.addMockResponse({
  94. url: `/organizations/${organization.slug}/events/`,
  95. body: emptyBody,
  96. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: `/organizations/${organization.slug}/events/`,
  100. body: emptyBody,
  101. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  102. });
  103. render(<TraceTimeline event={event} />, {organization});
  104. expect(await screen.findByTestId('trace-timeline-empty')).toBeInTheDocument();
  105. expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
  106. trace_timeline_status: 'empty',
  107. });
  108. });
  109. it('shows seconds for very short timelines', async () => {
  110. MockApiClient.addMockResponse({
  111. url: `/organizations/${organization.slug}/events/`,
  112. body: issuePlatformBody,
  113. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  114. });
  115. MockApiClient.addMockResponse({
  116. url: `/organizations/${organization.slug}/events/`,
  117. body: emptyBody,
  118. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  119. });
  120. render(<TraceTimeline event={event} />, {organization});
  121. // Checking for the presence of seconds
  122. expect(await screen.findAllByText(/\d{1,2}:\d{2}:\d{2} (AM|PM)/)).toHaveLength(5);
  123. });
  124. it('adds the current event if not in the api response', async () => {
  125. MockApiClient.addMockResponse({
  126. url: `/organizations/${organization.slug}/events/`,
  127. body: issuePlatformBody,
  128. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  129. });
  130. MockApiClient.addMockResponse({
  131. url: `/organizations/${organization.slug}/events/`,
  132. body: emptyBody,
  133. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  134. });
  135. render(<TraceTimeline event={event} />, {organization});
  136. expect(await screen.findByLabelText('Current Event')).toBeInTheDocument();
  137. });
  138. });