groupEvents.spec.tsx 14 KB

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