index.spec.tsx 37 KB

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