eventOrGroupHeader.spec.tsx 6.7 KB

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