issueFieldRenderers.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import GroupStore from 'sentry/stores/groupStore';
  4. import MemberListStore from 'sentry/stores/memberListStore';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import {getIssueFieldRenderer} from 'sentry/utils/dashboards/issueFieldRenderers';
  7. describe('getIssueFieldRenderer', function () {
  8. let location, context, project, organization, data, user;
  9. beforeEach(function () {
  10. context = initializeOrg({
  11. organization,
  12. router: {},
  13. project: TestStubs.Project(),
  14. projects: [TestStubs.Project()],
  15. });
  16. organization = context.organization;
  17. project = context.project;
  18. act(() => ProjectsStore.loadInitialData([project]));
  19. user = 'email:text@example.com';
  20. location = {
  21. pathname: '/events',
  22. query: {},
  23. };
  24. data = {
  25. id: '1',
  26. team_key_transaction: 1,
  27. title: 'ValueError: something bad',
  28. transaction: 'api.do_things',
  29. boolValue: 1,
  30. numeric: 1.23,
  31. createdAt: new Date(2019, 9, 3, 12, 13, 14),
  32. url: '/example',
  33. project: project.slug,
  34. release: 'F2520C43515BD1F0E8A6BD46233324641A370BF6',
  35. user,
  36. 'span_ops_breakdown.relative': '',
  37. 'spans.browser': 10,
  38. 'spans.db': 30,
  39. 'spans.http': 15,
  40. 'spans.resource': 20,
  41. 'spans.total.time': 75,
  42. 'transaction.duration': 75,
  43. 'timestamp.to_day': '2021-09-05T00:00:00+00:00',
  44. lifetimeEvents: 10000,
  45. filteredEvents: 3000,
  46. events: 6000,
  47. period: '7d',
  48. links: ['<a href="sentry.io">ANNO-123</a>'],
  49. };
  50. MockApiClient.addMockResponse({
  51. url: `/organizations/${organization.slug}/projects/${project.slug}/`,
  52. body: project,
  53. });
  54. MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/key-transactions/`,
  56. method: 'POST',
  57. });
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/key-transactions/`,
  60. method: 'DELETE',
  61. });
  62. });
  63. describe('Issue fields', () => {
  64. it('can render assignee', async function () {
  65. MemberListStore.loadInitialData([
  66. TestStubs.User({
  67. name: 'Test User',
  68. email: 'test@sentry.io',
  69. avatar: {
  70. avatarType: 'letter_avatar',
  71. avatarUuid: null,
  72. },
  73. }),
  74. ]);
  75. const group = TestStubs.Group({project});
  76. GroupStore.add([
  77. {
  78. ...group,
  79. owners: [{owner: 'user:1', type: 'suspectCommit'}],
  80. assignedTo: {
  81. email: 'test@sentry.io',
  82. type: 'user',
  83. id: '1',
  84. name: 'Test User',
  85. },
  86. },
  87. ]);
  88. const renderer = getIssueFieldRenderer('assignee');
  89. render(
  90. renderer!(data, {
  91. location,
  92. organization,
  93. }) as React.ReactElement
  94. );
  95. expect(screen.getByText('TU')).toBeInTheDocument();
  96. userEvent.hover(screen.getByText('TU'));
  97. expect(await screen.findByText('Assigned to')).toBeInTheDocument();
  98. expect(screen.getByText('Test User')).toBeInTheDocument();
  99. expect(screen.getByText('Based on')).toBeInTheDocument();
  100. expect(screen.getByText('commit data')).toBeInTheDocument();
  101. });
  102. it('can render counts', async function () {
  103. const renderer = getIssueFieldRenderer('events');
  104. render(
  105. renderer!(data, {
  106. location,
  107. organization,
  108. }) as React.ReactElement
  109. );
  110. expect(screen.getByText('3k')).toBeInTheDocument();
  111. expect(screen.getByText('6k')).toBeInTheDocument();
  112. userEvent.hover(screen.getByText('3k'));
  113. expect(await screen.findByText('Total in last 7 days')).toBeInTheDocument();
  114. expect(screen.getByText('Matching search filters')).toBeInTheDocument();
  115. expect(screen.getByText('Since issue began')).toBeInTheDocument();
  116. });
  117. });
  118. it('can render links', function () {
  119. const renderer = getIssueFieldRenderer('links');
  120. render(
  121. renderer!(data, {
  122. location,
  123. organization,
  124. }) as React.ReactElement
  125. );
  126. expect(screen.getByText('ANNO-123')).toBeInTheDocument();
  127. });
  128. it('can render multiple links', function () {
  129. const renderer = getIssueFieldRenderer('links');
  130. render(
  131. renderer!(
  132. {
  133. data,
  134. ...{
  135. links: [
  136. '<a href="sentry.io">ANNO-123</a>',
  137. '<a href="sentry.io">ANNO-456</a>',
  138. ],
  139. },
  140. },
  141. {
  142. location,
  143. organization,
  144. }
  145. ) as React.ReactElement
  146. );
  147. expect(screen.getByText('ANNO-123')).toBeInTheDocument();
  148. expect(screen.getByText('ANNO-456')).toBeInTheDocument();
  149. });
  150. });