eventOrGroupHeader.spec.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import EventOrGroupHeader from 'app/components/eventOrGroupHeader';
  4. const data = {
  5. metadata: {
  6. type: 'metadata type',
  7. directive: 'metadata directive',
  8. uri: 'metadata uri',
  9. value: 'metadata value',
  10. message: 'metadata message',
  11. },
  12. culprit: 'culprit',
  13. };
  14. describe('EventOrGroupHeader', function () {
  15. const {routerContext} = initializeOrg();
  16. describe('Group', function () {
  17. const groupData = {
  18. ...data,
  19. level: 'error',
  20. id: 'id',
  21. };
  22. it('renders with `type = error`', function () {
  23. const component = mountWithTheme(
  24. <EventOrGroupHeader
  25. orgId="orgId"
  26. data={{
  27. ...groupData,
  28. type: 'error',
  29. }}
  30. />,
  31. routerContext
  32. );
  33. expect(component).toSnapshot();
  34. });
  35. it('renders with `type = csp`', function () {
  36. const component = mountWithTheme(
  37. <EventOrGroupHeader
  38. params={{orgId: 'orgId'}}
  39. data={{
  40. ...groupData,
  41. ...{
  42. type: 'csp',
  43. },
  44. }}
  45. />,
  46. routerContext
  47. );
  48. expect(component).toSnapshot();
  49. });
  50. it('renders with `type = default`', function () {
  51. const component = mountWithTheme(
  52. <EventOrGroupHeader
  53. params={{orgId: 'orgId'}}
  54. data={{
  55. ...groupData,
  56. type: 'default',
  57. metadata: {
  58. ...groupData.metadata,
  59. title: 'metadata title',
  60. },
  61. }}
  62. />,
  63. routerContext
  64. );
  65. expect(component).toSnapshot();
  66. });
  67. it('renders metadata values in message for error events', function () {
  68. const component = mountWithTheme(
  69. <EventOrGroupHeader
  70. params={{orgId: 'orgId'}}
  71. data={{
  72. ...groupData,
  73. type: 'error',
  74. }}
  75. />,
  76. routerContext
  77. );
  78. const message = component.find('Message');
  79. expect(message.text()).toEqual('metadata value');
  80. });
  81. it('renders location', function () {
  82. const component = mountWithTheme(
  83. <EventOrGroupHeader
  84. params={{orgId: 'orgId'}}
  85. data={{
  86. metadata: {
  87. filename: 'path/to/file.swift',
  88. },
  89. platform: 'swift',
  90. type: 'error',
  91. }}
  92. />,
  93. routerContext
  94. );
  95. const location = component.find('Location');
  96. expect(location.text()).toEqual('in path/to/file.swift');
  97. });
  98. });
  99. describe('Event', function () {
  100. const eventData = {
  101. ...data,
  102. id: 'id',
  103. eventID: 'eventID',
  104. groupID: 'groupID',
  105. culprit: undefined,
  106. };
  107. it('renders with `type = error`', function () {
  108. const component = mountWithTheme(
  109. <EventOrGroupHeader
  110. params={{orgId: 'orgId'}}
  111. data={{
  112. ...eventData,
  113. type: 'error',
  114. }}
  115. />,
  116. routerContext
  117. );
  118. expect(component).toSnapshot();
  119. });
  120. it('renders with `type = csp`', function () {
  121. const component = mountWithTheme(
  122. <EventOrGroupHeader
  123. params={{orgId: 'orgId'}}
  124. data={{
  125. ...eventData,
  126. type: 'csp',
  127. }}
  128. />,
  129. routerContext
  130. );
  131. expect(component).toSnapshot();
  132. });
  133. it('renders with `type = default`', function () {
  134. const component = mountWithTheme(
  135. <EventOrGroupHeader
  136. params={{orgId: 'orgId'}}
  137. data={{
  138. ...eventData,
  139. type: 'default',
  140. metadata: {
  141. ...eventData.metadata,
  142. title: 'metadata title',
  143. },
  144. }}
  145. />,
  146. routerContext
  147. );
  148. expect(component).toSnapshot();
  149. });
  150. it('hides level tag', function () {
  151. const component = mountWithTheme(
  152. <EventOrGroupHeader
  153. projectId="projectId"
  154. hideLevel
  155. data={{
  156. ...eventData,
  157. type: 'default',
  158. metadata: {
  159. ...eventData.metadata,
  160. title: 'metadata title',
  161. },
  162. }}
  163. />,
  164. routerContext
  165. );
  166. expect(component).toSnapshot();
  167. });
  168. it('keeps sort in link when query has sort', function () {
  169. const query = {
  170. sort: 'freq',
  171. };
  172. const component = shallow(
  173. <EventOrGroupHeader
  174. params={{orgId: 'orgId'}}
  175. data={{
  176. ...eventData,
  177. type: 'default',
  178. }}
  179. location={{query}}
  180. />
  181. );
  182. const title = component.dive().dive().instance().getTitle();
  183. expect(title.props.to.query.sort).toEqual('freq');
  184. });
  185. it('lack of project adds allp parameter', function () {
  186. const query = {};
  187. const component = shallow(
  188. <EventOrGroupHeader
  189. params={{orgId: 'orgId'}}
  190. data={{
  191. ...eventData,
  192. type: 'default',
  193. }}
  194. location={{query}}
  195. />
  196. );
  197. const title = component.dive().dive().instance().getTitle();
  198. expect(title.props.to.query._allp).toEqual(1);
  199. });
  200. });
  201. });