index.spec.tsx 38 KB

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