transactionEvents.spec.tsx 8.4 KB

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