index.spec.tsx 36 KB

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