index.spec.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {EventsV2} from 'app/views/eventsV2';
  4. const FIELDS = [
  5. {
  6. field: 'title',
  7. title: 'Custom Title',
  8. },
  9. {
  10. field: 'timestamp',
  11. title: 'Custom Time',
  12. },
  13. {
  14. field: 'user',
  15. title: 'Custom User',
  16. },
  17. ];
  18. const generateFields = () => {
  19. return {
  20. alias: FIELDS.map(i => i.title),
  21. field: FIELDS.map(i => i.field),
  22. };
  23. };
  24. describe('EventsV2', function() {
  25. const eventTitle = 'Oh no something bad';
  26. const features = ['events-v2'];
  27. beforeEach(function() {
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/eventsv2/',
  30. body: {
  31. meta: {
  32. id: 'string',
  33. title: 'string',
  34. 'project.name': 'string',
  35. timestamp: 'date',
  36. 'user.id': 'string',
  37. },
  38. data: [
  39. {
  40. id: 'deadbeef',
  41. 'user.id': 'alberto leal',
  42. title: eventTitle,
  43. 'project.name': 'project-slug',
  44. timestamp: '2019-05-23T22:12:48+00:00',
  45. },
  46. ],
  47. },
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  51. method: 'GET',
  52. body: {
  53. id: '1234',
  54. size: 1200,
  55. eventID: 'deadbeef',
  56. title: 'Oh no something bad',
  57. message: 'It was not good',
  58. dateCreated: '2019-05-23T22:12:48+00:00',
  59. entries: [
  60. {
  61. type: 'message',
  62. message: 'bad stuff',
  63. data: {},
  64. },
  65. ],
  66. tags: [{key: 'browser', value: 'Firefox'}],
  67. },
  68. });
  69. });
  70. it('renders a link list', function() {
  71. const wrapper = mount(
  72. <EventsV2
  73. organization={TestStubs.Organization({features, projects: [TestStubs.Project()]})}
  74. location={{query: {}}}
  75. router={{}}
  76. />,
  77. TestStubs.routerContext()
  78. );
  79. const content = wrapper.find('PageContent');
  80. expect(content.text()).toContain('Events');
  81. expect(content.find('LinkContainer').length).toBeGreaterThanOrEqual(3);
  82. });
  83. it('renders a list of events', function() {
  84. const wrapper = mount(
  85. <EventsV2
  86. organization={TestStubs.Organization({features, projects: [TestStubs.Project()]})}
  87. location={{query: {...generateFields()}}}
  88. router={{}}
  89. />,
  90. TestStubs.routerContext()
  91. );
  92. const content = wrapper.find('PageContent');
  93. expect(content.find('Events PanelHeaderCell').length).toBeGreaterThan(0);
  94. expect(content.find('Events PanelItemCell').length).toBeGreaterThan(0);
  95. });
  96. it('handles no projects', function() {
  97. const wrapper = mount(
  98. <EventsV2
  99. organization={TestStubs.Organization({features})}
  100. location={{query: {...generateFields()}}}
  101. router={{}}
  102. />,
  103. TestStubs.routerContext()
  104. );
  105. const content = wrapper.find('PageContent');
  106. expect(content.text()).toContain('You need at least one project to use this view');
  107. });
  108. it('generates an active sort link based on default sort', function() {
  109. const wrapper = mount(
  110. <EventsV2
  111. organization={TestStubs.Organization({features, projects: [TestStubs.Project()]})}
  112. location={{query: {...generateFields(), sort: ['-timestamp']}}}
  113. router={{}}
  114. />,
  115. TestStubs.routerContext()
  116. );
  117. const findLink = sortKey =>
  118. wrapper
  119. .find('Table SortLink')
  120. .find({sortKey})
  121. .find('StyledLink');
  122. const timestamp = findLink('timestamp');
  123. // Sort should be active
  124. expect(
  125. timestamp
  126. .find('InlineSvg')
  127. .first()
  128. .props().src
  129. ).toEqual('icon-chevron-down');
  130. // Sort link should reverse.
  131. expect(timestamp.props().to.query).toEqual({
  132. ...generateFields(),
  133. sort: 'timestamp',
  134. });
  135. const userlink = findLink('user.id');
  136. // User link should be descending.
  137. expect(userlink.props().to.query).toEqual({
  138. ...generateFields(),
  139. sort: '-user.id',
  140. });
  141. });
  142. it('generates links to modals', async function() {
  143. const wrapper = mount(
  144. <EventsV2
  145. organization={TestStubs.Organization({features, projects: [TestStubs.Project()]})}
  146. location={{query: {...generateFields()}}}
  147. router={{}}
  148. />,
  149. TestStubs.routerContext()
  150. );
  151. const link = wrapper.find(`Table Link[aria-label="${eventTitle}"]`).first();
  152. expect(link.props().to.query).toEqual({
  153. eventSlug: 'project-slug:deadbeef',
  154. ...generateFields(),
  155. });
  156. });
  157. it('opens a modal when eventSlug is present', async function() {
  158. const organization = TestStubs.Organization({
  159. features,
  160. projects: [TestStubs.Project()],
  161. });
  162. const wrapper = mount(
  163. <EventsV2
  164. organization={organization}
  165. params={{orgId: organization.slug}}
  166. location={{query: {eventSlug: 'project-slug:deadbeef'}}}
  167. router={{}}
  168. />,
  169. TestStubs.routerContext()
  170. );
  171. const modal = wrapper.find('EventDetails');
  172. expect(modal).toHaveLength(1);
  173. });
  174. });