index.spec.tsx 36 KB

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