eventOrGroupHeader.spec.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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} = initializeOrg({
  32. router: {orgId: 'orgId'},
  33. } as Parameters<typeof initializeOrg>[0]);
  34. describe('Group', function () {
  35. it('renders with `type = error`', function () {
  36. const {container} = render(
  37. <EventOrGroupHeader organization={organization} data={group} {...router} />
  38. );
  39. expect(container).toSnapshot();
  40. });
  41. it('renders with `type = csp`', function () {
  42. const {container} = render(
  43. <EventOrGroupHeader
  44. organization={organization}
  45. data={{
  46. ...group,
  47. type: EventOrGroupType.CSP,
  48. }}
  49. {...router}
  50. />
  51. );
  52. expect(container).toSnapshot();
  53. });
  54. it('renders with `type = default`', function () {
  55. const {container} = render(
  56. <EventOrGroupHeader
  57. organization={organization}
  58. data={{
  59. ...group,
  60. type: EventOrGroupType.DEFAULT,
  61. metadata: {
  62. ...group.metadata,
  63. title: 'metadata title',
  64. },
  65. }}
  66. {...router}
  67. />
  68. );
  69. expect(container).toSnapshot();
  70. });
  71. it('renders metadata values in message for error events', function () {
  72. render(
  73. <EventOrGroupHeader
  74. organization={organization}
  75. data={{
  76. ...group,
  77. type: EventOrGroupType.ERROR,
  78. }}
  79. {...router}
  80. />
  81. );
  82. expect(screen.getByText('metadata value')).toBeInTheDocument();
  83. });
  84. it('renders location', function () {
  85. render(
  86. <EventOrGroupHeader
  87. organization={organization}
  88. data={{
  89. ...group,
  90. metadata: {
  91. filename: 'path/to/file.swift',
  92. },
  93. platform: 'swift',
  94. type: EventOrGroupType.ERROR,
  95. }}
  96. {...router}
  97. />
  98. );
  99. expect(
  100. screen.getByText(textWithMarkupMatcher('in path/to/file.swift'))
  101. ).toBeInTheDocument();
  102. });
  103. });
  104. describe('Event', function () {
  105. it('renders with `type = error`', function () {
  106. const {container} = render(
  107. <EventOrGroupHeader
  108. organization={organization}
  109. data={{
  110. ...event,
  111. type: EventOrGroupType.ERROR,
  112. }}
  113. {...router}
  114. />
  115. );
  116. expect(container).toSnapshot();
  117. });
  118. it('renders with `type = csp`', function () {
  119. const {container} = render(
  120. <EventOrGroupHeader
  121. organization={organization}
  122. data={{
  123. ...event,
  124. type: EventOrGroupType.CSP,
  125. }}
  126. {...router}
  127. />
  128. );
  129. expect(container).toSnapshot();
  130. });
  131. it('renders with `type = default`', function () {
  132. const {container} = render(
  133. <EventOrGroupHeader
  134. organization={organization}
  135. data={{
  136. ...event,
  137. type: EventOrGroupType.DEFAULT,
  138. metadata: {
  139. ...event.metadata,
  140. title: 'metadata title',
  141. },
  142. }}
  143. {...router}
  144. />
  145. );
  146. expect(container).toSnapshot();
  147. });
  148. it('hides level tag', function () {
  149. const {container} = render(
  150. <EventOrGroupHeader
  151. projectId="projectId"
  152. hideLevel
  153. organization={organization}
  154. data={{
  155. ...event,
  156. type: EventOrGroupType.DEFAULT,
  157. metadata: {
  158. ...event.metadata,
  159. title: 'metadata title',
  160. },
  161. }}
  162. {...router}
  163. />
  164. );
  165. expect(container).toSnapshot();
  166. });
  167. it('keeps sort in link when query has sort', function () {
  168. render(
  169. <EventOrGroupHeader
  170. organization={organization}
  171. data={{
  172. ...event,
  173. type: EventOrGroupType.DEFAULT,
  174. }}
  175. {...router}
  176. location={{
  177. ...router.location,
  178. query: {
  179. ...router.location.query,
  180. sort: 'freq',
  181. },
  182. }}
  183. />
  184. );
  185. expect(screen.getByRole('link')).toHaveAttribute(
  186. 'href',
  187. '/organizations/org-slug/issues/groupID/events/eventID/?_allp=1&sort=freq'
  188. );
  189. });
  190. it('lack of project adds allp parameter', function () {
  191. render(
  192. <EventOrGroupHeader
  193. organization={organization}
  194. data={{
  195. ...event,
  196. type: EventOrGroupType.DEFAULT,
  197. }}
  198. {...router}
  199. location={{
  200. ...router.location,
  201. query: {},
  202. }}
  203. />
  204. );
  205. expect(screen.getByRole('link')).toHaveAttribute(
  206. 'href',
  207. '/organizations/org-slug/issues/groupID/events/eventID/?_allp=1'
  208. );
  209. });
  210. });
  211. });