groupEvents.spec.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. userEvent.clear(input);
  135. userEvent.type(input, `${item.searchTerm}{enter}`);
  136. expect(browserHistory.push).toHaveBeenCalledWith(
  137. expect.objectContaining({
  138. query: {query: item.expectedQuery},
  139. })
  140. );
  141. }
  142. });
  143. it('handles environment filtering', () => {
  144. render(
  145. <GroupEvents
  146. {...baseProps}
  147. organization={organization}
  148. location={{...location, query: {environment: ['prod', 'staging']}}}
  149. />,
  150. {context: routerContext, organization}
  151. );
  152. expect(requests.discover).toHaveBeenCalledWith(
  153. '/organizations/org-slug/events/',
  154. expect.objectContaining({
  155. query: expect.objectContaining({environment: ['prod', 'staging']}),
  156. })
  157. );
  158. });
  159. it('renders events table for performance issue', () => {
  160. const group = TestStubs.Group();
  161. group.issueCategory = 'performance';
  162. render(
  163. <GroupEvents
  164. {...baseProps}
  165. group={group}
  166. organization={organization}
  167. location={{...location, query: {environment: ['prod', 'staging']}}}
  168. />,
  169. {context: routerContext, organization}
  170. );
  171. expect(requests.discover).toHaveBeenCalledWith(
  172. '/organizations/org-slug/events/',
  173. expect.objectContaining({
  174. query: expect.objectContaining({
  175. query: 'performance.issue_ids:1 event.type:transaction ',
  176. }),
  177. })
  178. );
  179. const perfEventsColumn = screen.getByText('transaction');
  180. expect(perfEventsColumn).toBeInTheDocument();
  181. });
  182. it('renders event and trace link correctly', async () => {
  183. const group = TestStubs.Group();
  184. group.issueCategory = 'performance';
  185. render(
  186. <GroupEvents
  187. {...baseProps}
  188. group={group}
  189. organization={organization}
  190. location={{...location, query: {environment: ['prod', 'staging']}}}
  191. />,
  192. {context: routerContext, organization}
  193. );
  194. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  195. const eventIdATag = screen.getByText('id123').closest('a');
  196. expect(eventIdATag).toHaveAttribute(
  197. 'href',
  198. '/organizations/org-slug/issues/1/events/id123/'
  199. );
  200. });
  201. it('does not make attachments request, when feature not enabled', async () => {
  202. const org = initializeOrg();
  203. render(
  204. <GroupEvents
  205. {...baseProps}
  206. organization={org.organization}
  207. location={{...location, query: {environment: ['prod', 'staging']}}}
  208. />,
  209. {context: routerContext, organization}
  210. );
  211. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  212. const attachmentsColumn = screen.queryByText('attachments');
  213. expect(attachmentsColumn).not.toBeInTheDocument();
  214. expect(requests.attachments).not.toHaveBeenCalled();
  215. });
  216. it('does not display attachments column with no attachments', async () => {
  217. render(
  218. <GroupEvents
  219. {...baseProps}
  220. organization={organization}
  221. location={{...location, query: {environment: ['prod', 'staging']}}}
  222. />,
  223. {context: routerContext, organization}
  224. );
  225. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  226. const attachmentsColumn = screen.queryByText('attachments');
  227. expect(attachmentsColumn).not.toBeInTheDocument();
  228. expect(requests.attachments).toHaveBeenCalled();
  229. });
  230. it('does not display minidump column with no minidumps', async () => {
  231. render(
  232. <GroupEvents
  233. {...baseProps}
  234. organization={organization}
  235. location={{...location, query: {environment: ['prod', 'staging']}}}
  236. />,
  237. {context: routerContext, organization}
  238. );
  239. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  240. const minidumpColumn = screen.queryByText('minidump');
  241. expect(minidumpColumn).not.toBeInTheDocument();
  242. });
  243. it('displays minidumps', async () => {
  244. requests.attachments = MockApiClient.addMockResponse({
  245. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  246. body: [
  247. {
  248. id: 'id123',
  249. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  250. headers: {
  251. 'Content-Type': 'application/octet-stream',
  252. },
  253. mimetype: 'application/octet-stream',
  254. size: 1294340,
  255. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  256. dateCreated: '2022-09-28T09:04:38.659307Z',
  257. type: 'event.minidump',
  258. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  259. },
  260. ],
  261. });
  262. render(
  263. <GroupEvents
  264. {...baseProps}
  265. organization={organization}
  266. location={{...location, query: {environment: ['prod', 'staging']}}}
  267. />,
  268. {context: routerContext, organization}
  269. );
  270. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  271. const minidumpColumn = screen.queryByText('minidump');
  272. expect(minidumpColumn).toBeInTheDocument();
  273. });
  274. it('does not display attachments but displays minidump', async () => {
  275. requests.attachments = MockApiClient.addMockResponse({
  276. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  277. body: [
  278. {
  279. id: 'id123',
  280. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  281. headers: {
  282. 'Content-Type': 'application/octet-stream',
  283. },
  284. mimetype: 'application/octet-stream',
  285. size: 1294340,
  286. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  287. dateCreated: '2022-09-28T09:04:38.659307Z',
  288. type: 'event.minidump',
  289. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  290. },
  291. ],
  292. });
  293. render(
  294. <GroupEvents
  295. {...baseProps}
  296. organization={organization}
  297. location={{...location, query: {environment: ['prod', 'staging']}}}
  298. />,
  299. {context: routerContext, organization}
  300. );
  301. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  302. const attachmentsColumn = screen.queryByText('attachments');
  303. const minidumpColumn = screen.queryByText('minidump');
  304. expect(attachmentsColumn).not.toBeInTheDocument();
  305. expect(minidumpColumn).toBeInTheDocument();
  306. expect(requests.attachments).toHaveBeenCalled();
  307. });
  308. it('renders events table for error', () => {
  309. render(
  310. <GroupEvents
  311. {...baseProps}
  312. organization={organization}
  313. location={{...location, query: {environment: ['prod', 'staging']}}}
  314. />,
  315. {context: routerContext, organization}
  316. );
  317. expect(requests.discover).toHaveBeenCalledWith(
  318. '/organizations/org-slug/events/',
  319. expect.objectContaining({
  320. query: expect.objectContaining({
  321. query: 'issue.id:1 ',
  322. field: expect.not.arrayContaining(['attachments', 'minidump']),
  323. }),
  324. })
  325. );
  326. const perfEventsColumn = screen.getByText('transaction');
  327. expect(perfEventsColumn).toBeInTheDocument();
  328. });
  329. it('removes sort if unsupported by the events table', () => {
  330. render(
  331. <GroupEvents
  332. {...baseProps}
  333. organization={organization}
  334. location={{...location, query: {environment: ['prod', 'staging'], sort: 'user'}}}
  335. />,
  336. {context: routerContext, organization}
  337. );
  338. expect(requests.discover).toHaveBeenCalledWith(
  339. '/organizations/org-slug/events/',
  340. expect.objectContaining({query: expect.not.objectContaining({sort: 'user'})})
  341. );
  342. });
  343. it('only request for a single projectId', () => {
  344. const group = TestStubs.Group();
  345. render(
  346. <GroupEvents
  347. {...baseProps}
  348. group={group}
  349. organization={organization}
  350. location={{
  351. ...location,
  352. query: {
  353. environment: ['prod', 'staging'],
  354. sort: 'user',
  355. project: [group.project.id, '456'],
  356. },
  357. }}
  358. />,
  359. {context: routerContext, organization}
  360. );
  361. expect(requests.discover).toHaveBeenCalledWith(
  362. '/organizations/org-slug/events/',
  363. expect.objectContaining({
  364. query: expect.objectContaining({project: [group.project.id]}),
  365. })
  366. );
  367. });
  368. it('shows discover query error message', async () => {
  369. requests.discover = MockApiClient.addMockResponse({
  370. url: '/organizations/org-slug/events/',
  371. statusCode: 500,
  372. body: {
  373. detail: 'Internal Error',
  374. errorId: '69ab396e73704cdba9342ff8dcd59795',
  375. },
  376. });
  377. render(
  378. <GroupEvents
  379. {...baseProps}
  380. organization={organization}
  381. location={{...location, query: {environment: ['prod', 'staging']}}}
  382. />,
  383. {context: routerContext, organization}
  384. );
  385. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  386. expect(screen.getByTestId('loading-error')).toHaveTextContent('Internal Error');
  387. });
  388. it('requests for backend columns if backend project', async () => {
  389. const group = TestStubs.Group();
  390. group.project.platform = 'node-express';
  391. render(
  392. <GroupEvents
  393. {...baseProps}
  394. group={group}
  395. organization={organization}
  396. location={{...location, query: {environment: ['prod', 'staging']}}}
  397. />,
  398. {context: routerContext, organization}
  399. );
  400. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  401. expect(requests.discover).toHaveBeenCalledWith(
  402. '/organizations/org-slug/events/',
  403. expect.objectContaining({
  404. query: expect.objectContaining({
  405. field: expect.arrayContaining(['url', 'runtime']),
  406. }),
  407. })
  408. );
  409. expect(requests.discover).toHaveBeenCalledWith(
  410. '/organizations/org-slug/events/',
  411. expect.objectContaining({
  412. query: expect.objectContaining({
  413. field: expect.not.arrayContaining(['browser']),
  414. }),
  415. })
  416. );
  417. });
  418. });