content.spec.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act} from 'sentry-test/reactTestingLibrary';
  4. import {t} from 'sentry/locale';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {
  8. SPAN_OP_BREAKDOWN_FIELDS,
  9. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  10. } from 'sentry/utils/discover/fields';
  11. import {WebVital} from 'sentry/utils/fields';
  12. import {OrganizationContext} from 'sentry/views/organizationContext';
  13. import {SpanOperationBreakdownFilter} from 'sentry/views/performance/transactionSummary/filter';
  14. import EventsPageContent from 'sentry/views/performance/transactionSummary/transactionEvents/content';
  15. import {EventsDisplayFilterName} from 'sentry/views/performance/transactionSummary/transactionEvents/utils';
  16. type Data = {
  17. features?: string[];
  18. };
  19. function initializeData({features: additionalFeatures = []}: Data = {}) {
  20. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  21. const organization = TestStubs.Organization({
  22. features,
  23. projects: [TestStubs.Project()],
  24. apdexThreshold: 400,
  25. });
  26. const initialData = initializeOrg({
  27. organization,
  28. router: {
  29. location: {
  30. query: {
  31. transaction: '/performance',
  32. project: 1,
  33. transactionCursor: '1:0:0',
  34. },
  35. },
  36. },
  37. project: 1,
  38. projects: [],
  39. });
  40. act(() => void ProjectsStore.loadInitialData(initialData.organization.projects));
  41. return initialData;
  42. }
  43. describe('Performance Transaction Events Content', function () {
  44. let fields;
  45. let organization;
  46. let data;
  47. let transactionName;
  48. let eventView;
  49. let totalEventCount;
  50. let initialData;
  51. const query =
  52. 'transaction.duration:<15m event.type:transaction transaction:/api/0/organizations/{organization_slug}/events/';
  53. beforeEach(function () {
  54. transactionName = 'transactionName';
  55. totalEventCount = '200';
  56. fields = [
  57. 'id',
  58. 'user.display',
  59. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  60. 'transaction.duration',
  61. 'trace',
  62. 'timestamp',
  63. 'spans.total.time',
  64. ...SPAN_OP_BREAKDOWN_FIELDS,
  65. ];
  66. organization = TestStubs.Organization();
  67. MockApiClient.addMockResponse({
  68. url: '/organizations/org-slug/projects/',
  69. body: [],
  70. });
  71. MockApiClient.addMockResponse({
  72. url: '/prompts-activity/',
  73. body: {},
  74. });
  75. MockApiClient.addMockResponse({
  76. url: '/organizations/org-slug/sdk-updates/',
  77. body: [],
  78. });
  79. data = [
  80. {
  81. id: 'deadbeef',
  82. 'user.display': 'uhoh@example.com',
  83. 'transaction.duration': 400,
  84. 'project.id': 1,
  85. timestamp: '2020-05-21T15:31:18+00:00',
  86. trace: '1234',
  87. 'span_ops_breakdown.relative': '',
  88. 'spans.browser': 100,
  89. 'spans.db': 30,
  90. 'spans.http': 170,
  91. 'spans.resource': 100,
  92. 'spans.total.time': 400,
  93. },
  94. {
  95. id: 'moredeadbeef',
  96. 'user.display': 'moreuhoh@example.com',
  97. 'transaction.duration': 600,
  98. 'project.id': 1,
  99. timestamp: '2020-05-22T15:31:18+00:00',
  100. trace: '4321',
  101. 'span_ops_breakdown.relative': '',
  102. 'spans.browser': 100,
  103. 'spans.db': 300,
  104. 'spans.http': 100,
  105. 'spans.resource': 100,
  106. 'spans.total.time': 600,
  107. },
  108. ];
  109. // Transaction list response
  110. MockApiClient.addMockResponse({
  111. url: '/organizations/org-slug/events/',
  112. headers: {
  113. Link:
  114. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  115. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  116. },
  117. body: {
  118. meta: {
  119. fields: {
  120. id: 'string',
  121. 'user.display': 'string',
  122. 'transaction.duration': 'duration',
  123. 'project.id': 'integer',
  124. timestamp: 'date',
  125. },
  126. },
  127. data,
  128. },
  129. match: [
  130. (_url, options) => {
  131. return options.query?.field?.includes('user.display');
  132. },
  133. ],
  134. });
  135. MockApiClient.addMockResponse({
  136. url: '/organizations/org-slug/events-has-measurements/',
  137. body: {measurements: false},
  138. });
  139. initialData = initializeData();
  140. eventView = EventView.fromNewQueryWithLocation(
  141. {
  142. id: undefined,
  143. version: 2,
  144. name: 'transactionName',
  145. fields,
  146. query,
  147. projects: [],
  148. orderby: '-timestamp',
  149. },
  150. initialData.router.location
  151. );
  152. });
  153. afterEach(function () {
  154. MockApiClient.clearMockResponses();
  155. ProjectsStore.reset();
  156. jest.clearAllMocks();
  157. });
  158. it('basic rendering', async function () {
  159. const wrapper = mountWithTheme(
  160. <OrganizationContext.Provider value={organization}>
  161. <EventsPageContent
  162. totalEventCount={totalEventCount}
  163. eventView={eventView}
  164. organization={organization}
  165. location={initialData.router.location}
  166. transactionName={transactionName}
  167. spanOperationBreakdownFilter={SpanOperationBreakdownFilter.None}
  168. onChangeSpanOperationBreakdownFilter={() => {}}
  169. eventsDisplayFilterName={EventsDisplayFilterName.p100}
  170. onChangeEventsDisplayFilter={() => {}}
  171. setError={() => {}}
  172. />
  173. </OrganizationContext.Provider>,
  174. initialData.routerContext
  175. );
  176. await tick();
  177. wrapper.update();
  178. expect(wrapper.find('EventsTable')).toHaveLength(1);
  179. expect(wrapper.find('CompactSelect')).toHaveLength(1);
  180. expect(wrapper.find('StyledSearchBar')).toHaveLength(1);
  181. expect(wrapper.find('Filter')).toHaveLength(1);
  182. const columnTitles = wrapper.find('EventsTable').props().columnTitles;
  183. expect(columnTitles).toEqual([
  184. t('event id'),
  185. t('user'),
  186. t('operation duration'),
  187. t('total duration'),
  188. t('trace id'),
  189. t('timestamp'),
  190. ]);
  191. });
  192. it('rendering with webvital selected', async function () {
  193. const wrapper = mountWithTheme(
  194. <OrganizationContext.Provider value={organization}>
  195. <EventsPageContent
  196. totalEventCount={totalEventCount}
  197. eventView={eventView}
  198. organization={organization}
  199. location={initialData.router.location}
  200. transactionName={transactionName}
  201. spanOperationBreakdownFilter={SpanOperationBreakdownFilter.None}
  202. onChangeSpanOperationBreakdownFilter={() => {}}
  203. eventsDisplayFilterName={EventsDisplayFilterName.p100}
  204. onChangeEventsDisplayFilter={() => {}}
  205. webVital={WebVital.LCP}
  206. setError={() => {}}
  207. />
  208. </OrganizationContext.Provider>,
  209. initialData.routerContext
  210. );
  211. await tick();
  212. wrapper.update();
  213. expect(wrapper.find('EventsTable')).toHaveLength(1);
  214. expect(wrapper.find('CompactSelect')).toHaveLength(1);
  215. expect(wrapper.find('StyledSearchBar')).toHaveLength(1);
  216. expect(wrapper.find('Filter')).toHaveLength(1);
  217. const columnTitles = wrapper.find('EventsTable').props().columnTitles;
  218. expect(columnTitles).toEqual([
  219. t('event id'),
  220. t('user'),
  221. t('operation duration'),
  222. t('measurements.lcp'),
  223. t('total duration'),
  224. t('trace id'),
  225. t('timestamp'),
  226. ]);
  227. });
  228. });