groupEvents.spec.jsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {
  4. render,
  5. screen,
  6. userEvent,
  7. waitForElementToBeRemoved,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {GroupEvents} from 'sentry/views/organizationGroupDetails/groupEvents';
  10. describe('groupEvents', function () {
  11. let request;
  12. let discoverRequest;
  13. const {organization, routerContext} = initializeOrg();
  14. beforeEach(function () {
  15. request = MockApiClient.addMockResponse({
  16. url: '/issues/1/events/',
  17. body: [
  18. TestStubs.Event({
  19. eventID: '12345',
  20. id: '1',
  21. message: 'ApiException',
  22. groupID: '1',
  23. }),
  24. TestStubs.Event({
  25. crashFile: {
  26. sha1: 'sha1',
  27. name: 'name.dmp',
  28. dateCreated: '2019-05-21T18:01:48.762Z',
  29. headers: {'Content-Type': 'application/octet-stream'},
  30. id: '12345',
  31. size: 123456,
  32. type: 'event.minidump',
  33. },
  34. culprit: '',
  35. dateCreated: '2019-05-21T18:00:23Z',
  36. 'event.type': 'error',
  37. eventID: '123456',
  38. groupID: '1',
  39. id: '98654',
  40. location: 'main.js',
  41. message: 'TestException',
  42. platform: 'native',
  43. projectID: '123',
  44. tags: [{value: 'production', key: 'production'}],
  45. title: 'TestException',
  46. }),
  47. ],
  48. });
  49. browserHistory.push = jest.fn();
  50. discoverRequest = MockApiClient.addMockResponse({
  51. url: '/organizations/org-slug/events/',
  52. body: {
  53. data: [
  54. {
  55. timestamp: '2022-09-11T15:01:10+00:00',
  56. transaction: '/api',
  57. release: 'backend@1.2.3',
  58. 'transaction.duration': 1803,
  59. environment: 'prod',
  60. 'user.display': 'sentry@sentry.sentry',
  61. id: 'id123',
  62. trace: 'trace123',
  63. 'project.name': 'project123',
  64. },
  65. ],
  66. meta: {
  67. fields: {
  68. timestamp: 'date',
  69. transaction: 'string',
  70. release: 'string',
  71. 'transaction.duration': 'duration',
  72. environment: 'string',
  73. 'user.display': 'string',
  74. id: 'string',
  75. trace: 'string',
  76. 'project.name': 'string',
  77. },
  78. units: {
  79. timestamp: null,
  80. transaction: null,
  81. release: null,
  82. 'transaction.duration': 'millisecond',
  83. environment: null,
  84. 'user.display': null,
  85. id: null,
  86. trace: null,
  87. 'project.name': null,
  88. },
  89. isMetricsData: false,
  90. tips: {query: null, columns: null},
  91. },
  92. },
  93. });
  94. });
  95. afterEach(() => {
  96. MockApiClient.clearMockResponses();
  97. jest.clearAllMocks();
  98. });
  99. it('renders', function () {
  100. const wrapper = render(
  101. <GroupEvents
  102. organization={organization}
  103. api={new MockApiClient()}
  104. group={TestStubs.Group()}
  105. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  106. location={{query: {}}}
  107. />,
  108. {context: routerContext, organization}
  109. );
  110. expect(wrapper.container).toSnapshot();
  111. });
  112. it('handles search', function () {
  113. render(
  114. <GroupEvents
  115. organization={organization}
  116. api={new MockApiClient()}
  117. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  118. group={TestStubs.Group()}
  119. location={{query: {}}}
  120. />,
  121. {context: routerContext, organization}
  122. );
  123. const list = [
  124. {searchTerm: '', expectedQuery: ''},
  125. {searchTerm: 'test', expectedQuery: 'test'},
  126. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  127. ];
  128. const input = screen.getByPlaceholderText('Search events by id, message, or tags');
  129. for (const item of list) {
  130. userEvent.clear(input);
  131. userEvent.type(input, `${item.searchTerm}{enter}`);
  132. expect(browserHistory.push).toHaveBeenCalledWith(
  133. expect.objectContaining({
  134. query: {query: item.expectedQuery},
  135. })
  136. );
  137. }
  138. });
  139. it('handles environment filtering', function () {
  140. render(
  141. <GroupEvents
  142. organization={organization}
  143. api={new MockApiClient()}
  144. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  145. group={TestStubs.Group()}
  146. location={{query: {environment: ['prod', 'staging']}}}
  147. />,
  148. {context: routerContext, organization}
  149. );
  150. expect(request).toHaveBeenCalledWith(
  151. '/issues/1/events/',
  152. expect.objectContaining({
  153. query: {limit: 50, query: '', environment: ['prod', 'staging']},
  154. })
  155. );
  156. });
  157. describe('When the performance flag is enabled', () => {
  158. let org;
  159. let group;
  160. beforeEach(() => {
  161. org = initializeOrg({
  162. organization: {features: ['performance-issues-all-events-tab']},
  163. });
  164. group = TestStubs.Group();
  165. });
  166. it('renders new events table for performance', function () {
  167. group.issueCategory = 'performance';
  168. render(
  169. <GroupEvents
  170. organization={org.organization}
  171. api={new MockApiClient()}
  172. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  173. group={group}
  174. location={{query: {environment: ['prod', 'staging']}}}
  175. />,
  176. {context: routerContext, organization}
  177. );
  178. expect(discoverRequest).toHaveBeenCalledWith(
  179. '/organizations/org-slug/events/',
  180. expect.objectContaining({
  181. query: expect.objectContaining({query: 'performance.issue_ids:1 '}),
  182. })
  183. );
  184. const perfEventsColumn = screen.getByText('transaction');
  185. expect(perfEventsColumn).toBeInTheDocument();
  186. });
  187. it('renders event and trace link correctly', async () => {
  188. group.issueCategory = 'performance';
  189. render(
  190. <GroupEvents
  191. organization={org.organization}
  192. api={new MockApiClient()}
  193. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  194. group={group}
  195. location={{query: {environment: ['prod', 'staging']}}}
  196. />,
  197. {context: routerContext, organization}
  198. );
  199. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  200. const eventIdATag = screen.getByText('id123').closest('a');
  201. const traceIdATag = screen.getByText('trace123').closest('a');
  202. expect(eventIdATag).toHaveAttribute(
  203. 'href',
  204. '/organizations/org-slug/issues/1/events/id123/'
  205. );
  206. expect(traceIdATag).toHaveAttribute(
  207. 'href',
  208. '/organizations/org-slug/performance/trace/trace123/?'
  209. );
  210. });
  211. it('renders new events table if error', function () {
  212. render(
  213. <GroupEvents
  214. organization={org.organization}
  215. api={new MockApiClient()}
  216. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  217. group={group}
  218. location={{query: {environment: ['prod', 'staging']}}}
  219. />,
  220. {context: routerContext, organization}
  221. );
  222. expect(discoverRequest).toHaveBeenCalledWith(
  223. '/organizations/org-slug/events/',
  224. expect.objectContaining({query: expect.objectContaining({query: 'issue.id:1 '})})
  225. );
  226. const perfEventsColumn = screen.getByText('transaction');
  227. expect(perfEventsColumn).toBeInTheDocument();
  228. });
  229. });
  230. it('does not renders new events table if error', function () {
  231. const org = initializeOrg();
  232. const group = TestStubs.Group();
  233. render(
  234. <GroupEvents
  235. organization={org.organization}
  236. api={new MockApiClient()}
  237. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  238. group={group}
  239. location={{query: {environment: ['prod', 'staging']}}}
  240. />,
  241. {context: routerContext, organization}
  242. );
  243. const perfEventsColumn = screen.queryByText('transaction');
  244. expect(perfEventsColumn).not.toBeInTheDocument();
  245. });
  246. });