index.spec.tsx 36 KB

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