transactionEvents.spec.tsx 8.4 KB

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