index.spec.tsx 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. import type {InjectedRouter} from 'react-router';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {TeamFixture} from 'sentry-fixture/team';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {makeTestQueryClient} from 'sentry-test/queryClient';
  7. import {
  8. render,
  9. renderGlobalModal,
  10. screen,
  11. userEvent,
  12. waitFor,
  13. } from 'sentry-test/reactTestingLibrary';
  14. import OrganizationStore from 'sentry/stores/organizationStore';
  15. import ProjectsStore from 'sentry/stores/projectsStore';
  16. import TeamStore from 'sentry/stores/teamStore';
  17. import type {Project} from 'sentry/types/project';
  18. import {browserHistory} from 'sentry/utils/browserHistory';
  19. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  20. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  21. import {
  22. MEPSetting,
  23. MEPState,
  24. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  25. import {QueryClientProvider} from 'sentry/utils/queryClient';
  26. import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';
  27. const teams = [
  28. TeamFixture({id: '1', slug: 'team1', name: 'Team 1'}),
  29. TeamFixture({id: '2', slug: 'team2', name: 'Team 2'}),
  30. ];
  31. function initializeData({
  32. features: additionalFeatures = [],
  33. query = {},
  34. project: prj,
  35. projects,
  36. }: {
  37. features?: string[];
  38. project?: Project;
  39. projects?: Project[];
  40. query?: Record<string, any>;
  41. } = {}) {
  42. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  43. const project = prj ?? ProjectFixture({teams});
  44. const organization = OrganizationFixture({
  45. features,
  46. });
  47. const initialData = initializeOrg({
  48. organization,
  49. projects: projects ? projects : [project],
  50. router: {
  51. location: {
  52. pathname: '/',
  53. query: {
  54. transaction: '/performance',
  55. project: project.id,
  56. transactionCursor: '1:0:0',
  57. ...query,
  58. },
  59. },
  60. },
  61. });
  62. ProjectsStore.loadInitialData(initialData.projects);
  63. TeamStore.loadInitialData(teams, false, null);
  64. return initialData;
  65. }
  66. function TestComponent({
  67. ...props
  68. }: React.ComponentProps<typeof TransactionSummary> & {
  69. router: InjectedRouter<Record<string, string>, any>;
  70. }) {
  71. if (!props.organization) {
  72. throw new Error('Missing organization');
  73. }
  74. return (
  75. <QueryClientProvider client={makeTestQueryClient()}>
  76. <MetricsCardinalityProvider
  77. organization={props.organization}
  78. location={props.location}
  79. >
  80. <TransactionSummary {...props} />
  81. </MetricsCardinalityProvider>
  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=trends&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: '/organizations/org-slug/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} = initializeData();
  457. render(
  458. <TestComponent
  459. organization={organization}
  460. router={router}
  461. location={router.location}
  462. />,
  463. {
  464. router,
  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} = initializeData({
  496. features: ['incidents'],
  497. });
  498. render(
  499. <TestComponent
  500. organization={organization}
  501. router={router}
  502. location={router.location}
  503. />,
  504. {
  505. router,
  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} = initializeData({
  514. project: ProjectFixture({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. router,
  528. organization,
  529. }
  530. );
  531. // It renders the web vitals widget
  532. await screen.findByRole('heading', {name: 'Web Vitals'});
  533. await waitFor(() => {
  534. expect(screen.getAllByTestId('vital-status')).toHaveLength(3);
  535. });
  536. const vitalStatues = screen.getAllByTestId('vital-status');
  537. expect(vitalStatues[0]).toHaveTextContent('31%');
  538. expect(vitalStatues[1]).toHaveTextContent('65%');
  539. expect(vitalStatues[2]).toHaveTextContent('3%');
  540. });
  541. it('renders sidebar widgets', async function () {
  542. const {organization, router} = initializeData({});
  543. render(
  544. <TestComponent
  545. organization={organization}
  546. router={router}
  547. location={router.location}
  548. />,
  549. {
  550. router,
  551. organization,
  552. }
  553. );
  554. // Renders Apdex widget
  555. await screen.findByRole('heading', {name: 'Apdex'});
  556. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  557. // Renders Failure Rate widget
  558. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  559. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  560. });
  561. it('renders project picker modal when no url does not have project id', async function () {
  562. MockApiClient.addMockResponse({
  563. url: '/organizations/org-slug/events/',
  564. body: {
  565. meta: {
  566. fields: {
  567. project: 'string',
  568. 'count()': 'number',
  569. },
  570. },
  571. data: [
  572. {
  573. 'count()': 2,
  574. project: 'proj-slug-1',
  575. },
  576. {
  577. 'count()': 3,
  578. project: 'proj-slug-2',
  579. },
  580. ],
  581. },
  582. match: [
  583. (_url, options) => {
  584. return options.query?.field?.includes('project');
  585. },
  586. ],
  587. });
  588. const projects = [
  589. ProjectFixture({
  590. slug: 'proj-slug-1',
  591. id: '1',
  592. name: 'Project Name 1',
  593. }),
  594. ProjectFixture({
  595. slug: 'proj-slug-2',
  596. id: '2',
  597. name: 'Project Name 2',
  598. }),
  599. ];
  600. OrganizationStore.onUpdate(OrganizationFixture({slug: 'org-slug'}), {
  601. replace: true,
  602. });
  603. const {organization, router} = initializeData({projects});
  604. const spy = jest.spyOn(router, 'replace');
  605. // Ensure project id is not in path
  606. delete router.location.query.project;
  607. render(
  608. <TestComponent
  609. organization={organization}
  610. router={router}
  611. location={router.location}
  612. />,
  613. {router, organization}
  614. );
  615. renderGlobalModal();
  616. const firstProjectOption = await screen.findByText('proj-slug-1');
  617. expect(firstProjectOption).toBeInTheDocument();
  618. expect(screen.getByText('proj-slug-2')).toBeInTheDocument();
  619. expect(screen.getByText('My Projects')).toBeInTheDocument();
  620. await userEvent.click(firstProjectOption);
  621. expect(spy).toHaveBeenCalledWith(
  622. '/organizations/org-slug/performance/summary/?transaction=/performance&statsPeriod=14d&referrer=performance-transaction-summary&transactionCursor=1:0:0&project=1'
  623. );
  624. });
  625. it('fetches transaction threshold', function () {
  626. const {organization, router} = initializeData();
  627. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  628. url: '/organizations/org-slug/project-transaction-threshold-override/',
  629. method: 'GET',
  630. body: {
  631. threshold: '800',
  632. metric: 'lcp',
  633. },
  634. });
  635. const getProjectThresholdMock = MockApiClient.addMockResponse({
  636. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  637. method: 'GET',
  638. body: {
  639. threshold: '200',
  640. metric: 'duration',
  641. },
  642. });
  643. render(
  644. <TestComponent
  645. organization={organization}
  646. router={router}
  647. location={router.location}
  648. />,
  649. {
  650. router,
  651. organization,
  652. }
  653. );
  654. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  655. expect(getProjectThresholdMock).not.toHaveBeenCalled();
  656. });
  657. it('fetches project transaction threshdold', async function () {
  658. const {organization, router} = initializeData();
  659. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  660. url: '/organizations/org-slug/project-transaction-threshold-override/',
  661. method: 'GET',
  662. statusCode: 404,
  663. });
  664. const getProjectThresholdMock = MockApiClient.addMockResponse({
  665. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  666. method: 'GET',
  667. body: {
  668. threshold: '200',
  669. metric: 'duration',
  670. },
  671. });
  672. render(
  673. <TestComponent
  674. organization={organization}
  675. router={router}
  676. location={router.location}
  677. />,
  678. {
  679. router,
  680. organization,
  681. }
  682. );
  683. await screen.findByText('Transaction Summary');
  684. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  685. expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
  686. });
  687. it('triggers a navigation on search', async function () {
  688. const {organization, router} = initializeData();
  689. render(
  690. <TestComponent
  691. organization={organization}
  692. router={router}
  693. location={router.location}
  694. />,
  695. {
  696. router,
  697. organization,
  698. }
  699. );
  700. // Fill out the search box, and submit it.
  701. await userEvent.type(
  702. screen.getByLabelText('Search events'),
  703. 'user.email:uhoh*{enter}'
  704. );
  705. // Check the navigation.
  706. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  707. expect(browserHistory.push).toHaveBeenCalledWith({
  708. pathname: '/',
  709. query: {
  710. transaction: '/performance',
  711. project: '2',
  712. statsPeriod: '14d',
  713. query: 'user.email:uhoh*',
  714. transactionCursor: '1:0:0',
  715. },
  716. });
  717. });
  718. it('can mark a transaction as key', async function () {
  719. const {organization, router} = initializeData();
  720. render(
  721. <TestComponent
  722. organization={organization}
  723. router={router}
  724. location={router.location}
  725. />,
  726. {
  727. router,
  728. organization,
  729. }
  730. );
  731. const mockUpdate = MockApiClient.addMockResponse({
  732. url: `/organizations/org-slug/key-transactions/`,
  733. method: 'POST',
  734. body: {},
  735. });
  736. await screen.findByRole('button', {name: 'Star for Team'});
  737. // Click the key transaction button
  738. await userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
  739. await userEvent.click(screen.getByRole('option', {name: '#team1'}));
  740. // Ensure request was made.
  741. expect(mockUpdate).toHaveBeenCalled();
  742. });
  743. it('triggers a navigation on transaction filter', async function () {
  744. const {organization, router} = initializeData();
  745. render(
  746. <TestComponent
  747. organization={organization}
  748. router={router}
  749. location={router.location}
  750. />,
  751. {
  752. router,
  753. organization,
  754. }
  755. );
  756. await screen.findByText('Transaction Summary');
  757. await waitFor(() => {
  758. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  759. });
  760. // Open the transaction filter dropdown
  761. await userEvent.click(
  762. screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
  763. );
  764. await userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
  765. // Check the navigation.
  766. expect(browserHistory.push).toHaveBeenCalledWith({
  767. pathname: '/',
  768. query: {
  769. transaction: '/performance',
  770. project: '2',
  771. showTransactions: 'slow',
  772. transactionCursor: undefined,
  773. },
  774. });
  775. });
  776. it('renders pagination buttons', async function () {
  777. const {organization, router} = initializeData();
  778. render(
  779. <TestComponent
  780. organization={organization}
  781. router={router}
  782. location={router.location}
  783. />,
  784. {
  785. router,
  786. organization,
  787. }
  788. );
  789. await screen.findByText('Transaction Summary');
  790. expect(await screen.findByLabelText('Previous')).toBeInTheDocument();
  791. // Click the 'next' button
  792. await userEvent.click(screen.getByLabelText('Next'));
  793. // Check the navigation.
  794. expect(browserHistory.push).toHaveBeenCalledWith({
  795. pathname: '/',
  796. query: {
  797. transaction: '/performance',
  798. project: '2',
  799. transactionCursor: '2:0:0',
  800. },
  801. });
  802. });
  803. it('forwards conditions to related issues', async function () {
  804. const issueGet = MockApiClient.addMockResponse({
  805. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=trends&statsPeriod=14d',
  806. body: [],
  807. });
  808. const {organization, router} = initializeData({
  809. query: {query: 'tag:value'},
  810. });
  811. render(
  812. <TestComponent
  813. organization={organization}
  814. router={router}
  815. location={router.location}
  816. />,
  817. {
  818. router,
  819. organization,
  820. }
  821. );
  822. await screen.findByText('Transaction Summary');
  823. expect(issueGet).toHaveBeenCalled();
  824. });
  825. it('does not forward event type to related issues', async function () {
  826. const issueGet = MockApiClient.addMockResponse({
  827. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=trends&statsPeriod=14d',
  828. body: [],
  829. match: [
  830. (_, options) => {
  831. // event.type must NOT be in the query params
  832. return !options.query?.query?.includes('event.type');
  833. },
  834. ],
  835. });
  836. const {organization, router} = initializeData({
  837. query: {query: 'tag:value event.type:transaction'},
  838. });
  839. render(
  840. <TestComponent
  841. organization={organization}
  842. router={router}
  843. location={router.location}
  844. />,
  845. {
  846. router,
  847. organization,
  848. }
  849. );
  850. await screen.findByText('Transaction Summary');
  851. expect(issueGet).toHaveBeenCalled();
  852. });
  853. it('renders the suspect spans table if the feature is enabled', async function () {
  854. MockApiClient.addMockResponse({
  855. url: '/organizations/org-slug/events-spans-performance/',
  856. body: [],
  857. });
  858. const {organization, router} = initializeData();
  859. render(
  860. <TestComponent
  861. organization={organization}
  862. router={router}
  863. location={router.location}
  864. />,
  865. {
  866. router,
  867. organization,
  868. }
  869. );
  870. expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
  871. });
  872. it('adds search condition on transaction status when clicking on status breakdown', async function () {
  873. const {organization, router} = initializeData();
  874. render(
  875. <TestComponent
  876. organization={organization}
  877. router={router}
  878. location={router.location}
  879. />,
  880. {
  881. router,
  882. organization,
  883. }
  884. );
  885. await screen.findByTestId('status-ok');
  886. await userEvent.click(screen.getByTestId('status-ok'));
  887. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  888. expect(browserHistory.push).toHaveBeenCalledWith(
  889. expect.objectContaining({
  890. query: expect.objectContaining({
  891. query: expect.stringContaining('transaction.status:ok'),
  892. }),
  893. })
  894. );
  895. });
  896. it('appends tag value to existing query when clicked', async function () {
  897. const {organization, router} = initializeData();
  898. render(
  899. <TestComponent
  900. organization={organization}
  901. router={router}
  902. location={router.location}
  903. />,
  904. {
  905. router,
  906. organization,
  907. }
  908. );
  909. await screen.findByText('Tag Summary');
  910. await userEvent.click(
  911. await screen.findByLabelText(
  912. 'environment, dev, 100% of all events. View events with this tag value.'
  913. )
  914. );
  915. await userEvent.click(
  916. await screen.findByLabelText(
  917. 'foo, bar, 100% of all events. View events with this tag value.'
  918. )
  919. );
  920. expect(router.push).toHaveBeenCalledTimes(2);
  921. expect(router.push).toHaveBeenNthCalledWith(1, {
  922. pathname: '/',
  923. query: {
  924. project: '2',
  925. query: 'tags[environment]:dev',
  926. transaction: '/performance',
  927. transactionCursor: '1:0:0',
  928. },
  929. });
  930. expect(router.push).toHaveBeenNthCalledWith(2, {
  931. pathname: '/',
  932. query: {
  933. project: '2',
  934. query: 'foo:bar',
  935. transaction: '/performance',
  936. transactionCursor: '1:0:0',
  937. },
  938. });
  939. });
  940. it('does not use MEP dataset for stats query without features', async function () {
  941. const {organization, router} = initializeData({
  942. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  943. features: [''], // No 'dynamic-sampling' feature to indicate it can use metrics dataset or metrics enhanced.
  944. });
  945. render(
  946. <TestComponent
  947. organization={organization}
  948. router={router}
  949. location={router.location}
  950. />,
  951. {
  952. router,
  953. organization,
  954. }
  955. );
  956. await screen.findByText('Transaction Summary');
  957. await screen.findByRole('heading', {name: 'Apdex'});
  958. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  959. expect(eventStatsMock).toHaveBeenNthCalledWith(
  960. 1,
  961. expect.anything(),
  962. expect.objectContaining({
  963. query: expect.objectContaining({
  964. environment: [],
  965. interval: '30m',
  966. partial: '1',
  967. project: [2],
  968. query:
  969. 'transaction.op:pageload event.type:transaction transaction:/performance',
  970. referrer: 'api.performance.transaction-summary.duration-chart',
  971. statsPeriod: '14d',
  972. yAxis: [
  973. 'p50(transaction.duration)',
  974. 'p75(transaction.duration)',
  975. 'p95(transaction.duration)',
  976. 'p99(transaction.duration)',
  977. 'p100(transaction.duration)',
  978. 'avg(transaction.duration)',
  979. ],
  980. }),
  981. })
  982. );
  983. });
  984. it('uses MEP dataset for stats query', async function () {
  985. const {organization, router} = initializeData({
  986. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  987. features: ['dynamic-sampling', 'mep-rollout-flag'],
  988. });
  989. render(
  990. <TestComponent
  991. organization={organization}
  992. router={router}
  993. location={router.location}
  994. />,
  995. {
  996. router,
  997. organization,
  998. }
  999. );
  1000. await screen.findByText('Transaction Summary');
  1001. // Renders Apdex widget
  1002. await screen.findByRole('heading', {name: 'Apdex'});
  1003. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1004. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1005. 1,
  1006. expect.anything(),
  1007. expect.objectContaining({
  1008. query: expect.objectContaining({
  1009. query:
  1010. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1011. dataset: 'metricsEnhanced',
  1012. }),
  1013. })
  1014. );
  1015. // Renders Failure Rate widget
  1016. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1017. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1018. expect(
  1019. screen.queryByTestId('search-metrics-fallback-warning')
  1020. ).not.toBeInTheDocument();
  1021. });
  1022. it('does not use MEP dataset for stats query if cardinality fallback fails', async function () {
  1023. MockApiClient.addMockResponse({
  1024. method: 'GET',
  1025. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  1026. body: {
  1027. sum: {
  1028. metrics: 100,
  1029. metrics_null: 100,
  1030. metrics_unparam: 0,
  1031. },
  1032. },
  1033. });
  1034. const {organization, router} = initializeData({
  1035. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  1036. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1037. });
  1038. render(
  1039. <TestComponent
  1040. organization={organization}
  1041. router={router}
  1042. location={router.location}
  1043. />,
  1044. {
  1045. router,
  1046. organization,
  1047. }
  1048. );
  1049. await screen.findByText('Transaction Summary');
  1050. // Renders Apdex widget
  1051. await screen.findByRole('heading', {name: 'Apdex'});
  1052. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  1053. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1054. 1,
  1055. expect.anything(),
  1056. expect.objectContaining({
  1057. query: expect.objectContaining({
  1058. query:
  1059. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1060. }),
  1061. })
  1062. );
  1063. });
  1064. it('uses MEP dataset for stats query and shows fallback warning', async function () {
  1065. MockApiClient.addMockResponse({
  1066. url: '/organizations/org-slug/issues/?limit=5&project=2&query=has%3Anot-compatible%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=trends&statsPeriod=14d',
  1067. body: [],
  1068. });
  1069. MockApiClient.addMockResponse({
  1070. url: '/organizations/org-slug/events/',
  1071. body: {
  1072. meta: {
  1073. fields: {
  1074. 'count()': 'number',
  1075. 'apdex()': 'number',
  1076. 'count_miserable_user()': 'number',
  1077. 'user_misery()': 'number',
  1078. 'count_unique_user()': 'number',
  1079. 'p95()': 'number',
  1080. 'failure_rate()': 'number',
  1081. 'tpm()': 'number',
  1082. project_threshold_config: 'string',
  1083. },
  1084. isMetricsData: false, // The total response is setting the metrics fallback behaviour.
  1085. },
  1086. data: [
  1087. {
  1088. 'count()': 200,
  1089. 'apdex()': 0.5,
  1090. 'count_miserable_user()': 120,
  1091. 'user_misery()': 0.1,
  1092. 'count_unique_user()': 100,
  1093. 'p95()': 731.3132,
  1094. 'failure_rate()': 1,
  1095. 'tpm()': 100,
  1096. project_threshold_config: ['duration', 300],
  1097. },
  1098. ],
  1099. },
  1100. match: [
  1101. (_url, options) => {
  1102. const isMetricsEnhanced =
  1103. options.query?.dataset === DiscoverDatasets.METRICS_ENHANCED;
  1104. return (
  1105. options.query?.field?.includes('p95()') &&
  1106. isMetricsEnhanced &&
  1107. options.query?.query?.includes('not-compatible')
  1108. );
  1109. },
  1110. ],
  1111. });
  1112. const {organization, router} = initializeData({
  1113. query: {query: 'transaction.op:pageload has:not-compatible'}, // Adds incompatible w/ metrics tag
  1114. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1115. });
  1116. render(
  1117. <TestComponent
  1118. organization={organization}
  1119. router={router}
  1120. location={router.location}
  1121. />,
  1122. {
  1123. router,
  1124. organization,
  1125. }
  1126. );
  1127. await screen.findByText('Transaction Summary');
  1128. // Renders Apdex widget
  1129. await screen.findByRole('heading', {name: 'Apdex'});
  1130. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1131. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1132. 1,
  1133. expect.anything(),
  1134. expect.objectContaining({
  1135. query: expect.objectContaining({
  1136. query:
  1137. 'transaction.op:pageload has:not-compatible event.type:transaction transaction:/performance',
  1138. dataset: 'metricsEnhanced',
  1139. }),
  1140. })
  1141. );
  1142. // Renders Failure Rate widget
  1143. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1144. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1145. expect(screen.getByTestId('search-metrics-fallback-warning')).toBeInTheDocument();
  1146. });
  1147. });
  1148. });