index.spec.tsx 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. import {browserHistory, InjectedRouter} from 'react-router';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {makeTestQueryClient} from 'sentry-test/queryClient';
  5. import {
  6. render,
  7. renderGlobalModal,
  8. screen,
  9. userEvent,
  10. waitFor,
  11. } from 'sentry-test/reactTestingLibrary';
  12. import OrganizationStore from 'sentry/stores/organizationStore';
  13. import ProjectsStore from 'sentry/stores/projectsStore';
  14. import TeamStore from 'sentry/stores/teamStore';
  15. import {Project} from 'sentry/types';
  16. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  17. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  18. import {
  19. MEPSetting,
  20. MEPState,
  21. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  22. import {QueryClientProvider} from 'sentry/utils/queryClient';
  23. import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';
  24. import {RouteContext} from 'sentry/views/routeContext';
  25. const teams = [
  26. TestStubs.Team({id: '1', slug: 'team1', name: 'Team 1'}),
  27. TestStubs.Team({id: '2', slug: 'team2', name: 'Team 2'}),
  28. ];
  29. function initializeData({
  30. features: additionalFeatures = [],
  31. query = {},
  32. project: prj,
  33. projects,
  34. }: {
  35. features?: string[];
  36. project?: Project;
  37. projects?: Project[];
  38. query?: Record<string, any>;
  39. } = {}) {
  40. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  41. const project = prj ?? TestStubs.Project({teams});
  42. const organization = Organization({
  43. features,
  44. projects: projects ? projects : [project],
  45. });
  46. const initialData = initializeOrg({
  47. organization,
  48. router: {
  49. location: {
  50. query: {
  51. transaction: '/performance',
  52. project: project.id,
  53. transactionCursor: '1:0:0',
  54. ...query,
  55. },
  56. },
  57. },
  58. });
  59. ProjectsStore.loadInitialData(initialData.organization.projects);
  60. TeamStore.loadInitialData(teams, false, null);
  61. return initialData;
  62. }
  63. function TestComponent({
  64. router,
  65. ...props
  66. }: React.ComponentProps<typeof TransactionSummary> & {
  67. router: InjectedRouter<Record<string, string>, any>;
  68. }) {
  69. if (!props.organization) {
  70. throw new Error('Missing organization');
  71. }
  72. return (
  73. <QueryClientProvider client={makeTestQueryClient()}>
  74. <RouteContext.Provider value={{router, ...router}}>
  75. <MetricsCardinalityProvider
  76. organization={props.organization}
  77. location={props.location}
  78. >
  79. <TransactionSummary {...props} />
  80. </MetricsCardinalityProvider>
  81. </RouteContext.Provider>
  82. </QueryClientProvider>
  83. );
  84. }
  85. describe('Performance > TransactionSummary', function () {
  86. let eventStatsMock: jest.Mock;
  87. beforeEach(function () {
  88. // eslint-disable-next-line no-console
  89. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  90. MockApiClient.clearMockResponses();
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/projects/',
  93. body: [],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/tags/',
  97. body: [],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: '/organizations/org-slug/tags/user.email/values/',
  101. body: [],
  102. });
  103. eventStatsMock = MockApiClient.addMockResponse({
  104. url: '/organizations/org-slug/events-stats/',
  105. body: {data: [[123, []]]},
  106. });
  107. MockApiClient.addMockResponse({
  108. url: '/organizations/org-slug/releases/stats/',
  109. body: [],
  110. });
  111. MockApiClient.addMockResponse({
  112. url: '/organizations/org-slug/issues/?limit=5&project=2&query=is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  113. body: [],
  114. });
  115. MockApiClient.addMockResponse({
  116. url: '/organizations/org-slug/users/',
  117. body: [],
  118. });
  119. MockApiClient.addMockResponse({
  120. url: '/organizations/org-slug/recent-searches/',
  121. body: [],
  122. });
  123. MockApiClient.addMockResponse({
  124. url: '/organizations/org-slug/recent-searches/',
  125. method: 'POST',
  126. body: [],
  127. });
  128. MockApiClient.addMockResponse({
  129. url: '/organizations/org-slug/sdk-updates/',
  130. body: [],
  131. });
  132. MockApiClient.addMockResponse({
  133. url: '/prompts-activity/',
  134. body: {},
  135. });
  136. MockApiClient.addMockResponse({
  137. url: '/organizations/org-slug/events-facets-performance/',
  138. body: {},
  139. });
  140. // Events Mock totals for the sidebar and other summary data
  141. MockApiClient.addMockResponse({
  142. url: '/organizations/org-slug/events/',
  143. body: {
  144. meta: {
  145. fields: {
  146. 'count()': 'number',
  147. 'apdex()': 'number',
  148. 'count_miserable_user()': 'number',
  149. 'user_misery()': 'number',
  150. 'count_unique_user()': 'number',
  151. 'p95()': 'number',
  152. 'failure_rate()': 'number',
  153. 'tpm()': 'number',
  154. project_threshold_config: 'string',
  155. },
  156. },
  157. data: [
  158. {
  159. 'count()': 2,
  160. 'apdex()': 0.6,
  161. 'count_miserable_user()': 122,
  162. 'user_misery()': 0.114,
  163. 'count_unique_user()': 1,
  164. 'p95()': 750.123,
  165. 'failure_rate()': 1,
  166. 'tpm()': 1,
  167. project_threshold_config: ['duration', 300],
  168. },
  169. ],
  170. },
  171. match: [
  172. (_url, options) => {
  173. return options.query?.field?.includes('p95()');
  174. },
  175. ],
  176. });
  177. // [Metrics Enhanced] Events Mock totals for the sidebar and other summary data
  178. MockApiClient.addMockResponse({
  179. url: '/organizations/org-slug/events/',
  180. body: {
  181. meta: {
  182. fields: {
  183. 'count()': 'number',
  184. 'apdex()': 'number',
  185. 'count_miserable_user()': 'number',
  186. 'user_misery()': 'number',
  187. 'count_unique_user()': 'number',
  188. 'p95()': 'number',
  189. 'failure_rate()': 'number',
  190. 'tpm()': 'number',
  191. project_threshold_config: 'string',
  192. },
  193. isMetricsData: true,
  194. },
  195. data: [
  196. {
  197. 'count()': 200,
  198. 'apdex()': 0.5,
  199. 'count_miserable_user()': 120,
  200. 'user_misery()': 0.1,
  201. 'count_unique_user()': 100,
  202. 'p95()': 731.3132,
  203. 'failure_rate()': 1,
  204. 'tpm()': 100,
  205. project_threshold_config: ['duration', 300],
  206. },
  207. ],
  208. },
  209. match: [
  210. (_url, options) => {
  211. const isMetricsEnhanced =
  212. options.query?.dataset === DiscoverDatasets.METRICS_ENHANCED;
  213. return options.query?.field?.includes('p95()') && isMetricsEnhanced;
  214. },
  215. ],
  216. });
  217. // Events Mock unfiltered totals for percentage calculations
  218. MockApiClient.addMockResponse({
  219. url: '/organizations/org-slug/events/',
  220. body: {
  221. meta: {
  222. fields: {
  223. 'tpm()': 'number',
  224. },
  225. },
  226. data: [
  227. {
  228. 'tpm()': 1,
  229. },
  230. ],
  231. },
  232. match: [
  233. (_url, options) => {
  234. return (
  235. options.query?.field?.includes('tpm()') &&
  236. !options.query?.field?.includes('p95()')
  237. );
  238. },
  239. ],
  240. });
  241. // Events Mock count totals for histogram percentage calculations
  242. MockApiClient.addMockResponse({
  243. url: '/organizations/org-slug/events/',
  244. body: {
  245. meta: {
  246. fields: {
  247. 'count()': 'number',
  248. },
  249. },
  250. data: [
  251. {
  252. 'count()': 2,
  253. },
  254. ],
  255. },
  256. match: [
  257. (_url, options) => {
  258. return (
  259. options.query?.field?.includes('count()') &&
  260. !options.query?.field?.includes('p95()')
  261. );
  262. },
  263. ],
  264. });
  265. // Events Transaction list response
  266. MockApiClient.addMockResponse({
  267. url: '/organizations/org-slug/events/',
  268. headers: {
  269. Link:
  270. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  271. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  272. },
  273. body: {
  274. meta: {
  275. fields: {
  276. id: 'string',
  277. 'user.display': 'string',
  278. 'transaction.duration': 'duration',
  279. 'project.id': 'integer',
  280. timestamp: 'date',
  281. },
  282. },
  283. data: [
  284. {
  285. id: 'deadbeef',
  286. 'user.display': 'uhoh@example.com',
  287. 'transaction.duration': 400,
  288. 'project.id': 2,
  289. timestamp: '2020-05-21T15:31:18+00:00',
  290. },
  291. ],
  292. },
  293. match: [
  294. (_url, options) => {
  295. return options.query?.field?.includes('user.display');
  296. },
  297. ],
  298. });
  299. // Events Mock totals for status breakdown
  300. MockApiClient.addMockResponse({
  301. url: '/organizations/org-slug/events/',
  302. body: {
  303. meta: {
  304. fields: {
  305. 'transaction.status': 'string',
  306. 'count()': 'number',
  307. },
  308. },
  309. data: [
  310. {
  311. 'count()': 2,
  312. 'transaction.status': 'ok',
  313. },
  314. ],
  315. },
  316. match: [
  317. (_url, options) => {
  318. return options.query?.field?.includes('transaction.status');
  319. },
  320. ],
  321. });
  322. MockApiClient.addMockResponse({
  323. url: '/organizations/org-slug/events-facets/',
  324. body: [
  325. {
  326. key: 'release',
  327. topValues: [{count: 3, value: 'abcd123', name: 'abcd123'}],
  328. },
  329. {
  330. key: 'environment',
  331. topValues: [
  332. {count: 2, value: 'dev', name: 'dev'},
  333. {count: 1, value: 'prod', name: 'prod'},
  334. ],
  335. },
  336. {
  337. key: 'foo',
  338. topValues: [
  339. {count: 2, value: 'bar', name: 'bar'},
  340. {count: 1, value: 'baz', name: 'baz'},
  341. ],
  342. },
  343. {
  344. key: 'user',
  345. topValues: [
  346. {count: 2, value: 'id:100', name: '100'},
  347. {count: 1, value: 'id:101', name: '101'},
  348. ],
  349. },
  350. ],
  351. });
  352. MockApiClient.addMockResponse({
  353. url: '/organizations/org-slug/project-transaction-threshold-override/',
  354. method: 'GET',
  355. body: {
  356. threshold: '800',
  357. metric: 'lcp',
  358. },
  359. });
  360. MockApiClient.addMockResponse({
  361. url: '/organizations/org-slug/events-vitals/',
  362. body: {
  363. 'measurements.fcp': {
  364. poor: 3,
  365. meh: 100,
  366. good: 47,
  367. total: 150,
  368. p75: 1500,
  369. },
  370. 'measurements.lcp': {
  371. poor: 2,
  372. meh: 38,
  373. good: 40,
  374. total: 80,
  375. p75: 2750,
  376. },
  377. 'measurements.fid': {
  378. poor: 2,
  379. meh: 53,
  380. good: 5,
  381. total: 60,
  382. p75: 1000,
  383. },
  384. 'measurements.cls': {
  385. poor: 3,
  386. meh: 10,
  387. good: 4,
  388. total: 17,
  389. p75: 0.2,
  390. },
  391. },
  392. });
  393. MockApiClient.addMockResponse({
  394. method: 'GET',
  395. url: `/organizations/org-slug/key-transactions-list/`,
  396. body: teams.map(({id}) => ({
  397. team: id,
  398. count: 0,
  399. keyed: [],
  400. })),
  401. });
  402. MockApiClient.addMockResponse({
  403. url: '/organizations/org-slug/events-has-measurements/',
  404. body: {measurements: false},
  405. });
  406. MockApiClient.addMockResponse({
  407. url: '/organizations/org-slug/events-spans-performance/',
  408. body: [
  409. {
  410. op: 'ui.long-task',
  411. group: 'c777169faad84eb4',
  412. description: 'Main UI thread blocked',
  413. frequency: 713,
  414. count: 9040,
  415. avgOccurrences: null,
  416. sumExclusiveTime: 1743893.9822921753,
  417. p50ExclusiveTime: null,
  418. p75ExclusiveTime: 244.9998779296875,
  419. p95ExclusiveTime: null,
  420. p99ExclusiveTime: null,
  421. },
  422. ],
  423. });
  424. MockApiClient.addMockResponse({
  425. url: `/projects/org-slug/project-slug/profiling/functions/`,
  426. body: {functions: []},
  427. });
  428. MockApiClient.addMockResponse({
  429. method: 'GET',
  430. url: `/organizations/org-slug/metrics-compatibility/`,
  431. body: {
  432. compatible_projects: [],
  433. incompatible_projecs: [],
  434. },
  435. });
  436. MockApiClient.addMockResponse({
  437. method: 'GET',
  438. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  439. body: {
  440. sum: {
  441. metrics: 100,
  442. metrics_null: 0,
  443. metrics_unparam: 0,
  444. },
  445. },
  446. });
  447. jest.spyOn(MEPSetting, 'get').mockImplementation(() => MEPState.AUTO);
  448. });
  449. afterEach(function () {
  450. MockApiClient.clearMockResponses();
  451. ProjectsStore.reset();
  452. jest.clearAllMocks();
  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(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.getByRole('option', {name: '#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: [
  982. 'p50(transaction.duration)',
  983. 'p75(transaction.duration)',
  984. 'p95(transaction.duration)',
  985. 'p99(transaction.duration)',
  986. 'p100(transaction.duration)',
  987. 'avg(transaction.duration)',
  988. ],
  989. }),
  990. })
  991. );
  992. });
  993. it('uses MEP dataset for stats query', async function () {
  994. const {organization, router, routerContext} = initializeData({
  995. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  996. features: ['dynamic-sampling', 'mep-rollout-flag'],
  997. });
  998. render(
  999. <TestComponent
  1000. organization={organization}
  1001. router={router}
  1002. location={router.location}
  1003. />,
  1004. {
  1005. context: routerContext,
  1006. organization,
  1007. }
  1008. );
  1009. await screen.findByText('Transaction Summary');
  1010. // Renders Apdex widget
  1011. await screen.findByRole('heading', {name: 'Apdex'});
  1012. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1013. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1014. 1,
  1015. expect.anything(),
  1016. expect.objectContaining({
  1017. query: expect.objectContaining({
  1018. query:
  1019. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1020. dataset: 'metricsEnhanced',
  1021. }),
  1022. })
  1023. );
  1024. // Renders Failure Rate widget
  1025. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1026. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1027. // Renders TPM widget
  1028. expect(
  1029. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1030. ).toBeInTheDocument();
  1031. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1032. '100%'
  1033. );
  1034. expect(
  1035. screen.queryByTestId('search-metrics-fallback-warning')
  1036. ).not.toBeInTheDocument();
  1037. });
  1038. it('does not use MEP dataset for stats query if cardinality fallback fails', async function () {
  1039. MockApiClient.addMockResponse({
  1040. method: 'GET',
  1041. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  1042. body: {
  1043. sum: {
  1044. metrics: 100,
  1045. metrics_null: 100,
  1046. metrics_unparam: 0,
  1047. },
  1048. },
  1049. });
  1050. const {organization, router, routerContext} = initializeData({
  1051. query: {query: 'transaction.op:pageload'}, // transaction.op is covered by the metrics dataset
  1052. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1053. });
  1054. render(
  1055. <TestComponent
  1056. organization={organization}
  1057. router={router}
  1058. location={router.location}
  1059. />,
  1060. {
  1061. context: routerContext,
  1062. organization,
  1063. }
  1064. );
  1065. await screen.findByText('Transaction Summary');
  1066. // Renders Apdex widget
  1067. await screen.findByRole('heading', {name: 'Apdex'});
  1068. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  1069. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1070. 1,
  1071. expect.anything(),
  1072. expect.objectContaining({
  1073. query: expect.objectContaining({
  1074. query:
  1075. 'transaction.op:pageload event.type:transaction transaction:/performance',
  1076. }),
  1077. })
  1078. );
  1079. // Renders TPM widget
  1080. expect(
  1081. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1082. ).toBeInTheDocument();
  1083. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1084. '100%'
  1085. );
  1086. });
  1087. it('uses MEP dataset for stats query and shows fallback warning', async function () {
  1088. MockApiClient.addMockResponse({
  1089. url: '/organizations/org-slug/issues/?limit=5&project=2&query=has%3Anot-compatible%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  1090. body: [],
  1091. });
  1092. MockApiClient.addMockResponse({
  1093. url: '/organizations/org-slug/events/',
  1094. body: {
  1095. meta: {
  1096. fields: {
  1097. 'count()': 'number',
  1098. 'apdex()': 'number',
  1099. 'count_miserable_user()': 'number',
  1100. 'user_misery()': 'number',
  1101. 'count_unique_user()': 'number',
  1102. 'p95()': 'number',
  1103. 'failure_rate()': 'number',
  1104. 'tpm()': 'number',
  1105. project_threshold_config: 'string',
  1106. },
  1107. isMetricsData: false, // The total response is setting the metrics fallback behaviour.
  1108. },
  1109. data: [
  1110. {
  1111. 'count()': 200,
  1112. 'apdex()': 0.5,
  1113. 'count_miserable_user()': 120,
  1114. 'user_misery()': 0.1,
  1115. 'count_unique_user()': 100,
  1116. 'p95()': 731.3132,
  1117. 'failure_rate()': 1,
  1118. 'tpm()': 100,
  1119. project_threshold_config: ['duration', 300],
  1120. },
  1121. ],
  1122. },
  1123. match: [
  1124. (_url, options) => {
  1125. const isMetricsEnhanced =
  1126. options.query?.dataset === DiscoverDatasets.METRICS_ENHANCED;
  1127. return (
  1128. options.query?.field?.includes('p95()') &&
  1129. isMetricsEnhanced &&
  1130. options.query?.query?.includes('not-compatible')
  1131. );
  1132. },
  1133. ],
  1134. });
  1135. const {organization, router, routerContext} = initializeData({
  1136. query: {query: 'transaction.op:pageload has:not-compatible'}, // Adds incompatible w/ metrics tag
  1137. features: ['dynamic-sampling', 'mep-rollout-flag'],
  1138. });
  1139. render(
  1140. <TestComponent
  1141. organization={organization}
  1142. router={router}
  1143. location={router.location}
  1144. />,
  1145. {
  1146. context: routerContext,
  1147. organization,
  1148. }
  1149. );
  1150. await screen.findByText('Transaction Summary');
  1151. // Renders Apdex widget
  1152. await screen.findByRole('heading', {name: 'Apdex'});
  1153. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.5');
  1154. expect(eventStatsMock).toHaveBeenNthCalledWith(
  1155. 1,
  1156. expect.anything(),
  1157. expect.objectContaining({
  1158. query: expect.objectContaining({
  1159. query:
  1160. 'transaction.op:pageload has:not-compatible event.type:transaction transaction:/performance',
  1161. dataset: 'metricsEnhanced',
  1162. }),
  1163. })
  1164. );
  1165. // Renders Failure Rate widget
  1166. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  1167. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  1168. // Renders TPM widget
  1169. expect(
  1170. screen.getByRole('heading', {name: 'Percentage of Total Transactions'})
  1171. ).toBeInTheDocument();
  1172. expect(screen.getByTestId('count-percentage-summary-value')).toHaveTextContent(
  1173. '100%'
  1174. );
  1175. expect(screen.getByTestId('search-metrics-fallback-warning')).toBeInTheDocument();
  1176. });
  1177. });
  1178. });