index.spec.tsx 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. import {browserHistory, InjectedRouter} from 'react-router';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {makeTestQueryClient} from 'sentry-test/queryClient';
  5. import {
  6. render,
  7. renderGlobalModal,
  8. screen,
  9. userEvent,
  10. waitFor,
  11. } from 'sentry-test/reactTestingLibrary';
  12. import OrganizationStore from 'sentry/stores/organizationStore';
  13. import ProjectsStore from 'sentry/stores/projectsStore';
  14. import TeamStore from 'sentry/stores/teamStore';
  15. import {Project} from 'sentry/types';
  16. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  17. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  18. import {
  19. MEPSetting,
  20. MEPState,
  21. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  22. import {QueryClientProvider} from 'sentry/utils/queryClient';
  23. import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';
  24. import {RouteContext} from 'sentry/views/routeContext';
  25. const teams = [
  26. TestStubs.Team({id: '1', slug: 'team1', name: 'Team 1'}),
  27. TestStubs.Team({id: '2', slug: 'team2', name: 'Team 2'}),
  28. ];
  29. function initializeData({
  30. features: additionalFeatures = [],
  31. query = {},
  32. project: prj,
  33. projects,
  34. }: {
  35. features?: string[];
  36. project?: Project;
  37. projects?: Project[];
  38. query?: Record<string, any>;
  39. } = {}) {
  40. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  41. const project = prj ?? TestStubs.Project({teams});
  42. const organization = Organization({
  43. features,
  44. projects: projects ? projects : [project],
  45. });
  46. const initialData = initializeOrg({
  47. organization,
  48. router: {
  49. location: {
  50. query: {
  51. transaction: '/performance',
  52. project: project.id,
  53. transactionCursor: '1:0:0',
  54. ...query,
  55. },
  56. },
  57. },
  58. });
  59. ProjectsStore.loadInitialData(initialData.organization.projects);
  60. TeamStore.loadInitialData(teams, false, null);
  61. return initialData;
  62. }
  63. function TestComponent({
  64. router,
  65. ...props
  66. }: React.ComponentProps<typeof TransactionSummary> & {
  67. router: InjectedRouter<Record<string, string>, any>;
  68. }) {
  69. if (!props.organization) {
  70. throw new Error('Missing organization');
  71. }
  72. return (
  73. <QueryClientProvider client={makeTestQueryClient()}>
  74. <RouteContext.Provider value={{router, ...router}}>
  75. <MetricsCardinalityProvider
  76. organization={props.organization}
  77. location={props.location}
  78. >
  79. <TransactionSummary {...props} />
  80. </MetricsCardinalityProvider>
  81. </RouteContext.Provider>
  82. </QueryClientProvider>
  83. );
  84. }
  85. describe('Performance > TransactionSummary', function () {
  86. let eventStatsMock: jest.Mock;
  87. beforeEach(function () {
  88. // eslint-disable-next-line no-console
  89. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  90. MockApiClient.clearMockResponses();
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/projects/',
  93. body: [],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/tags/',
  97. body: [],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: '/organizations/org-slug/tags/user.email/values/',
  101. body: [],
  102. });
  103. eventStatsMock = MockApiClient.addMockResponse({
  104. url: '/organizations/org-slug/events-stats/',
  105. body: {data: [[123, []]]},
  106. });
  107. MockApiClient.addMockResponse({
  108. url: '/organizations/org-slug/releases/stats/',
  109. body: [],
  110. });
  111. MockApiClient.addMockResponse({
  112. url: '/organizations/org-slug/issues/?limit=5&project=2&query=is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  113. body: [],
  114. });
  115. MockApiClient.addMockResponse({
  116. url: '/organizations/org-slug/users/',
  117. body: [],
  118. });
  119. MockApiClient.addMockResponse({
  120. url: '/organizations/org-slug/recent-searches/',
  121. body: [],
  122. });
  123. MockApiClient.addMockResponse({
  124. url: '/organizations/org-slug/recent-searches/',
  125. method: 'POST',
  126. body: [],
  127. });
  128. MockApiClient.addMockResponse({
  129. url: '/organizations/org-slug/sdk-updates/',
  130. body: [],
  131. });
  132. MockApiClient.addMockResponse({
  133. url: '/prompts-activity/',
  134. body: {},
  135. });
  136. MockApiClient.addMockResponse({
  137. url: '/organizations/org-slug/events-facets-performance/',
  138. body: {},
  139. });
  140. // Events Mock totals for the sidebar and other summary data
  141. MockApiClient.addMockResponse({
  142. url: '/organizations/org-slug/events/',
  143. body: {
  144. meta: {
  145. fields: {
  146. 'count()': 'number',
  147. 'apdex()': 'number',
  148. 'count_miserable_user()': 'number',
  149. 'user_misery()': 'number',
  150. 'count_unique_user()': 'number',
  151. 'p95()': 'number',
  152. 'failure_rate()': 'number',
  153. 'tpm()': 'number',
  154. project_threshold_config: 'string',
  155. },
  156. },
  157. data: [
  158. {
  159. 'count()': 2,
  160. 'apdex()': 0.6,
  161. 'count_miserable_user()': 122,
  162. 'user_misery()': 0.114,
  163. 'count_unique_user()': 1,
  164. 'p95()': 750.123,
  165. 'failure_rate()': 1,
  166. 'tpm()': 1,
  167. project_threshold_config: ['duration', 300],
  168. },
  169. ],
  170. },
  171. match: [
  172. (_url, options) => {
  173. return options.query?.field?.includes('p95()');
  174. },
  175. ],
  176. });
  177. // [Metrics Enhanced] Events Mock totals for the sidebar and other summary data
  178. MockApiClient.addMockResponse({
  179. url: '/organizations/org-slug/events/',
  180. body: {
  181. meta: {
  182. fields: {
  183. 'count()': 'number',
  184. 'apdex()': 'number',
  185. 'count_miserable_user()': 'number',
  186. 'user_misery()': 'number',
  187. 'count_unique_user()': 'number',
  188. 'p95()': 'number',
  189. 'failure_rate()': 'number',
  190. 'tpm()': 'number',
  191. project_threshold_config: 'string',
  192. },
  193. isMetricsData: true,
  194. },
  195. data: [
  196. {
  197. 'count()': 200,
  198. 'apdex()': 0.5,
  199. 'count_miserable_user()': 120,
  200. 'user_misery()': 0.1,
  201. 'count_unique_user()': 100,
  202. 'p95()': 731.3132,
  203. 'failure_rate()': 1,
  204. 'tpm()': 100,
  205. project_threshold_config: ['duration', 300],
  206. },
  207. ],
  208. },
  209. match: [
  210. (_url, options) => {
  211. const isMetricsEnhanced =
  212. options.query?.dataset === DiscoverDatasets.METRICS_ENHANCED;
  213. return options.query?.field?.includes('p95()') && isMetricsEnhanced;
  214. },
  215. ],
  216. });
  217. // Events Mock unfiltered totals for percentage calculations
  218. MockApiClient.addMockResponse({
  219. url: '/organizations/org-slug/events/',
  220. body: {
  221. meta: {
  222. fields: {
  223. 'tpm()': 'number',
  224. },
  225. },
  226. data: [
  227. {
  228. 'tpm()': 1,
  229. },
  230. ],
  231. },
  232. match: [
  233. (_url, options) => {
  234. return (
  235. options.query?.field?.includes('tpm()') &&
  236. !options.query?.field?.includes('p95()')
  237. );
  238. },
  239. ],
  240. });
  241. // Events Mock count totals for histogram percentage calculations
  242. MockApiClient.addMockResponse({
  243. url: '/organizations/org-slug/events/',
  244. body: {
  245. meta: {
  246. fields: {
  247. 'count()': 'number',
  248. },
  249. },
  250. data: [
  251. {
  252. 'count()': 2,
  253. },
  254. ],
  255. },
  256. match: [
  257. (_url, options) => {
  258. return (
  259. options.query?.field?.includes('count()') &&
  260. !options.query?.field?.includes('p95()')
  261. );
  262. },
  263. ],
  264. });
  265. // Events Transaction list response
  266. MockApiClient.addMockResponse({
  267. url: '/organizations/org-slug/events/',
  268. headers: {
  269. Link:
  270. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  271. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  272. },
  273. body: {
  274. meta: {
  275. fields: {
  276. id: 'string',
  277. 'user.display': 'string',
  278. 'transaction.duration': 'duration',
  279. 'project.id': 'integer',
  280. timestamp: 'date',
  281. },
  282. },
  283. data: [
  284. {
  285. id: 'deadbeef',
  286. 'user.display': 'uhoh@example.com',
  287. 'transaction.duration': 400,
  288. 'project.id': 2,
  289. timestamp: '2020-05-21T15:31:18+00:00',
  290. },
  291. ],
  292. },
  293. match: [
  294. (_url, options) => {
  295. return options.query?.field?.includes('user.display');
  296. },
  297. ],
  298. });
  299. // Events Mock totals for status breakdown
  300. MockApiClient.addMockResponse({
  301. url: '/organizations/org-slug/events/',
  302. body: {
  303. meta: {
  304. fields: {
  305. 'transaction.status': 'string',
  306. 'count()': 'number',
  307. },
  308. },
  309. data: [
  310. {
  311. 'count()': 2,
  312. 'transaction.status': 'ok',
  313. },
  314. ],
  315. },
  316. match: [
  317. (_url, options) => {
  318. return options.query?.field?.includes('transaction.status');
  319. },
  320. ],
  321. });
  322. MockApiClient.addMockResponse({
  323. url: '/organizations/org-slug/events-facets/',
  324. body: [
  325. {
  326. key: 'release',
  327. topValues: [{count: 3, value: 'abcd123', name: 'abcd123'}],
  328. },
  329. {
  330. key: 'environment',
  331. topValues: [
  332. {count: 2, value: 'dev', name: 'dev'},
  333. {count: 1, value: 'prod', name: 'prod'},
  334. ],
  335. },
  336. {
  337. key: 'foo',
  338. topValues: [
  339. {count: 2, value: 'bar', name: 'bar'},
  340. {count: 1, value: 'baz', name: 'baz'},
  341. ],
  342. },
  343. {
  344. key: 'user',
  345. topValues: [
  346. {count: 2, value: 'id:100', name: '100'},
  347. {count: 1, value: 'id:101', name: '101'},
  348. ],
  349. },
  350. ],
  351. });
  352. MockApiClient.addMockResponse({
  353. url: '/organizations/org-slug/project-transaction-threshold-override/',
  354. method: 'GET',
  355. body: {
  356. threshold: '800',
  357. metric: 'lcp',
  358. },
  359. });
  360. MockApiClient.addMockResponse({
  361. url: '/organizations/org-slug/events-vitals/',
  362. body: {
  363. 'measurements.fcp': {
  364. poor: 3,
  365. meh: 100,
  366. good: 47,
  367. total: 150,
  368. p75: 1500,
  369. },
  370. 'measurements.lcp': {
  371. poor: 2,
  372. meh: 38,
  373. good: 40,
  374. total: 80,
  375. p75: 2750,
  376. },
  377. 'measurements.fid': {
  378. poor: 2,
  379. meh: 53,
  380. good: 5,
  381. total: 60,
  382. p75: 1000,
  383. },
  384. 'measurements.cls': {
  385. poor: 3,
  386. meh: 10,
  387. good: 4,
  388. total: 17,
  389. p75: 0.2,
  390. },
  391. },
  392. });
  393. MockApiClient.addMockResponse({
  394. method: 'GET',
  395. url: `/organizations/org-slug/key-transactions-list/`,
  396. body: teams.map(({id}) => ({
  397. team: id,
  398. count: 0,
  399. keyed: [],
  400. })),
  401. });
  402. MockApiClient.addMockResponse({
  403. url: '/organizations/org-slug/events-has-measurements/',
  404. body: {measurements: false},
  405. });
  406. MockApiClient.addMockResponse({
  407. url: '/organizations/org-slug/events-spans-performance/',
  408. body: [
  409. {
  410. op: 'ui.long-task',
  411. group: 'c777169faad84eb4',
  412. description: 'Main UI thread blocked',
  413. frequency: 713,
  414. count: 9040,
  415. avgOccurrences: null,
  416. sumExclusiveTime: 1743893.9822921753,
  417. p50ExclusiveTime: null,
  418. p75ExclusiveTime: 244.9998779296875,
  419. p95ExclusiveTime: null,
  420. p99ExclusiveTime: null,
  421. },
  422. ],
  423. });
  424. MockApiClient.addMockResponse({
  425. url: `/projects/org-slug/project-slug/profiling/functions/`,
  426. body: {functions: []},
  427. });
  428. MockApiClient.addMockResponse({
  429. method: 'GET',
  430. url: `/organizations/org-slug/metrics-compatibility/`,
  431. body: {
  432. compatible_projects: [],
  433. incompatible_projecs: [],
  434. },
  435. });
  436. MockApiClient.addMockResponse({
  437. method: 'GET',
  438. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  439. body: {
  440. sum: {
  441. metrics: 100,
  442. metrics_null: 0,
  443. metrics_unparam: 0,
  444. },
  445. },
  446. });
  447. jest.spyOn(MEPSetting, 'get').mockImplementation(() => MEPState.AUTO);
  448. });
  449. afterEach(function () {
  450. MockApiClient.clearMockResponses();
  451. ProjectsStore.reset();
  452. jest.clearAllMocks();
  453. });
  454. describe('with events', function () {
  455. it('renders basic UI elements', async function () {
  456. const {organization, router, routerContext} = initializeData();
  457. render(
  458. <TestComponent
  459. organization={organization}
  460. router={router}
  461. location={router.location}
  462. />,
  463. {
  464. context: routerContext,
  465. organization,
  466. }
  467. );
  468. // It shows the header
  469. await screen.findByText('Transaction Summary');
  470. expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
  471. // It shows a chart
  472. expect(
  473. screen.getByRole('button', {name: 'Display Duration Breakdown'})
  474. ).toBeInTheDocument();
  475. // It shows a searchbar
  476. expect(screen.getByLabelText('Search events')).toBeInTheDocument();
  477. // It shows a table
  478. expect(screen.getByTestId('transactions-table')).toBeInTheDocument();
  479. // Ensure open in discover button exists.
  480. expect(screen.getByTestId('transaction-events-open')).toBeInTheDocument();
  481. // Ensure open issues button exists.
  482. expect(screen.getByRole('button', {name: 'Open in Issues'})).toBeInTheDocument();
  483. // Ensure transaction filter button exists
  484. expect(
  485. screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
  486. ).toBeInTheDocument();
  487. // Ensure create alert from discover is hidden without metric alert
  488. expect(
  489. screen.queryByRole('button', {name: 'Create Alert'})
  490. ).not.toBeInTheDocument();
  491. // Ensure status breakdown exists
  492. expect(screen.getByText('Status Breakdown')).toBeInTheDocument();
  493. });
  494. it('renders feature flagged UI elements', function () {
  495. const {organization, router, routerContext} = initializeData({
  496. features: ['incidents'],
  497. });
  498. render(
  499. <TestComponent
  500. organization={organization}
  501. router={router}
  502. location={router.location}
  503. />,
  504. {
  505. context: routerContext,
  506. organization,
  507. }
  508. );
  509. // Ensure create alert from discover is shown with metric alerts
  510. expect(screen.getByRole('button', {name: 'Create Alert'})).toBeInTheDocument();
  511. });
  512. it('renders Web Vitals widget', async function () {
  513. const {organization, router, routerContext} = initializeData({
  514. project: TestStubs.Project({teams, platform: 'javascript'}),
  515. query: {
  516. query:
  517. 'transaction.duration:<15m transaction.op:pageload event.type:transaction transaction:/organizations/:orgId/issues/',
  518. },
  519. });
  520. render(
  521. <TestComponent
  522. organization={organization}
  523. router={router}
  524. location={router.location}
  525. />,
  526. {
  527. context: routerContext,
  528. organization,
  529. }
  530. );
  531. // It renders the web vitals widget
  532. await screen.findByRole('heading', {name: 'Web Vitals'});
  533. const vitalStatues = screen.getAllByTestId('vital-status');
  534. expect(vitalStatues).toHaveLength(3);
  535. expect(vitalStatues[0]).toHaveTextContent('31%');
  536. expect(vitalStatues[1]).toHaveTextContent('65%');
  537. expect(vitalStatues[2]).toHaveTextContent('3%');
  538. });
  539. it('renders sidebar widgets', async function () {
  540. const {organization, router, routerContext} = initializeData({});
  541. render(
  542. <TestComponent
  543. organization={organization}
  544. router={router}
  545. location={router.location}
  546. />,
  547. {
  548. context: routerContext,
  549. organization,
  550. }
  551. );
  552. // Renders Apdex widget
  553. await screen.findByRole('heading', {name: 'Apdex'});
  554. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  555. // Renders Failure Rate widget
  556. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  557. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  558. // Renders TPM widget
  559. expect(
  560. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  561. ).toBeInTheDocument();
  562. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  563. '100%'
  564. );
  565. });
  566. it('renders project picker modal when no url does not have project id', async function () {
  567. MockApiClient.addMockResponse({
  568. url: '/organizations/org-slug/events/',
  569. body: {
  570. meta: {
  571. fields: {
  572. project: 'string',
  573. 'count()': 'number',
  574. },
  575. },
  576. data: [
  577. {
  578. 'count()': 2,
  579. project: 'proj-slug-1',
  580. },
  581. {
  582. 'count()': 3,
  583. project: 'proj-slug-2',
  584. },
  585. ],
  586. },
  587. match: [
  588. (_url, options) => {
  589. return options.query?.field?.includes('project');
  590. },
  591. ],
  592. });
  593. const projects = [
  594. TestStubs.Project({
  595. slug: 'proj-slug-1',
  596. id: '1',
  597. name: 'Project Name 1',
  598. }),
  599. TestStubs.Project({
  600. slug: 'proj-slug-2',
  601. id: '2',
  602. name: 'Project Name 2',
  603. }),
  604. ];
  605. OrganizationStore.onUpdate(Organization({slug: 'org-slug'}), {
  606. replace: true,
  607. });
  608. const {organization, router, routerContext} = initializeData({projects});
  609. const spy = jest.spyOn(router, 'replace');
  610. // Ensure project id is not in path
  611. delete router.location.query.project;
  612. render(
  613. <TestComponent
  614. organization={organization}
  615. router={router}
  616. location={router.location}
  617. />,
  618. {
  619. context: routerContext,
  620. organization,
  621. projects,
  622. }
  623. );
  624. renderGlobalModal();
  625. const firstProjectOption = await screen.findByText('proj-slug-1');
  626. expect(firstProjectOption).toBeInTheDocument();
  627. expect(screen.getByText('proj-slug-2')).toBeInTheDocument();
  628. expect(screen.getByText('My Projects')).toBeInTheDocument();
  629. await userEvent.click(firstProjectOption);
  630. expect(spy).toHaveBeenCalledWith(
  631. '/organizations/org-slug/performance/summary/?transaction=/performance&statsPeriod=14d&referrer=performance-transaction-summary&transactionCursor=1:0:0&project=1'
  632. );
  633. });
  634. it('fetches transaction threshold', function () {
  635. const {organization, router, routerContext} = initializeData();
  636. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  637. url: '/organizations/org-slug/project-transaction-threshold-override/',
  638. method: 'GET',
  639. body: {
  640. threshold: '800',
  641. metric: 'lcp',
  642. },
  643. });
  644. const getProjectThresholdMock = MockApiClient.addMockResponse({
  645. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  646. method: 'GET',
  647. body: {
  648. threshold: '200',
  649. metric: 'duration',
  650. },
  651. });
  652. render(
  653. <TestComponent
  654. organization={organization}
  655. router={router}
  656. location={router.location}
  657. />,
  658. {
  659. context: routerContext,
  660. organization,
  661. }
  662. );
  663. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  664. expect(getProjectThresholdMock).not.toHaveBeenCalled();
  665. });
  666. it('fetches project transaction threshdold', async function () {
  667. const {organization, router, routerContext} = initializeData();
  668. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  669. url: '/organizations/org-slug/project-transaction-threshold-override/',
  670. method: 'GET',
  671. statusCode: 404,
  672. });
  673. const getProjectThresholdMock = MockApiClient.addMockResponse({
  674. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  675. method: 'GET',
  676. body: {
  677. threshold: '200',
  678. metric: 'duration',
  679. },
  680. });
  681. render(
  682. <TestComponent
  683. organization={organization}
  684. router={router}
  685. location={router.location}
  686. />,
  687. {
  688. context: routerContext,
  689. organization,
  690. }
  691. );
  692. await screen.findByText('Transaction Summary');
  693. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  694. expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
  695. });
  696. it('triggers a navigation on search', async function () {
  697. const {organization, router, routerContext} = initializeData();
  698. render(
  699. <TestComponent
  700. organization={organization}
  701. router={router}
  702. location={router.location}
  703. />,
  704. {
  705. context: routerContext,
  706. organization,
  707. }
  708. );
  709. // Fill out the search box, and submit it.
  710. await userEvent.type(
  711. screen.getByLabelText('Search events'),
  712. 'user.email:uhoh*{enter}'
  713. );
  714. // Check the navigation.
  715. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  716. expect(browserHistory.push).toHaveBeenCalledWith({
  717. pathname: undefined,
  718. query: {
  719. transaction: '/performance',
  720. project: '2',
  721. statsPeriod: '14d',
  722. query: 'user.email:uhoh*',
  723. transactionCursor: '1:0:0',
  724. },
  725. });
  726. });
  727. it('can mark a transaction as key', async function () {
  728. const {organization, router, routerContext} = initializeData();
  729. render(
  730. <TestComponent
  731. organization={organization}
  732. router={router}
  733. location={router.location}
  734. />,
  735. {
  736. context: routerContext,
  737. organization,
  738. }
  739. );
  740. const mockUpdate = MockApiClient.addMockResponse({
  741. url: `/organizations/org-slug/key-transactions/`,
  742. method: 'POST',
  743. body: {},
  744. });
  745. await screen.findByRole('button', {name: 'Star for Team'});
  746. // Click the key transaction button
  747. await userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
  748. await userEvent.click(screen.getByRole('option', {name: '#team1'}));
  749. // Ensure request was made.
  750. expect(mockUpdate).toHaveBeenCalled();
  751. });
  752. it('triggers a navigation on transaction filter', async function () {
  753. const {organization, router, routerContext} = initializeData();
  754. render(
  755. <TestComponent
  756. organization={organization}
  757. router={router}
  758. location={router.location}
  759. />,
  760. {
  761. context: routerContext,
  762. organization,
  763. }
  764. );
  765. await screen.findByText('Transaction Summary');
  766. await waitFor(() => {
  767. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  768. });
  769. // Open the transaction filter dropdown
  770. await userEvent.click(
  771. screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
  772. );
  773. await userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
  774. // Check the navigation.
  775. expect(browserHistory.push).toHaveBeenCalledWith({
  776. pathname: undefined,
  777. query: {
  778. transaction: '/performance',
  779. project: '2',
  780. showTransactions: 'slow',
  781. transactionCursor: undefined,
  782. },
  783. });
  784. });
  785. it('renders pagination buttons', async function () {
  786. const {organization, router, routerContext} = initializeData();
  787. render(
  788. <TestComponent
  789. organization={organization}
  790. router={router}
  791. location={router.location}
  792. />,
  793. {
  794. context: routerContext,
  795. organization,
  796. }
  797. );
  798. await screen.findByText('Transaction Summary');
  799. expect(await screen.findByLabelText('Previous')).toBeInTheDocument();
  800. // Click the 'next' button
  801. await userEvent.click(screen.getByLabelText('Next'));
  802. // Check the navigation.
  803. expect(browserHistory.push).toHaveBeenCalledWith({
  804. pathname: undefined,
  805. query: {
  806. transaction: '/performance',
  807. project: '2',
  808. transactionCursor: '2:0:0',
  809. },
  810. });
  811. });
  812. it('forwards conditions to related issues', async function () {
  813. const issueGet = MockApiClient.addMockResponse({
  814. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  815. body: [],
  816. });
  817. const {organization, router, routerContext} = initializeData({
  818. query: {query: 'tag:value'},
  819. });
  820. render(
  821. <TestComponent
  822. organization={organization}
  823. router={router}
  824. location={router.location}
  825. />,
  826. {
  827. context: routerContext,
  828. organization,
  829. }
  830. );
  831. await screen.findByText('Transaction Summary');
  832. expect(issueGet).toHaveBeenCalled();
  833. });
  834. it('does not forward event type to related issues', async function () {
  835. const issueGet = MockApiClient.addMockResponse({
  836. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  837. body: [],
  838. match: [
  839. (_, options) => {
  840. // event.type must NOT be in the query params
  841. return !options.query?.query?.includes('event.type');
  842. },
  843. ],
  844. });
  845. const {organization, router, routerContext} = initializeData({
  846. query: {query: 'tag:value event.type:transaction'},
  847. });
  848. render(
  849. <TestComponent
  850. organization={organization}
  851. router={router}
  852. location={router.location}
  853. />,
  854. {
  855. context: routerContext,
  856. organization,
  857. }
  858. );
  859. await screen.findByText('Transaction Summary');
  860. expect(issueGet).toHaveBeenCalled();
  861. });
  862. it('renders the suspect spans table if the feature is enabled', async function () {
  863. MockApiClient.addMockResponse({
  864. url: '/organizations/org-slug/events-spans-performance/',
  865. body: [],
  866. });
  867. const {organization, router, routerContext} = initializeData();
  868. render(
  869. <TestComponent
  870. organization={organization}
  871. router={router}
  872. location={router.location}
  873. />,
  874. {
  875. context: routerContext,
  876. organization,
  877. }
  878. );
  879. expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
  880. });
  881. it('adds search condition on transaction status when clicking on status breakdown', async function () {
  882. const {organization, router, routerContext} = initializeData();
  883. render(
  884. <TestComponent
  885. organization={organization}
  886. router={router}
  887. location={router.location}
  888. />,
  889. {
  890. context: routerContext,
  891. organization,
  892. }
  893. );
  894. await screen.findByTestId('status-ok');
  895. await userEvent.click(screen.getByTestId('status-ok'));
  896. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  897. expect(browserHistory.push).toHaveBeenCalledWith(
  898. expect.objectContaining({
  899. query: expect.objectContaining({
  900. query: expect.stringContaining('transaction.status:ok'),
  901. }),
  902. })
  903. );
  904. });
  905. it('appends tag value to existing query when clicked', async function () {
  906. const {organization, router, routerContext} = initializeData();
  907. render(
  908. <TestComponent
  909. organization={organization}
  910. router={router}
  911. location={router.location}
  912. />,
  913. {
  914. context: routerContext,
  915. organization,
  916. }
  917. );
  918. await screen.findByText('Tag Summary');
  919. await userEvent.click(
  920. await screen.findByLabelText(
  921. 'environment, dev, 100% of all events. View events with this tag value.'
  922. )
  923. );
  924. await userEvent.click(
  925. await screen.findByLabelText(
  926. 'foo, bar, 100% of all events. View events with this tag value.'
  927. )
  928. );
  929. expect(router.push).toHaveBeenCalledTimes(2);
  930. expect(router.push).toHaveBeenNthCalledWith(1, {
  931. query: {
  932. project: '2',
  933. query: 'tags[environment]:dev',
  934. transaction: '/performance',
  935. transactionCursor: '1:0:0',
  936. },
  937. });
  938. expect(router.push).toHaveBeenNthCalledWith(2, {
  939. query: {
  940. project: '2',
  941. query: 'foo:bar',
  942. transaction: '/performance',
  943. transactionCursor: '1:0:0',
  944. },
  945. });
  946. });
  947. it('does not use MEP dataset for stats query without features', async function () {
  948. const {organization, router, routerContext} = initializeData({
  949. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  950. features: [''], // No 'dynamic-sampling' feature to indicate it can use metrics dataset or metrics enhanced.
  951. });
  952. render(
  953. <TestComponent
  954. organization={organization}
  955. router={router}
  956. location={router.location}
  957. />,
  958. {
  959. context: routerContext,
  960. organization,
  961. }
  962. );
  963. await screen.findByText('Transaction Summary');
  964. await screen.findByRole('heading', {name: 'Apdex'});
  965. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  966. expect(eventStatsMock).toHaveBeenNthCalledWith(
  967. 1,
  968. expect.anything(),
  969. expect.objectContaining({
  970. query: expect.objectContaining({
  971. environment: [],
  972. interval: '30m',
  973. partial: '1',
  974. project: [2],
  975. query:
  976. 'transaction.op:pageload event.type:transaction transaction:/performance',
  977. referrer: 'api.performance.transaction-summary.duration-chart',
  978. statsPeriod: '14d',
  979. yAxis: [
  980. 'p50(transaction.duration)',
  981. 'p75(transaction.duration)',
  982. 'p95(transaction.duration)',
  983. 'p99(transaction.duration)',
  984. 'p100(transaction.duration)',
  985. 'avg(transaction.duration)',
  986. ],
  987. }),
  988. })
  989. );
  990. });
  991. it('uses MEP dataset for stats query', async function () {
  992. const {organization, router, routerContext} = initializeData({
  993. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  994. features: ['dynamic-sampling', 'mep-rollout-flag'],
  995. });
  996. render(
  997. <TestComponent
  998. organization={organization}
  999. router={router}
  1000. location={router.location}
  1001. />,
  1002. {
  1003. context: routerContext,
  1004. organization,
  1005. }
  1006. );
  1007. await screen.findByText('Transaction Summary');
  1008. // Renders Apdex widget
  1009. await screen.findByRole('heading', {name: 'Apdex'});
  1010. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1011. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1012. 1,
  1013. expect.anything(),
  1014. expect.objectContaining({
  1015. query: expect.objectContaining({
  1016. query:
  1017. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1018. dataset: 'metricsEnhanced',
  1019. }),
  1020. })
  1021. );
  1022. // Renders Failure Rate widget
  1023. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1024. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1025. // Renders TPM widget
  1026. expect(
  1027. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1028. ).toBeInTheDocument();
  1029. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1030. '100%'
  1031. );
  1032. expect(
  1033. screen.queryByTestId('search-metrics-fallback-warning')
  1034. ).not.toBeInTheDocument();
  1035. });
  1036. it('does not use MEP dataset for stats query if cardinality fallback fails', async function () {
  1037. MockApiClient.addMockResponse({
  1038. method: 'GET',
  1039. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  1040. body: {
  1041. sum: {
  1042. metrics: 100,
  1043. metrics_null: 100,
  1044. metrics_unparam: 0,
  1045. },
  1046. },
  1047. });
  1048. const {organization, router, routerContext} = initializeData({
  1049. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  1050. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1051. });
  1052. render(
  1053. <TestComponent
  1054. organization={organization}
  1055. router={router}
  1056. location={router.location}
  1057. />,
  1058. {
  1059. context: routerContext,
  1060. organization,
  1061. }
  1062. );
  1063. await screen.findByText('Transaction Summary');
  1064. // Renders Apdex widget
  1065. await screen.findByRole('heading', {name: 'Apdex'});
  1066. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  1067. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1068. 1,
  1069. expect.anything(),
  1070. expect.objectContaining({
  1071. query: expect.objectContaining({
  1072. query:
  1073. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1074. }),
  1075. })
  1076. );
  1077. // Renders TPM widget
  1078. expect(
  1079. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1080. ).toBeInTheDocument();
  1081. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1082. '100%'
  1083. );
  1084. });
  1085. it('uses MEP dataset for stats query and shows fallback warning', async function () {
  1086. MockApiClient.addMockResponse({
  1087. url: '/organizations/org-slug/issues/?limit=5&project=2&query=has%3Anot-compatible%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  1088. body: [],
  1089. });
  1090. MockApiClient.addMockResponse({
  1091. url: '/organizations/org-slug/events/',
  1092. body: {
  1093. meta: {
  1094. fields: {
  1095. 'count()': 'number',
  1096. 'apdex()': 'number',
  1097. 'count_miserable_user()': 'number',
  1098. 'user_misery()': 'number',
  1099. 'count_unique_user()': 'number',
  1100. 'p95()': 'number',
  1101. 'failure_rate()': 'number',
  1102. 'tpm()': 'number',
  1103. project_threshold_config: 'string',
  1104. },
  1105. isMetricsData: false, // The total response is setting the metrics fallback behaviour.
  1106. },
  1107. data: [
  1108. {
  1109. 'count()': 200,
  1110. 'apdex()': 0.5,
  1111. 'count_miserable_user()': 120,
  1112. 'user_misery()': 0.1,
  1113. 'count_unique_user()': 100,
  1114. 'p95()': 731.3132,
  1115. 'failure_rate()': 1,
  1116. 'tpm()': 100,
  1117. project_threshold_config: ['duration', 300],
  1118. },
  1119. ],
  1120. },
  1121. match: [
  1122. (_url, options) => {
  1123. const isMetricsEnhanced =
  1124. options.query?.dataset === DiscoverDatasets.METRICS_ENHANCED;
  1125. return (
  1126. options.query?.field?.includes('p95()') &&
  1127. isMetricsEnhanced &&
  1128. options.query?.query?.includes('not-compatible')
  1129. );
  1130. },
  1131. ],
  1132. });
  1133. const {organization, router, routerContext} = initializeData({
  1134. query: {query: 'transaction.op:pageload has:not-compatible'}, // Adds incompatible w/ metrics tag
  1135. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1136. });
  1137. render(
  1138. <TestComponent
  1139. organization={organization}
  1140. router={router}
  1141. location={router.location}
  1142. />,
  1143. {
  1144. context: routerContext,
  1145. organization,
  1146. }
  1147. );
  1148. await screen.findByText('Transaction Summary');
  1149. // Renders Apdex widget
  1150. await screen.findByRole('heading', {name: 'Apdex'});
  1151. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1152. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1153. 1,
  1154. expect.anything(),
  1155. expect.objectContaining({
  1156. query: expect.objectContaining({
  1157. query:
  1158. 'transaction.op:pageload has:not-compatible event.type:transaction transaction:/performance',
  1159. dataset: 'metricsEnhanced',
  1160. }),
  1161. })
  1162. );
  1163. // Renders Failure Rate widget
  1164. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1165. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1166. // Renders TPM widget
  1167. expect(
  1168. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1169. ).toBeInTheDocument();
  1170. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1171. '100%'
  1172. );
  1173. expect(screen.getByTestId('search-metrics-fallback-warning')).toBeInTheDocument();
  1174. });
  1175. });
  1176. });