index.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {ALL_VIEWS, DEFAULT_EVENT_VIEW} from 'sentry/views/discover/data';
  7. import EventDetails from 'sentry/views/discover/eventDetails';
  8. describe('Discover > EventDetails', function () {
  9. const allEventsView = EventView.fromSavedQuery(DEFAULT_EVENT_VIEW);
  10. const errorsView = EventView.fromSavedQuery(
  11. ALL_VIEWS.find(view => view.name === 'Errors by Title')!
  12. );
  13. beforeEach(function () {
  14. act(() => ProjectsStore.loadInitialData([TestStubs.Project()]));
  15. MockApiClient.addMockResponse({
  16. url: '/organizations/org-slug/projects/',
  17. body: [],
  18. });
  19. MockApiClient.addMockResponse({
  20. url: '/organizations/org-slug/discover/',
  21. body: {
  22. meta: {
  23. id: 'string',
  24. title: 'string',
  25. 'project.name': 'string',
  26. timestamp: 'date',
  27. },
  28. data: [
  29. {
  30. id: 'deadbeef',
  31. title: 'Oh no something bad',
  32. 'project.name': 'project-slug',
  33. timestamp: '2019-05-23T22:12:48+00:00',
  34. },
  35. ],
  36. },
  37. });
  38. MockApiClient.addMockResponse({
  39. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  40. method: 'GET',
  41. body: {
  42. id: '1234',
  43. size: 1200,
  44. projectSlug: 'project-slug',
  45. eventID: 'deadbeef',
  46. groupID: '123',
  47. title: 'Oh no something bad',
  48. location: '/users/login',
  49. message: 'It was not good',
  50. dateCreated: '2019-05-23T22:12:48+00:00',
  51. entries: [
  52. {
  53. type: 'message',
  54. message: 'bad stuff',
  55. data: {},
  56. },
  57. ],
  58. tags: [
  59. {key: 'browser', value: 'Firefox'},
  60. {key: 'device.uuid', value: 'test-uuid'},
  61. {key: 'release', value: '82ebf297206a'},
  62. ],
  63. },
  64. });
  65. MockApiClient.addMockResponse({
  66. url: '/issues/123/',
  67. method: 'GET',
  68. body: TestStubs.Group({id: '123'}),
  69. });
  70. MockApiClient.addMockResponse({
  71. url: '/organizations/org-slug/events-stats/',
  72. method: 'GET',
  73. body: {
  74. data: [
  75. [1234561700, [1]],
  76. [1234561800, [1]],
  77. ],
  78. },
  79. });
  80. MockApiClient.addMockResponse({
  81. url: '/projects/org-slug/project-slug/events/1234/committers/',
  82. method: 'GET',
  83. statusCode: 404,
  84. body: {},
  85. });
  86. MockApiClient.addMockResponse({
  87. url: '/projects/org-slug/project-slug/events/1234/grouping-info/',
  88. body: {},
  89. });
  90. // Missing event
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/events/project-slug:abad1/',
  93. method: 'GET',
  94. statusCode: 404,
  95. body: {},
  96. });
  97. });
  98. it('renders', async function () {
  99. render(
  100. <EventDetails
  101. {...TestStubs.routeComponentProps()}
  102. organization={Organization()}
  103. params={{eventSlug: 'project-slug:deadbeef'}}
  104. location={{
  105. ...TestStubs.location(),
  106. query: allEventsView.generateQueryStringObject(),
  107. }}
  108. />
  109. );
  110. expect(await screen.findByText('Oh no something bad')).toBeInTheDocument();
  111. });
  112. it('renders a 404', async function () {
  113. render(
  114. <EventDetails
  115. {...TestStubs.routeComponentProps()}
  116. organization={Organization()}
  117. params={{eventSlug: 'project-slug:abad1'}}
  118. location={{
  119. ...TestStubs.location(),
  120. query: allEventsView.generateQueryStringObject(),
  121. }}
  122. />
  123. );
  124. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  125. });
  126. it('renders a chart in grouped view', async function () {
  127. render(
  128. <EventDetails
  129. {...TestStubs.routeComponentProps()}
  130. organization={Organization()}
  131. params={{eventSlug: 'project-slug:deadbeef'}}
  132. location={{
  133. ...TestStubs.location(),
  134. query: errorsView.generateQueryStringObject(),
  135. }}
  136. />
  137. );
  138. expect(await screen.findByText('Oh no something bad')).toBeInTheDocument();
  139. });
  140. it('renders an alert when linked issues are missing', async function () {
  141. MockApiClient.addMockResponse({
  142. url: '/issues/123/',
  143. statusCode: 404,
  144. method: 'GET',
  145. body: {},
  146. });
  147. render(
  148. <EventDetails
  149. {...TestStubs.routeComponentProps()}
  150. organization={Organization()}
  151. params={{eventSlug: 'project-slug:deadbeef'}}
  152. location={{
  153. ...TestStubs.location(),
  154. query: allEventsView.generateQueryStringObject(),
  155. }}
  156. />
  157. );
  158. expect(
  159. await screen.findByText(
  160. 'The linked issue cannot be found. It may have been deleted, or merged.'
  161. )
  162. ).toBeInTheDocument();
  163. });
  164. it('navigates when tag values are clicked', async function () {
  165. const {organization, routerContext} = initializeOrg({
  166. organization: Organization(),
  167. router: {
  168. location: {
  169. pathname: '/organizations/org-slug/discover/project-slug:deadbeef',
  170. query: {},
  171. },
  172. },
  173. });
  174. render(
  175. <EventDetails
  176. {...TestStubs.routeComponentProps()}
  177. organization={organization}
  178. params={{eventSlug: 'project-slug:deadbeef'}}
  179. location={{
  180. ...TestStubs.location(),
  181. query: allEventsView.generateQueryStringObject(),
  182. }}
  183. />,
  184. {context: routerContext}
  185. );
  186. // Get the first link as we wrap react-router's link
  187. expect(await screen.findByText('Firefox')).toBeInTheDocument();
  188. expect(screen.getByRole('link', {name: 'Firefox'})).toHaveAttribute(
  189. 'href',
  190. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=browser%3AFirefox%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  191. );
  192. // Get the second link
  193. expect(screen.getByRole('link', {name: 'test-uuid'})).toHaveAttribute(
  194. 'href',
  195. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=tags%5Bdevice.uuid%5D%3Atest-uuid%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  196. );
  197. // Get the third link
  198. expect(screen.getByRole('link', {name: '82ebf297206a'})).toHaveAttribute(
  199. 'href',
  200. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=release%3A82ebf297206a%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  201. );
  202. });
  203. it('navigates to homepage when tag values are clicked', async function () {
  204. const {organization, routerContext, router} = initializeOrg({
  205. organization: Organization(),
  206. router: {
  207. location: {
  208. pathname: '/organizations/org-slug/discover/project-slug:deadbeef',
  209. query: {...allEventsView.generateQueryStringObject(), homepage: 'true'},
  210. },
  211. },
  212. });
  213. render(
  214. <EventDetails
  215. {...TestStubs.routeComponentProps()}
  216. organization={organization}
  217. params={{eventSlug: 'project-slug:deadbeef'}}
  218. location={router.location}
  219. />,
  220. {context: routerContext}
  221. );
  222. // Get the first link as we wrap react-router's link
  223. expect(await screen.findByText('Firefox')).toBeInTheDocument();
  224. expect(screen.getByRole('link', {name: 'Firefox'})).toHaveAttribute(
  225. 'href',
  226. '/organizations/org-slug/discover/homepage/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=browser%3AFirefox%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  227. );
  228. // Get the second link
  229. expect(screen.getByRole('link', {name: 'test-uuid'})).toHaveAttribute(
  230. 'href',
  231. '/organizations/org-slug/discover/homepage/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=tags%5Bdevice.uuid%5D%3Atest-uuid%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  232. );
  233. // Get the third link
  234. expect(screen.getByRole('link', {name: '82ebf297206a'})).toHaveAttribute(
  235. 'href',
  236. '/organizations/org-slug/discover/homepage/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=release%3A82ebf297206a%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  237. );
  238. });
  239. it('appends tag value to existing query when clicked', async function () {
  240. const {organization, routerContext} = initializeOrg({
  241. organization: Organization(),
  242. router: {
  243. location: {
  244. pathname: '/organizations/org-slug/discover/project-slug:deadbeef',
  245. query: {},
  246. },
  247. },
  248. });
  249. render(
  250. <EventDetails
  251. {...TestStubs.routeComponentProps()}
  252. organization={organization}
  253. params={{eventSlug: 'project-slug:deadbeef'}}
  254. location={{
  255. ...TestStubs.location(),
  256. query: {...allEventsView.generateQueryStringObject(), query: 'Dumpster'},
  257. }}
  258. />,
  259. {context: routerContext}
  260. );
  261. // Get the first link as we wrap react-router's link
  262. expect(await screen.findByText('Firefox')).toBeInTheDocument();
  263. expect(screen.getByRole('link', {name: 'Firefox'})).toHaveAttribute(
  264. 'href',
  265. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=Dumpster%20browser%3AFirefox%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  266. );
  267. // Get the second link
  268. expect(screen.getByRole('link', {name: 'test-uuid'})).toHaveAttribute(
  269. 'href',
  270. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=Dumpster%20tags%5Bdevice.uuid%5D%3Atest-uuid%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  271. );
  272. // Get the third link
  273. expect(screen.getByRole('link', {name: '82ebf297206a'})).toHaveAttribute(
  274. 'href',
  275. '/organizations/org-slug/discover/results/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All%20Events&query=Dumpster%20release%3A82ebf297206a%20title%3A%22Oh%20no%20something%20bad%22&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29'
  276. );
  277. });
  278. it('links back to the homepage if the query param contains homepage flag', async () => {
  279. const {organization, router, routerContext} = initializeOrg({
  280. organization: Organization(),
  281. router: {
  282. location: {
  283. pathname: '/organizations/org-slug/discover/project-slug:deadbeef',
  284. query: {...allEventsView.generateQueryStringObject(), homepage: '1'},
  285. },
  286. },
  287. });
  288. render(
  289. <EventDetails
  290. {...TestStubs.routeComponentProps()}
  291. organization={organization}
  292. params={{eventSlug: 'project-slug:deadbeef'}}
  293. location={router.location}
  294. />,
  295. {context: routerContext, organization}
  296. );
  297. const breadcrumb = await screen.findByTestId('breadcrumb-link');
  298. expect(breadcrumb).toHaveTextContent('Discover');
  299. expect(breadcrumb).toHaveAttribute(
  300. 'href',
  301. expect.stringMatching(new RegExp('^/organizations/org-slug/discover/homepage/?'))
  302. );
  303. });
  304. });