eventsTable.spec.tsx 6.5 KB

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