transactionEvents.spec.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import {WebVital} from 'sentry/utils/fields';
  5. import TransactionEvents from 'sentry/views/performance/transactionSummary/transactionEvents';
  6. // XXX(epurkhiser): This appears to also be tested by ./transactionSummary/transactionEvents/index.spec.tsx
  7. type Data = {
  8. features?: string[];
  9. query?: {
  10. webVital?: WebVital;
  11. };
  12. };
  13. function initializeData({features: additionalFeatures = [], query = {}}: Data = {}) {
  14. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  15. const organization = TestStubs.Organization({
  16. features,
  17. projects: [TestStubs.Project()],
  18. });
  19. return initializeOrg({
  20. organization,
  21. router: {
  22. location: {
  23. query: {
  24. transaction: '/performance',
  25. project: '1',
  26. transactionCursor: '1:0:0',
  27. ...query,
  28. },
  29. },
  30. },
  31. projects: [],
  32. });
  33. }
  34. describe('Performance > TransactionSummary', function () {
  35. beforeAll(function () {
  36. // eslint-disable-next-line no-console
  37. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  38. MockApiClient.addMockResponse({
  39. url: '/organizations/org-slug/projects/',
  40. body: [],
  41. });
  42. MockApiClient.addMockResponse({
  43. url: '/prompts-activity/',
  44. body: {},
  45. });
  46. MockApiClient.addMockResponse({
  47. url: '/organizations/org-slug/sdk-updates/',
  48. body: [],
  49. });
  50. MockApiClient.addMockResponse({
  51. url: '/organizations/org-slug/events/',
  52. body: {
  53. data: [
  54. {
  55. 'p100()': 9502,
  56. 'p99()': 9285.7,
  57. 'p95()': 7273.6,
  58. 'p75()': 3639.5,
  59. 'p50()': 755.5,
  60. },
  61. ],
  62. meta: {
  63. fields: {
  64. 'p100()': 'duration',
  65. 'p99()': 'duration',
  66. 'p95()': 'duration',
  67. 'p75()': 'duration',
  68. 'p50()': 'duration',
  69. },
  70. },
  71. },
  72. match: [
  73. (_, options) => {
  74. return options.query?.field?.includes('p95()');
  75. },
  76. ],
  77. });
  78. // Transaction list response
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/events/',
  81. headers: {
  82. Link:
  83. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  84. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  85. },
  86. body: {
  87. meta: {
  88. fields: {
  89. id: 'string',
  90. 'user.display': 'string',
  91. 'transaction.duration': 'duration',
  92. 'project.id': 'integer',
  93. timestamp: 'date',
  94. },
  95. },
  96. data: [
  97. {
  98. id: 'deadbeef',
  99. 'user.display': 'uhoh@example.com',
  100. 'transaction.duration': 400,
  101. 'project.id': 1,
  102. timestamp: '2020-05-21T15:31:18+00:00',
  103. trace: '1234',
  104. 'measurements.lcp': 200,
  105. },
  106. {
  107. id: 'moredeadbeef',
  108. 'user.display': 'moreuhoh@example.com',
  109. 'transaction.duration': 600,
  110. 'project.id': 1,
  111. timestamp: '2020-05-22T15:31:18+00:00',
  112. trace: '4321',
  113. 'measurements.lcp': 300,
  114. },
  115. ],
  116. },
  117. match: [
  118. (_url, options) => {
  119. return options.query?.field?.includes('user.display');
  120. },
  121. ],
  122. });
  123. MockApiClient.addMockResponse({
  124. url: '/organizations/org-slug/events/',
  125. body: {
  126. data: [{'count()': 5161}],
  127. },
  128. match: [
  129. (_url, options) => {
  130. return options.query?.field?.includes('count()');
  131. },
  132. ],
  133. });
  134. MockApiClient.addMockResponse({
  135. url: '/organizations/org-slug/events-has-measurements/',
  136. body: {measurements: false},
  137. });
  138. });
  139. it('renders basic UI elements', async function () {
  140. const {organization, router, routerContext} = initializeData();
  141. ProjectsStore.loadInitialData(organization.projects);
  142. render(<TransactionEvents organization={organization} location={router.location} />, {
  143. context: routerContext,
  144. });
  145. // Breadcrumb
  146. expect(screen.getByRole('link', {name: 'Performance'})).toHaveAttribute(
  147. 'href',
  148. '/organizations/org-slug/performance/?project=1&transactionCursor=1%3A0%3A0'
  149. );
  150. // Header
  151. expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
  152. expect(
  153. await screen.findByRole('textbox', {name: 'Search events'})
  154. ).toBeInTheDocument();
  155. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  156. expect(screen.getByRole('button', {name: 'Previous'})).toBeInTheDocument();
  157. expect(screen.getByRole('table')).toBeInTheDocument();
  158. expect(screen.getByRole('tab', {name: 'Overview'})).toBeInTheDocument();
  159. expect(screen.getByRole('tab', {name: 'All Events'})).toBeInTheDocument();
  160. expect(screen.getByRole('tab', {name: 'Tags'})).toBeInTheDocument();
  161. ProjectsStore.reset();
  162. });
  163. it('renders relative span breakdown header when no filter selected', async function () {
  164. const {organization, router, routerContext} = initializeData();
  165. ProjectsStore.loadInitialData(organization.projects);
  166. render(<TransactionEvents organization={organization} location={router.location} />, {
  167. context: routerContext,
  168. });
  169. expect(await screen.findByText('operation duration')).toBeInTheDocument();
  170. expect(screen.getAllByRole('columnheader')).toHaveLength(6);
  171. ProjectsStore.reset();
  172. });
  173. it('renders event column results correctly', async function () {
  174. const {organization, router, routerContext} = initializeData();
  175. ProjectsStore.loadInitialData(organization.projects);
  176. render(<TransactionEvents organization={organization} location={router.location} />, {
  177. context: routerContext,
  178. });
  179. const tableHeader = await screen.findAllByRole('columnheader');
  180. expect(tableHeader).toHaveLength(6);
  181. expect(tableHeader[0]).toHaveTextContent('event id');
  182. expect(tableHeader[1]).toHaveTextContent('user');
  183. expect(tableHeader[2]).toHaveTextContent('operation duration');
  184. expect(tableHeader[3]).toHaveTextContent('total duration');
  185. expect(tableHeader[4]).toHaveTextContent('trace id');
  186. expect(tableHeader[5]).toHaveTextContent('timestamp');
  187. const tableFirstRowColumns = screen.getAllByRole('cell');
  188. expect(tableFirstRowColumns[0]).toHaveTextContent('deadbeef');
  189. expect(tableFirstRowColumns[1]).toHaveTextContent('Uuhoh@example.com');
  190. expect(tableFirstRowColumns[2]).toHaveTextContent('(no value)');
  191. expect(tableFirstRowColumns[3]).toHaveTextContent('400.00ms');
  192. expect(tableFirstRowColumns[4]).toHaveTextContent('1234');
  193. expect(tableFirstRowColumns[5]).toHaveTextContent('May 21, 2020 3:31:18 PM UTC');
  194. ProjectsStore.reset();
  195. });
  196. it('renders additional Web Vital column', async function () {
  197. const {organization, router, routerContext} = initializeData({
  198. query: {webVital: WebVital.LCP},
  199. });
  200. ProjectsStore.loadInitialData(organization.projects);
  201. render(<TransactionEvents organization={organization} location={router.location} />, {
  202. context: routerContext,
  203. });
  204. const tableHeader = await screen.findAllByRole('columnheader');
  205. expect(tableHeader).toHaveLength(7);
  206. expect(tableHeader[0]).toHaveTextContent('event id');
  207. expect(tableHeader[1]).toHaveTextContent('user');
  208. expect(tableHeader[2]).toHaveTextContent('operation duration');
  209. expect(tableHeader[3]).toHaveTextContent('measurements.lcp');
  210. expect(tableHeader[4]).toHaveTextContent('total duration');
  211. expect(tableHeader[5]).toHaveTextContent('trace id');
  212. expect(tableHeader[6]).toHaveTextContent('timestamp');
  213. const tableFirstRowColumns = screen.getAllByRole('cell');
  214. expect(tableFirstRowColumns[0]).toHaveTextContent('deadbeef');
  215. expect(tableFirstRowColumns[1]).toHaveTextContent('Uuhoh@example.com');
  216. expect(tableFirstRowColumns[2]).toHaveTextContent('(no value)');
  217. expect(tableFirstRowColumns[3]).toHaveTextContent('200');
  218. expect(tableFirstRowColumns[4]).toHaveTextContent('400.00ms');
  219. expect(tableFirstRowColumns[5]).toHaveTextContent('1234');
  220. expect(tableFirstRowColumns[6]).toHaveTextContent('May 21, 2020 3:31:18 PM UTC');
  221. ProjectsStore.reset();
  222. });
  223. });