index.spec.tsx 37 KB

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