groupEvents.spec.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. let attachmentsRequest;
  14. const {organization, routerContext} = initializeOrg();
  15. beforeEach(function () {
  16. request = MockApiClient.addMockResponse({
  17. url: '/issues/1/events/',
  18. body: [
  19. TestStubs.Event({
  20. eventID: '12345',
  21. id: '1',
  22. message: 'ApiException',
  23. groupID: '1',
  24. }),
  25. TestStubs.Event({
  26. crashFile: {
  27. sha1: 'sha1',
  28. name: 'name.dmp',
  29. dateCreated: '2019-05-21T18:01:48.762Z',
  30. headers: {'Content-Type': 'application/octet-stream'},
  31. id: '12345',
  32. size: 123456,
  33. type: 'event.minidump',
  34. },
  35. culprit: '',
  36. dateCreated: '2019-05-21T18:00:23Z',
  37. 'event.type': 'error',
  38. eventID: '123456',
  39. groupID: '1',
  40. id: '98654',
  41. location: 'main.js',
  42. message: 'TestException',
  43. platform: 'native',
  44. projectID: '123',
  45. tags: [{value: 'production', key: 'production'}],
  46. title: 'TestException',
  47. }),
  48. ],
  49. });
  50. browserHistory.push = jest.fn();
  51. discoverRequest = MockApiClient.addMockResponse({
  52. url: '/organizations/org-slug/events/',
  53. headers: {
  54. Link: `<https://sentry.io/api/0/issues/1/events/?limit=50&cursor=0:0:1>; rel="previous"; results="true"; cursor="0:0:1", <https://sentry.io/api/0/issues/1/events/?limit=50&cursor=0:200:0>; rel="next"; results="true"; cursor="0:200:0"`,
  55. },
  56. body: {
  57. data: [
  58. {
  59. timestamp: '2022-09-11T15:01:10+00:00',
  60. transaction: '/api',
  61. release: 'backend@1.2.3',
  62. 'transaction.duration': 1803,
  63. environment: 'prod',
  64. 'user.display': 'sentry@sentry.sentry',
  65. id: 'id123',
  66. trace: 'trace123',
  67. 'project.name': 'project123',
  68. },
  69. ],
  70. meta: {
  71. fields: {
  72. timestamp: 'date',
  73. transaction: 'string',
  74. release: 'string',
  75. 'transaction.duration': 'duration',
  76. environment: 'string',
  77. 'user.display': 'string',
  78. id: 'string',
  79. trace: 'string',
  80. 'project.name': 'string',
  81. },
  82. units: {
  83. timestamp: null,
  84. transaction: null,
  85. release: null,
  86. 'transaction.duration': 'millisecond',
  87. environment: null,
  88. 'user.display': null,
  89. id: null,
  90. trace: null,
  91. 'project.name': null,
  92. },
  93. isMetricsData: false,
  94. tips: {query: null, columns: null},
  95. },
  96. },
  97. });
  98. attachmentsRequest = MockApiClient.addMockResponse({
  99. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  100. body: [],
  101. });
  102. });
  103. afterEach(() => {
  104. MockApiClient.clearMockResponses();
  105. jest.clearAllMocks();
  106. });
  107. it('renders', function () {
  108. const wrapper = render(
  109. <GroupEvents
  110. organization={organization}
  111. api={new MockApiClient()}
  112. group={TestStubs.Group()}
  113. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  114. location={{query: {}}}
  115. />,
  116. {context: routerContext, organization}
  117. );
  118. expect(wrapper.container).toSnapshot();
  119. });
  120. it('handles search', function () {
  121. render(
  122. <GroupEvents
  123. organization={organization}
  124. api={new MockApiClient()}
  125. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  126. group={TestStubs.Group()}
  127. location={{query: {}}}
  128. />,
  129. {context: routerContext, organization}
  130. );
  131. const list = [
  132. {searchTerm: '', expectedQuery: ''},
  133. {searchTerm: 'test', expectedQuery: 'test'},
  134. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  135. ];
  136. const input = screen.getByPlaceholderText('Search events by id, message, or tags');
  137. for (const item of list) {
  138. userEvent.clear(input);
  139. userEvent.type(input, `${item.searchTerm}{enter}`);
  140. expect(browserHistory.push).toHaveBeenCalledWith(
  141. expect.objectContaining({
  142. query: {query: item.expectedQuery},
  143. })
  144. );
  145. }
  146. });
  147. it('handles environment filtering', function () {
  148. render(
  149. <GroupEvents
  150. organization={organization}
  151. api={new MockApiClient()}
  152. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  153. group={TestStubs.Group()}
  154. location={{query: {environment: ['prod', 'staging']}}}
  155. />,
  156. {context: routerContext, organization}
  157. );
  158. expect(request).toHaveBeenCalledWith(
  159. '/issues/1/events/',
  160. expect.objectContaining({
  161. query: {limit: 50, query: '', environment: ['prod', 'staging']},
  162. })
  163. );
  164. });
  165. describe('When the performance flag is enabled', () => {
  166. let org;
  167. let group;
  168. beforeEach(() => {
  169. org = initializeOrg({
  170. organization: {features: ['performance-issues-all-events-tab']},
  171. });
  172. group = TestStubs.Group();
  173. });
  174. it('renders new events table for performance', function () {
  175. group.issueCategory = 'performance';
  176. render(
  177. <GroupEvents
  178. organization={org.organization}
  179. api={new MockApiClient()}
  180. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  181. group={group}
  182. location={{query: {environment: ['prod', 'staging']}}}
  183. />,
  184. {context: routerContext, organization}
  185. );
  186. expect(discoverRequest).toHaveBeenCalledWith(
  187. '/organizations/org-slug/events/',
  188. expect.objectContaining({
  189. query: expect.objectContaining({
  190. query: 'performance.issue_ids:1 event.type:transaction ',
  191. }),
  192. })
  193. );
  194. const perfEventsColumn = screen.getByText('transaction');
  195. expect(perfEventsColumn).toBeInTheDocument();
  196. expect(request).not.toHaveBeenCalled();
  197. });
  198. it('renders event and trace link correctly', async () => {
  199. group.issueCategory = 'performance';
  200. render(
  201. <GroupEvents
  202. organization={org.organization}
  203. api={new MockApiClient()}
  204. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  205. group={group}
  206. location={{query: {environment: ['prod', 'staging']}}}
  207. />,
  208. {context: routerContext, organization}
  209. );
  210. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  211. const eventIdATag = screen.getByText('id123').closest('a');
  212. const traceIdATag = screen.getByText('trace123').closest('a');
  213. expect(eventIdATag).toHaveAttribute(
  214. 'href',
  215. '/organizations/org-slug/issues/1/events/id123/'
  216. );
  217. expect(traceIdATag).toHaveAttribute(
  218. 'href',
  219. '/organizations/org-slug/performance/trace/trace123/?'
  220. );
  221. });
  222. it('does not display attachments column with no attachments', async () => {
  223. render(
  224. <GroupEvents
  225. organization={org.organization}
  226. api={new MockApiClient()}
  227. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  228. group={group}
  229. location={{query: {environment: ['prod', 'staging']}}}
  230. />,
  231. {context: routerContext, organization}
  232. );
  233. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  234. const attachmentsColumn = screen.queryByText('attachments');
  235. expect(attachmentsColumn).not.toBeInTheDocument();
  236. expect(attachmentsRequest).toHaveBeenCalled();
  237. });
  238. it('does not display minidump column with no minidumps', async () => {
  239. render(
  240. <GroupEvents
  241. organization={org.organization}
  242. api={new MockApiClient()}
  243. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  244. group={group}
  245. location={{query: {environment: ['prod', 'staging']}}}
  246. />,
  247. {context: routerContext, organization}
  248. );
  249. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  250. const minidumpColumn = screen.queryByText('minidump');
  251. expect(minidumpColumn).not.toBeInTheDocument();
  252. });
  253. it('displays minidumps', async () => {
  254. attachmentsRequest = MockApiClient.addMockResponse({
  255. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  256. body: [
  257. {
  258. id: 'id123',
  259. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  260. headers: {
  261. 'Content-Type': 'application/octet-stream',
  262. },
  263. mimetype: 'application/octet-stream',
  264. size: 1294340,
  265. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  266. dateCreated: '2022-09-28T09:04:38.659307Z',
  267. type: 'event.minidump',
  268. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  269. },
  270. ],
  271. });
  272. render(
  273. <GroupEvents
  274. organization={org.organization}
  275. api={new MockApiClient()}
  276. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  277. group={group}
  278. location={{query: {environment: ['prod', 'staging']}}}
  279. />,
  280. {context: routerContext, organization}
  281. );
  282. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  283. const minidumpColumn = screen.queryByText('minidump');
  284. expect(minidumpColumn).toBeInTheDocument();
  285. });
  286. it('does not display attachments but displays minidump', async () => {
  287. attachmentsRequest = MockApiClient.addMockResponse({
  288. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  289. body: [
  290. {
  291. id: 'id123',
  292. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  293. headers: {
  294. 'Content-Type': 'application/octet-stream',
  295. },
  296. mimetype: 'application/octet-stream',
  297. size: 1294340,
  298. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  299. dateCreated: '2022-09-28T09:04:38.659307Z',
  300. type: 'event.minidump',
  301. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  302. },
  303. ],
  304. });
  305. render(
  306. <GroupEvents
  307. organization={org.organization}
  308. api={new MockApiClient()}
  309. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  310. group={group}
  311. location={{query: {environment: ['prod', 'staging']}}}
  312. />,
  313. {context: routerContext, organization}
  314. );
  315. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  316. const attachmentsColumn = screen.queryByText('attachments');
  317. const minidumpColumn = screen.queryByText('minidump');
  318. expect(attachmentsColumn).not.toBeInTheDocument();
  319. expect(minidumpColumn).toBeInTheDocument();
  320. expect(attachmentsRequest).toHaveBeenCalled();
  321. });
  322. it('renders new events table if error', function () {
  323. render(
  324. <GroupEvents
  325. organization={org.organization}
  326. api={new MockApiClient()}
  327. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  328. group={group}
  329. location={{query: {environment: ['prod', 'staging']}}}
  330. />,
  331. {context: routerContext, organization}
  332. );
  333. expect(discoverRequest).toHaveBeenCalledWith(
  334. '/organizations/org-slug/events/',
  335. expect.objectContaining({
  336. query: expect.objectContaining({
  337. query: 'issue.id:1 ',
  338. field: expect.not.arrayContaining(['attachments', 'minidump']),
  339. }),
  340. })
  341. );
  342. const perfEventsColumn = screen.getByText('transaction');
  343. expect(perfEventsColumn).toBeInTheDocument();
  344. });
  345. it('removes sort if unsupported by the events table', function () {
  346. render(
  347. <GroupEvents
  348. organization={org.organization}
  349. api={new MockApiClient()}
  350. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  351. group={group}
  352. location={{query: {environment: ['prod', 'staging'], sort: 'user'}}}
  353. />,
  354. {context: routerContext, organization}
  355. );
  356. expect(discoverRequest).toHaveBeenCalledWith(
  357. '/organizations/org-slug/events/',
  358. expect.objectContaining({query: expect.not.objectContaining({sort: 'user'})})
  359. );
  360. });
  361. it('shows discover query error message', async () => {
  362. discoverRequest = MockApiClient.addMockResponse({
  363. url: '/organizations/org-slug/events/',
  364. statusCode: 500,
  365. body: {
  366. detail: 'Internal Error',
  367. errorId: '69ab396e73704cdba9342ff8dcd59795',
  368. },
  369. });
  370. render(
  371. <GroupEvents
  372. organization={org.organization}
  373. api={new MockApiClient()}
  374. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  375. group={group}
  376. location={{query: {environment: ['prod', 'staging']}}}
  377. />,
  378. {context: routerContext, organization}
  379. );
  380. await waitForElementToBeRemoved(document.querySelector('div.loading-indicator'));
  381. expect(screen.getByTestId('loading-error')).toHaveTextContent('Internal Error');
  382. });
  383. });
  384. it('does not renders new events table if error', function () {
  385. const org = initializeOrg();
  386. const group = TestStubs.Group();
  387. render(
  388. <GroupEvents
  389. organization={org.organization}
  390. api={new MockApiClient()}
  391. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  392. group={group}
  393. location={{query: {environment: ['prod', 'staging']}}}
  394. />,
  395. {context: routerContext, organization}
  396. );
  397. const perfEventsColumn = screen.queryByText('transaction');
  398. expect(perfEventsColumn).not.toBeInTheDocument();
  399. });
  400. });