eventOrGroupHeader.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import EventOrGroupHeader from 'sentry/components/eventOrGroupHeader';
  5. import {EventOrGroupType} from 'sentry/types';
  6. const group = TestStubs.Group({
  7. level: 'error',
  8. metadata: {
  9. type: 'metadata type',
  10. directive: 'metadata directive',
  11. uri: 'metadata uri',
  12. value: 'metadata value',
  13. message: 'metadata message',
  14. },
  15. culprit: 'culprit',
  16. });
  17. const event = TestStubs.Event({
  18. id: 'id',
  19. eventID: 'eventID',
  20. groupID: 'groupID',
  21. culprit: undefined,
  22. metadata: {
  23. type: 'metadata type',
  24. directive: 'metadata directive',
  25. uri: 'metadata uri',
  26. value: 'metadata value',
  27. message: 'metadata message',
  28. },
  29. });
  30. describe('EventOrGroupHeader', function () {
  31. const {organization, router, routerContext} = initializeOrg();
  32. describe('Group', function () {
  33. it('renders with `type = error`', function () {
  34. render(<EventOrGroupHeader organization={organization} data={group} {...router} />);
  35. });
  36. it('renders with `type = csp`', function () {
  37. render(
  38. <EventOrGroupHeader
  39. organization={organization}
  40. data={{
  41. ...group,
  42. type: EventOrGroupType.CSP,
  43. }}
  44. {...router}
  45. />
  46. );
  47. });
  48. it('renders with `type = default`', function () {
  49. render(
  50. <EventOrGroupHeader
  51. organization={organization}
  52. data={{
  53. ...group,
  54. type: EventOrGroupType.DEFAULT,
  55. metadata: {
  56. ...group.metadata,
  57. title: 'metadata title',
  58. },
  59. }}
  60. {...router}
  61. />
  62. );
  63. });
  64. it('renders metadata values in message for error events', function () {
  65. render(
  66. <EventOrGroupHeader
  67. organization={organization}
  68. data={{
  69. ...group,
  70. type: EventOrGroupType.ERROR,
  71. }}
  72. {...router}
  73. />
  74. );
  75. expect(screen.getByText('metadata value')).toBeInTheDocument();
  76. });
  77. it('renders location', function () {
  78. render(
  79. <EventOrGroupHeader
  80. organization={organization}
  81. data={{
  82. ...group,
  83. metadata: {
  84. filename: 'path/to/file.swift',
  85. },
  86. platform: 'swift',
  87. type: EventOrGroupType.ERROR,
  88. }}
  89. {...router}
  90. />
  91. );
  92. expect(
  93. screen.getByText(textWithMarkupMatcher('in path/to/file.swift'))
  94. ).toBeInTheDocument();
  95. });
  96. });
  97. describe('Event', function () {
  98. it('renders with `type = error`', function () {
  99. render(
  100. <EventOrGroupHeader
  101. organization={organization}
  102. data={{
  103. ...event,
  104. type: EventOrGroupType.ERROR,
  105. }}
  106. {...router}
  107. />
  108. );
  109. });
  110. it('renders with `type = csp`', function () {
  111. render(
  112. <EventOrGroupHeader
  113. organization={organization}
  114. data={{
  115. ...event,
  116. type: EventOrGroupType.CSP,
  117. }}
  118. {...router}
  119. />
  120. );
  121. });
  122. it('renders with `type = default`', function () {
  123. render(
  124. <EventOrGroupHeader
  125. organization={organization}
  126. data={{
  127. ...event,
  128. type: EventOrGroupType.DEFAULT,
  129. metadata: {
  130. ...event.metadata,
  131. title: 'metadata title',
  132. },
  133. }}
  134. {...router}
  135. />
  136. );
  137. });
  138. it('hides level tag', function () {
  139. render(
  140. <EventOrGroupHeader
  141. hideLevel
  142. organization={organization}
  143. data={{
  144. ...event,
  145. type: EventOrGroupType.DEFAULT,
  146. metadata: {
  147. ...event.metadata,
  148. title: 'metadata title',
  149. },
  150. }}
  151. />
  152. );
  153. });
  154. it('keeps sort in link when query has sort', function () {
  155. render(
  156. <EventOrGroupHeader
  157. organization={organization}
  158. data={{
  159. ...event,
  160. type: EventOrGroupType.DEFAULT,
  161. }}
  162. />,
  163. {
  164. context: routerContext,
  165. router: {
  166. ...router,
  167. location: {
  168. ...router.location,
  169. query: {
  170. ...router.location.query,
  171. sort: 'freq',
  172. },
  173. },
  174. },
  175. }
  176. );
  177. expect(screen.getByRole('link')).toHaveAttribute(
  178. 'href',
  179. '/organizations/org-slug/issues/groupID/events/eventID/?_allp=1&referrer=event-or-group-header&sort=freq'
  180. );
  181. });
  182. it('lack of project adds all parameter', function () {
  183. render(
  184. <EventOrGroupHeader
  185. organization={organization}
  186. data={{
  187. ...event,
  188. type: EventOrGroupType.DEFAULT,
  189. }}
  190. />,
  191. {
  192. context: routerContext,
  193. router: {
  194. ...router,
  195. location: {
  196. ...router.location,
  197. query: {},
  198. },
  199. },
  200. }
  201. );
  202. expect(screen.getByRole('link')).toHaveAttribute(
  203. 'href',
  204. '/organizations/org-slug/issues/groupID/events/eventID/?_allp=1&referrer=event-or-group-header'
  205. );
  206. });
  207. });
  208. it('renders group tombstone without link to group', function () {
  209. render(
  210. <EventOrGroupHeader
  211. organization={organization}
  212. data={{
  213. id: '123',
  214. level: 'error',
  215. message: 'numTabItems is not defined ReferenceError something',
  216. culprit:
  217. 'useOverflowTabs(webpack-internal:///./app/components/tabs/tabList.tsx)',
  218. type: EventOrGroupType.ERROR,
  219. metadata: {
  220. value: 'numTabItems is not defined',
  221. type: 'ReferenceError',
  222. filename: 'webpack-internal:///./app/components/tabs/tabList.tsx',
  223. function: 'useOverflowTabs',
  224. display_title_with_tree_label: false,
  225. },
  226. actor: TestStubs.User(),
  227. isTombstone: true,
  228. }}
  229. {...router}
  230. />
  231. );
  232. expect(screen.queryByRole('link')).not.toBeInTheDocument();
  233. });
  234. });