widgetContainer.spec.tsx 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. import type {InitializeDataSettings} from 'sentry-test/performance/initializePerformanceData';
  2. import {initializeData as _initializeData} from 'sentry-test/performance/initializePerformanceData';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  5. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  6. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  7. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  8. import {OrganizationContext} from 'sentry/views/organizationContext';
  9. import WidgetContainer from 'sentry/views/performance/landing/widgets/components/widgetContainer';
  10. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  11. import {ProjectPerformanceType} from 'sentry/views/performance/utils';
  12. import {QUERY_LIMIT_PARAM} from '../utils';
  13. const initializeData = (query = {}, rest: InitializeDataSettings = {}) => {
  14. const data = _initializeData({
  15. query: {statsPeriod: '7d', environment: ['prod'], project: [-42], ...query},
  16. ...rest,
  17. });
  18. data.eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  19. return data;
  20. };
  21. function WrappedComponent({data, withStaticFilters = false, ...rest}) {
  22. return (
  23. <OrganizationContext.Provider value={data.organization}>
  24. <MetricsCardinalityProvider
  25. location={data.router.location}
  26. organization={data.organization}
  27. >
  28. <MEPSettingProvider forceTransactions>
  29. <PerformanceDisplayProvider
  30. value={{performanceType: ProjectPerformanceType.ANY}}
  31. >
  32. <WidgetContainer
  33. chartHeight={100}
  34. allowedCharts={[
  35. PerformanceWidgetSetting.TPM_AREA,
  36. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  37. PerformanceWidgetSetting.USER_MISERY_AREA,
  38. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  39. ]}
  40. rowChartSettings={[]}
  41. withStaticFilters={withStaticFilters}
  42. forceDefaultChartSetting
  43. {...data}
  44. {...rest}
  45. />
  46. </PerformanceDisplayProvider>
  47. </MEPSettingProvider>
  48. </MetricsCardinalityProvider>
  49. </OrganizationContext.Provider>
  50. );
  51. }
  52. const issuesPredicate = (url, options) =>
  53. url.includes('events') && options.query?.query.includes('error');
  54. describe('Performance > Widgets > WidgetContainer', function () {
  55. let wrapper;
  56. let eventStatsMock;
  57. let eventsTrendsStats;
  58. let eventsMock;
  59. let issuesListMock;
  60. beforeEach(function () {
  61. eventStatsMock = MockApiClient.addMockResponse({
  62. method: 'GET',
  63. url: `/organizations/org-slug/events-stats/`,
  64. body: [],
  65. });
  66. eventsMock = MockApiClient.addMockResponse({
  67. method: 'GET',
  68. url: `/organizations/org-slug/events/`,
  69. body: {
  70. data: [{}],
  71. meta: {},
  72. },
  73. match: [(...args) => !issuesPredicate(...args)],
  74. });
  75. issuesListMock = MockApiClient.addMockResponse({
  76. method: 'GET',
  77. url: `/organizations/org-slug/events/`,
  78. body: {
  79. data: [
  80. {
  81. 'issue.id': 123,
  82. transaction: '/issue/:id/',
  83. title: 'Error: Something is broken.',
  84. 'project.id': 1,
  85. count: 3100,
  86. issue: 'JAVASCRIPT-ABCD',
  87. },
  88. ],
  89. },
  90. match: [(...args) => issuesPredicate(...args)],
  91. });
  92. eventsTrendsStats = MockApiClient.addMockResponse({
  93. method: 'GET',
  94. url: '/organizations/org-slug/events-trends-stats/',
  95. body: [],
  96. });
  97. MockApiClient.addMockResponse({
  98. method: 'GET',
  99. url: `/organizations/org-slug/metrics-compatibility/`,
  100. body: [],
  101. });
  102. MockApiClient.addMockResponse({
  103. method: 'GET',
  104. url: `/organizations/org-slug/metrics-compatibility-sums/`,
  105. body: [],
  106. });
  107. });
  108. afterEach(function () {
  109. if (wrapper) {
  110. wrapper.unmount();
  111. wrapper = undefined;
  112. }
  113. });
  114. it('Check requests when changing widget props', async function () {
  115. const data = initializeData();
  116. wrapper = render(
  117. <WrappedComponent
  118. data={data}
  119. defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
  120. />
  121. );
  122. await waitFor(() => {
  123. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  124. });
  125. // Change eventView reference
  126. data.eventView = data.eventView.clone();
  127. wrapper.rerender(
  128. <WrappedComponent
  129. data={data}
  130. defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
  131. />
  132. );
  133. await waitFor(() => {
  134. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  135. });
  136. // Change eventView statsperiod
  137. const modifiedData = initializeData({
  138. statsPeriod: '14d',
  139. });
  140. wrapper.rerender(
  141. <WrappedComponent
  142. data={modifiedData}
  143. defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
  144. />
  145. );
  146. await waitFor(() => {
  147. expect(eventStatsMock).toHaveBeenCalledTimes(2);
  148. });
  149. expect(eventStatsMock).toHaveBeenNthCalledWith(
  150. 2,
  151. expect.anything(),
  152. expect.objectContaining({
  153. query: expect.objectContaining({
  154. interval: '1h',
  155. partial: '1',
  156. query: 'transaction.op:pageload',
  157. statsPeriod: '28d',
  158. yAxis: 'tpm()',
  159. }),
  160. })
  161. );
  162. });
  163. it('Check requests when changing widget props for GenericDiscoverQuery based widget', async function () {
  164. const data = initializeData();
  165. wrapper = render(
  166. <MEPSettingProvider forceTransactions>
  167. <WrappedComponent
  168. data={data}
  169. defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
  170. />
  171. </MEPSettingProvider>
  172. );
  173. await waitFor(() => {
  174. expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
  175. });
  176. // Change eventView reference
  177. data.eventView = data.eventView.clone();
  178. wrapper.rerender(
  179. <MEPSettingProvider forceTransactions>
  180. <WrappedComponent
  181. data={data}
  182. defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
  183. />
  184. </MEPSettingProvider>
  185. );
  186. await waitFor(() => {
  187. expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
  188. });
  189. // Change eventView statsperiod
  190. const modifiedData = initializeData({
  191. statsPeriod: '14d',
  192. });
  193. wrapper.rerender(
  194. <MEPSettingProvider forceTransactions>
  195. <WrappedComponent
  196. data={modifiedData}
  197. defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
  198. />
  199. </MEPSettingProvider>
  200. );
  201. await waitFor(() => {
  202. expect(eventsTrendsStats).toHaveBeenCalledTimes(2);
  203. });
  204. expect(eventsTrendsStats).toHaveBeenNthCalledWith(
  205. 2,
  206. expect.anything(),
  207. expect.objectContaining({
  208. query: expect.objectContaining({
  209. cursor: '0:0:1',
  210. environment: ['prod'],
  211. field: ['transaction', 'project'],
  212. interval: undefined,
  213. middle: undefined,
  214. noPagination: true,
  215. per_page: QUERY_LIMIT_PARAM,
  216. project: ['-42'],
  217. query:
  218. 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
  219. sort: 'trend_percentage()',
  220. statsPeriod: '14d',
  221. trendFunction: 'p95(transaction.duration)',
  222. trendType: 'improved',
  223. }),
  224. })
  225. );
  226. });
  227. it('should call PageError Provider when errors are present', async function () {
  228. const data = initializeData();
  229. eventStatsMock = MockApiClient.addMockResponse({
  230. method: 'GET',
  231. url: `/organizations/org-slug/events-stats/`,
  232. statusCode: 400,
  233. body: {
  234. detail: 'Request did not work :(',
  235. },
  236. });
  237. wrapper = render(
  238. <PageAlertProvider>
  239. <PageAlert />
  240. <WrappedComponent
  241. data={data}
  242. defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
  243. />
  244. </PageAlertProvider>
  245. );
  246. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  247. 'Transactions Per Minute'
  248. );
  249. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  250. expect(await screen.findByTestId('page-error-alert')).toHaveTextContent(
  251. 'Request did not work :('
  252. );
  253. });
  254. it('TPM Widget', async function () {
  255. const data = initializeData();
  256. wrapper = render(
  257. <WrappedComponent
  258. data={data}
  259. defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
  260. />
  261. );
  262. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  263. 'Transactions Per Minute'
  264. );
  265. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  266. expect(eventStatsMock).toHaveBeenNthCalledWith(
  267. 1,
  268. expect.anything(),
  269. expect.objectContaining({
  270. query: expect.objectContaining({
  271. interval: '1h',
  272. partial: '1',
  273. query: 'transaction.op:pageload',
  274. statsPeriod: '14d',
  275. yAxis: 'tpm()',
  276. }),
  277. })
  278. );
  279. });
  280. it('Failure Rate Widget', async function () {
  281. const data = initializeData();
  282. wrapper = render(
  283. <WrappedComponent
  284. data={data}
  285. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  286. />
  287. );
  288. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  289. 'Failure Rate'
  290. );
  291. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  292. expect(eventStatsMock).toHaveBeenNthCalledWith(
  293. 1,
  294. expect.anything(),
  295. expect.objectContaining({
  296. query: expect.objectContaining({
  297. interval: '1h',
  298. partial: '1',
  299. query: 'transaction.op:pageload',
  300. statsPeriod: '14d',
  301. yAxis: 'failure_rate()',
  302. }),
  303. })
  304. );
  305. });
  306. it('Widget with MEP enabled and metric meta set to true', async function () {
  307. const data = initializeData(
  308. {},
  309. {
  310. features: ['performance-use-metrics'],
  311. }
  312. );
  313. eventStatsMock = MockApiClient.addMockResponse({
  314. method: 'GET',
  315. url: `/organizations/org-slug/events-stats/`,
  316. body: {
  317. data: [],
  318. isMetricsData: true,
  319. },
  320. });
  321. eventsMock = MockApiClient.addMockResponse({
  322. method: 'GET',
  323. url: `/organizations/org-slug/events/`,
  324. body: {
  325. data: [{}],
  326. meta: {isMetricsData: true},
  327. },
  328. });
  329. wrapper = render(
  330. <WrappedComponent
  331. data={data}
  332. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  333. />
  334. );
  335. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  336. expect(eventStatsMock).toHaveBeenNthCalledWith(
  337. 1,
  338. expect.anything(),
  339. expect.objectContaining({
  340. query: expect.objectContaining({dataset: 'metrics'}),
  341. })
  342. );
  343. expect(eventsMock).toHaveBeenCalledTimes(1);
  344. expect(eventsMock).toHaveBeenCalledWith(
  345. expect.anything(),
  346. expect.objectContaining({
  347. query: expect.objectContaining({dataset: 'metrics'}),
  348. })
  349. );
  350. expect(await screen.findByTestId('has-metrics-data-tag')).toHaveTextContent(
  351. 'processed'
  352. );
  353. });
  354. it('Widget with MEP enabled and metric meta set to undefined', async function () {
  355. const data = initializeData(
  356. {},
  357. {
  358. features: ['performance-use-metrics'],
  359. }
  360. );
  361. eventStatsMock = MockApiClient.addMockResponse({
  362. method: 'GET',
  363. url: `/organizations/org-slug/events-stats/`,
  364. body: {
  365. data: [],
  366. isMetricsData: undefined,
  367. },
  368. });
  369. wrapper = render(
  370. <WrappedComponent
  371. data={data}
  372. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  373. />
  374. );
  375. expect(await screen.findByTestId('no-metrics-data-tag')).toBeInTheDocument();
  376. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  377. expect(eventStatsMock).toHaveBeenNthCalledWith(
  378. 1,
  379. expect.anything(),
  380. expect.objectContaining({
  381. query: expect.objectContaining({dataset: 'metrics'}),
  382. })
  383. );
  384. });
  385. it('Widget with MEP enabled and metric meta set to false', async function () {
  386. const data = initializeData(
  387. {},
  388. {
  389. features: ['performance-use-metrics'],
  390. }
  391. );
  392. eventStatsMock = MockApiClient.addMockResponse({
  393. method: 'GET',
  394. url: `/organizations/org-slug/events-stats/`,
  395. body: {
  396. data: [],
  397. isMetricsData: false,
  398. },
  399. });
  400. eventsMock = MockApiClient.addMockResponse({
  401. method: 'GET',
  402. url: `/organizations/org-slug/events/`,
  403. body: {
  404. data: [{}],
  405. meta: {isMetricsData: false},
  406. },
  407. });
  408. wrapper = render(
  409. <WrappedComponent
  410. data={data}
  411. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  412. />
  413. );
  414. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  415. expect(eventStatsMock).toHaveBeenNthCalledWith(
  416. 1,
  417. expect.anything(),
  418. expect.objectContaining({
  419. query: expect.objectContaining({dataset: 'metrics'}),
  420. })
  421. );
  422. expect(eventsMock).toHaveBeenCalledTimes(1);
  423. expect(eventsMock).toHaveBeenCalledWith(
  424. expect.anything(),
  425. expect.objectContaining({
  426. query: expect.objectContaining({dataset: 'metrics'}),
  427. })
  428. );
  429. expect(await screen.findByTestId('has-metrics-data-tag')).toHaveTextContent(
  430. 'indexed'
  431. );
  432. });
  433. it('User misery Widget', async function () {
  434. const data = initializeData();
  435. wrapper = render(
  436. <WrappedComponent
  437. data={data}
  438. defaultChartSetting={PerformanceWidgetSetting.USER_MISERY_AREA}
  439. />
  440. );
  441. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  442. 'User Misery'
  443. );
  444. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  445. expect(eventStatsMock).toHaveBeenNthCalledWith(
  446. 1,
  447. expect.anything(),
  448. expect.objectContaining({
  449. query: expect.objectContaining({
  450. interval: '1h',
  451. partial: '1',
  452. query: 'transaction.op:pageload',
  453. statsPeriod: '14d',
  454. yAxis: 'user_misery()',
  455. }),
  456. })
  457. );
  458. });
  459. it('Worst LCP widget', async function () {
  460. const data = initializeData();
  461. wrapper = render(
  462. <WrappedComponent
  463. data={data}
  464. defaultChartSetting={PerformanceWidgetSetting.WORST_LCP_VITALS}
  465. />
  466. );
  467. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  468. 'Worst LCP Web Vitals'
  469. );
  470. expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
  471. expect(eventsMock).toHaveBeenCalledTimes(1);
  472. expect(eventsMock).toHaveBeenNthCalledWith(
  473. 1,
  474. expect.anything(),
  475. expect.objectContaining({
  476. query: expect.objectContaining({
  477. environment: ['prod'],
  478. field: [
  479. 'transaction',
  480. 'title',
  481. 'project.id',
  482. 'count_web_vitals(measurements.lcp, poor)',
  483. 'count_web_vitals(measurements.lcp, meh)',
  484. 'count_web_vitals(measurements.lcp, good)',
  485. ],
  486. per_page: 4,
  487. project: ['-42'],
  488. query: 'transaction.op:pageload',
  489. sort: '-count_web_vitals(measurements.lcp, poor)',
  490. statsPeriod: '7d',
  491. }),
  492. })
  493. );
  494. });
  495. it('Worst LCP widget - MEP', async function () {
  496. const data = initializeData(
  497. {},
  498. {
  499. features: ['performance-use-metrics'],
  500. }
  501. );
  502. wrapper = render(
  503. <WrappedComponent
  504. data={data}
  505. defaultChartSetting={PerformanceWidgetSetting.WORST_LCP_VITALS}
  506. />
  507. );
  508. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  509. 'Worst LCP Web Vitals'
  510. );
  511. expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
  512. expect(eventsMock).toHaveBeenCalledTimes(1);
  513. expect(eventsMock).toHaveBeenNthCalledWith(
  514. 1,
  515. expect.anything(),
  516. expect.objectContaining({
  517. query: expect.objectContaining({
  518. environment: ['prod'],
  519. field: [
  520. 'transaction',
  521. 'title',
  522. 'project.id',
  523. 'count_web_vitals(measurements.lcp, poor)',
  524. 'count_web_vitals(measurements.lcp, meh)',
  525. 'count_web_vitals(measurements.lcp, good)',
  526. ],
  527. per_page: 4,
  528. project: ['-42'],
  529. query: 'transaction.op:pageload !transaction:"<< unparameterized >>"',
  530. sort: '-count_web_vitals(measurements.lcp, poor)',
  531. statsPeriod: '7d',
  532. }),
  533. })
  534. );
  535. });
  536. it('Worst FCP widget', async function () {
  537. const data = initializeData();
  538. wrapper = render(
  539. <WrappedComponent
  540. data={data}
  541. defaultChartSetting={PerformanceWidgetSetting.WORST_FCP_VITALS}
  542. />
  543. );
  544. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  545. 'Worst FCP Web Vitals'
  546. );
  547. expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
  548. expect(eventsMock).toHaveBeenCalledTimes(1);
  549. expect(eventsMock).toHaveBeenNthCalledWith(
  550. 1,
  551. expect.anything(),
  552. expect.objectContaining({
  553. query: expect.objectContaining({
  554. environment: ['prod'],
  555. field: [
  556. 'transaction',
  557. 'title',
  558. 'project.id',
  559. 'count_web_vitals(measurements.fcp, poor)',
  560. 'count_web_vitals(measurements.fcp, meh)',
  561. 'count_web_vitals(measurements.fcp, good)',
  562. ],
  563. per_page: 4,
  564. project: ['-42'],
  565. query: 'transaction.op:pageload',
  566. sort: '-count_web_vitals(measurements.fcp, poor)',
  567. statsPeriod: '7d',
  568. }),
  569. })
  570. );
  571. });
  572. it('Worst FID widget', async function () {
  573. const data = initializeData();
  574. wrapper = render(
  575. <WrappedComponent
  576. data={data}
  577. defaultChartSetting={PerformanceWidgetSetting.WORST_FID_VITALS}
  578. />
  579. );
  580. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  581. 'Worst FID Web Vitals'
  582. );
  583. expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
  584. expect(eventsMock).toHaveBeenCalledTimes(1);
  585. expect(eventsMock).toHaveBeenNthCalledWith(
  586. 1,
  587. expect.anything(),
  588. expect.objectContaining({
  589. query: expect.objectContaining({
  590. environment: ['prod'],
  591. field: [
  592. 'transaction',
  593. 'title',
  594. 'project.id',
  595. 'count_web_vitals(measurements.fid, poor)',
  596. 'count_web_vitals(measurements.fid, meh)',
  597. 'count_web_vitals(measurements.fid, good)',
  598. ],
  599. per_page: 4,
  600. project: ['-42'],
  601. query: 'transaction.op:pageload',
  602. sort: '-count_web_vitals(measurements.fid, poor)',
  603. statsPeriod: '7d',
  604. }),
  605. })
  606. );
  607. });
  608. it('LCP Histogram Widget', async function () {
  609. const data = initializeData();
  610. wrapper = render(
  611. <WrappedComponent
  612. data={data}
  613. defaultChartSetting={PerformanceWidgetSetting.LCP_HISTOGRAM}
  614. />
  615. );
  616. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  617. 'LCP Distribution'
  618. );
  619. // TODO(k-fish): Add histogram mock
  620. });
  621. it('FCP Histogram Widget', async function () {
  622. const data = initializeData();
  623. wrapper = render(
  624. <WrappedComponent
  625. data={data}
  626. defaultChartSetting={PerformanceWidgetSetting.FCP_HISTOGRAM}
  627. />
  628. );
  629. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  630. 'FCP Distribution'
  631. );
  632. // TODO(k-fish): Add histogram mock
  633. });
  634. it('Most errors widget', async function () {
  635. const data = initializeData();
  636. wrapper = render(
  637. <WrappedComponent
  638. data={data}
  639. defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ERRORS}
  640. />
  641. );
  642. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  643. 'Most Related Errors'
  644. );
  645. expect(eventsMock).toHaveBeenCalledTimes(1);
  646. expect(eventsMock).toHaveBeenNthCalledWith(
  647. 1,
  648. expect.anything(),
  649. expect.objectContaining({
  650. query: expect.objectContaining({
  651. environment: ['prod'],
  652. field: ['transaction', 'project.id', 'failure_count()'],
  653. per_page: QUERY_LIMIT_PARAM,
  654. project: ['-42'],
  655. query: 'transaction.op:pageload failure_count():>0',
  656. sort: '-failure_count()',
  657. statsPeriod: '7d',
  658. }),
  659. })
  660. );
  661. });
  662. it('Most related issues widget', async function () {
  663. const data = initializeData();
  664. wrapper = render(
  665. <WrappedComponent
  666. data={data}
  667. defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ISSUES}
  668. />
  669. );
  670. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  671. 'Most Related Issues'
  672. );
  673. expect(issuesListMock).toHaveBeenCalledTimes(1);
  674. expect(issuesListMock).toHaveBeenNthCalledWith(
  675. 1,
  676. expect.anything(),
  677. expect.objectContaining({
  678. query: expect.objectContaining({
  679. environment: ['prod'],
  680. field: ['issue', 'transaction', 'title', 'project.id', 'count()'],
  681. per_page: QUERY_LIMIT_PARAM,
  682. project: ['-42'],
  683. query: 'event.type:error !tags[transaction]:"" count():>0',
  684. sort: '-count()',
  685. statsPeriod: '7d',
  686. }),
  687. })
  688. );
  689. });
  690. it('Switching from issues to errors widget', async function () {
  691. const data = initializeData();
  692. wrapper = render(
  693. <WrappedComponent
  694. data={data}
  695. defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ISSUES}
  696. />
  697. );
  698. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  699. 'Most Related Issues'
  700. );
  701. expect(issuesListMock).toHaveBeenCalledTimes(1);
  702. wrapper.rerender(
  703. <WrappedComponent
  704. data={data}
  705. defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ERRORS}
  706. />
  707. );
  708. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  709. 'Most Related Errors'
  710. );
  711. expect(eventsMock).toHaveBeenCalledTimes(1);
  712. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  713. });
  714. it('Most improved trends widget', async function () {
  715. const data = initializeData();
  716. wrapper = render(
  717. <MEPSettingProvider forceTransactions>
  718. <WrappedComponent
  719. data={data}
  720. defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
  721. />
  722. </MEPSettingProvider>
  723. );
  724. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  725. 'Most Improved'
  726. );
  727. expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
  728. expect(eventsTrendsStats).toHaveBeenNthCalledWith(
  729. 1,
  730. expect.anything(),
  731. expect.objectContaining({
  732. query: expect.objectContaining({
  733. environment: ['prod'],
  734. field: ['transaction', 'project'],
  735. interval: undefined,
  736. middle: undefined,
  737. per_page: QUERY_LIMIT_PARAM,
  738. project: ['-42'],
  739. query:
  740. 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
  741. sort: 'trend_percentage()',
  742. statsPeriod: '7d',
  743. trendFunction: 'p95(transaction.duration)',
  744. trendType: 'improved',
  745. }),
  746. })
  747. );
  748. });
  749. it('Most time spent in db queries widget', async function () {
  750. const data = initializeData();
  751. wrapper = render(
  752. <MEPSettingProvider forceTransactions>
  753. <WrappedComponent
  754. data={data}
  755. defaultChartSetting={PerformanceWidgetSetting.MOST_TIME_SPENT_DB_QUERIES}
  756. />
  757. </MEPSettingProvider>
  758. );
  759. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  760. 'Most Time-Consuming Queries'
  761. );
  762. expect(eventsMock).toHaveBeenCalledTimes(1);
  763. expect(eventsMock).toHaveBeenNthCalledWith(
  764. 1,
  765. expect.anything(),
  766. expect.objectContaining({
  767. query: expect.objectContaining({
  768. dataset: 'spansMetrics',
  769. environment: ['prod'],
  770. field: [
  771. 'span.op',
  772. 'span.group',
  773. 'project.id',
  774. 'span.description',
  775. 'sum(span.self_time)',
  776. 'avg(span.self_time)',
  777. 'time_spent_percentage()',
  778. ],
  779. per_page: QUERY_LIMIT_PARAM,
  780. project: ['-42'],
  781. query: 'has:span.description span.module:db transaction.op:pageload',
  782. sort: '-time_spent_percentage()',
  783. statsPeriod: '7d',
  784. }),
  785. })
  786. );
  787. });
  788. it('Most time consuming resources widget', async function () {
  789. const data = initializeData();
  790. wrapper = render(
  791. <MEPSettingProvider forceTransactions>
  792. <WrappedComponent
  793. data={data}
  794. defaultChartSetting={PerformanceWidgetSetting.MOST_TIME_CONSUMING_RESOURCES}
  795. />
  796. </MEPSettingProvider>
  797. );
  798. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  799. 'Most Time Consuming Resources'
  800. );
  801. expect(eventsMock).toHaveBeenCalledTimes(1);
  802. expect(eventsMock).toHaveBeenNthCalledWith(
  803. 1,
  804. expect.anything(),
  805. expect.objectContaining({
  806. query: expect.objectContaining({
  807. dataset: 'spansMetrics',
  808. environment: ['prod'],
  809. field: [
  810. 'span.description',
  811. 'span.op',
  812. 'project.id',
  813. 'span.group',
  814. 'sum(span.self_time)',
  815. 'avg(span.self_time)',
  816. 'time_spent_percentage()',
  817. ],
  818. per_page: QUERY_LIMIT_PARAM,
  819. project: ['-42'],
  820. query:
  821. '!span.description:browser-extension://* resource.render_blocking_status:blocking ( span.op:resource.script OR file_extension:css OR file_extension:[woff,woff2,ttf,otf,eot] OR file_extension:[jpg,jpeg,png,gif,svg,webp,apng,avif] OR span.op:resource.img ) transaction.op:pageload',
  822. sort: '-time_spent_percentage()',
  823. statsPeriod: '7d',
  824. }),
  825. })
  826. );
  827. });
  828. it('Best Page Opportunities widget', async function () {
  829. const data = initializeData();
  830. wrapper = render(
  831. <MEPSettingProvider forceTransactions>
  832. <WrappedComponent
  833. data={data}
  834. defaultChartSetting={PerformanceWidgetSetting.HIGHEST_OPPORTUNITY_PAGES}
  835. />
  836. </MEPSettingProvider>
  837. );
  838. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  839. 'Best Page Opportunities'
  840. );
  841. expect(eventsMock).toHaveBeenCalledTimes(2);
  842. expect(eventsMock).toHaveBeenNthCalledWith(
  843. 2,
  844. expect.anything(),
  845. expect.objectContaining({
  846. query: expect.objectContaining({
  847. dataset: 'metrics',
  848. field: [
  849. 'transaction',
  850. 'p75(measurements.lcp)',
  851. 'p75(measurements.fcp)',
  852. 'p75(measurements.cls)',
  853. 'p75(measurements.ttfb)',
  854. 'p75(measurements.fid)',
  855. 'p75(measurements.inp)',
  856. 'opportunity_score(measurements.score.total)',
  857. 'avg(measurements.score.total)',
  858. 'count()',
  859. 'count_scores(measurements.score.lcp)',
  860. 'count_scores(measurements.score.fcp)',
  861. 'count_scores(measurements.score.cls)',
  862. 'count_scores(measurements.score.fid)',
  863. 'count_scores(measurements.score.inp)',
  864. 'count_scores(measurements.score.ttfb)',
  865. ],
  866. query:
  867. 'transaction.op:[pageload,""] span.op:[ui.interaction.click,""] avg(measurements.score.total):>=0',
  868. }),
  869. })
  870. );
  871. });
  872. it('Most regressed trends widget', async function () {
  873. const data = initializeData();
  874. wrapper = render(
  875. <WrappedComponent
  876. data={data}
  877. defaultChartSetting={PerformanceWidgetSetting.MOST_REGRESSED}
  878. />
  879. );
  880. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  881. 'Most Regressed'
  882. );
  883. expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
  884. expect(eventsTrendsStats).toHaveBeenNthCalledWith(
  885. 1,
  886. expect.anything(),
  887. expect.objectContaining({
  888. query: expect.objectContaining({
  889. environment: ['prod'],
  890. field: ['transaction', 'project'],
  891. interval: undefined,
  892. middle: undefined,
  893. per_page: QUERY_LIMIT_PARAM,
  894. project: ['-42'],
  895. query:
  896. 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
  897. sort: '-trend_percentage()',
  898. statsPeriod: '7d',
  899. trendFunction: 'p95(transaction.duration)',
  900. trendType: 'regression',
  901. }),
  902. })
  903. );
  904. });
  905. it('Most slow frames widget', async function () {
  906. const data = initializeData();
  907. wrapper = render(
  908. <WrappedComponent
  909. data={data}
  910. defaultChartSetting={PerformanceWidgetSetting.MOST_SLOW_FRAMES}
  911. />
  912. );
  913. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  914. 'Most Slow Frames'
  915. );
  916. expect(eventsMock).toHaveBeenCalledTimes(1);
  917. expect(eventsMock).toHaveBeenNthCalledWith(
  918. 1,
  919. expect.anything(),
  920. expect.objectContaining({
  921. query: expect.objectContaining({
  922. cursor: '0:0:1',
  923. environment: ['prod'],
  924. field: ['transaction', 'project.id', 'epm()', 'avg(measurements.frames_slow)'],
  925. noPagination: true,
  926. per_page: QUERY_LIMIT_PARAM,
  927. project: ['-42'],
  928. query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_slow):>0',
  929. sort: '-avg(measurements.frames_slow)',
  930. statsPeriod: '7d',
  931. }),
  932. })
  933. );
  934. expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
  935. });
  936. it('Most slow frames widget - MEP', async function () {
  937. const data = initializeData(
  938. {},
  939. {
  940. features: ['performance-use-metrics'],
  941. }
  942. );
  943. wrapper = render(
  944. <WrappedComponent
  945. data={data}
  946. defaultChartSetting={PerformanceWidgetSetting.MOST_SLOW_FRAMES}
  947. />
  948. );
  949. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  950. 'Most Slow Frames'
  951. );
  952. expect(eventsMock).toHaveBeenCalledTimes(1);
  953. expect(eventsMock).toHaveBeenNthCalledWith(
  954. 1,
  955. expect.anything(),
  956. expect.objectContaining({
  957. query: expect.objectContaining({
  958. cursor: '0:0:1',
  959. environment: ['prod'],
  960. field: ['transaction', 'project.id', 'epm()', 'avg(measurements.frames_slow)'],
  961. noPagination: true,
  962. per_page: QUERY_LIMIT_PARAM,
  963. project: ['-42'],
  964. query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_slow):>0',
  965. sort: '-avg(measurements.frames_slow)',
  966. statsPeriod: '7d',
  967. }),
  968. })
  969. );
  970. expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
  971. });
  972. it('Most frozen frames widget', async function () {
  973. const data = initializeData();
  974. wrapper = render(
  975. <WrappedComponent
  976. data={data}
  977. defaultChartSetting={PerformanceWidgetSetting.MOST_FROZEN_FRAMES}
  978. />
  979. );
  980. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  981. 'Most Frozen Frames'
  982. );
  983. expect(eventsMock).toHaveBeenCalledTimes(1);
  984. expect(eventsMock).toHaveBeenNthCalledWith(
  985. 1,
  986. expect.anything(),
  987. expect.objectContaining({
  988. query: expect.objectContaining({
  989. cursor: '0:0:1',
  990. environment: ['prod'],
  991. field: [
  992. 'transaction',
  993. 'project.id',
  994. 'epm()',
  995. 'avg(measurements.frames_frozen)',
  996. ],
  997. noPagination: true,
  998. per_page: QUERY_LIMIT_PARAM,
  999. project: ['-42'],
  1000. query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_frozen):>0',
  1001. sort: '-avg(measurements.frames_frozen)',
  1002. statsPeriod: '7d',
  1003. }),
  1004. })
  1005. );
  1006. expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
  1007. });
  1008. it('Able to change widget type from menu', async function () {
  1009. const data = initializeData();
  1010. const setRowChartSettings = jest.fn(() => {});
  1011. wrapper = render(
  1012. <WrappedComponent
  1013. data={data}
  1014. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  1015. setRowChartSettings={setRowChartSettings}
  1016. />
  1017. );
  1018. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  1019. 'Failure Rate'
  1020. );
  1021. expect(eventStatsMock).toHaveBeenCalledTimes(1);
  1022. expect(setRowChartSettings).toHaveBeenCalledTimes(0);
  1023. await userEvent.click(await screen.findByLabelText('More'));
  1024. await userEvent.click(await screen.findByText('User Misery'));
  1025. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  1026. 'User Misery'
  1027. );
  1028. expect(eventStatsMock).toHaveBeenCalledTimes(2);
  1029. expect(setRowChartSettings).toHaveBeenCalledTimes(1);
  1030. });
  1031. it('Chart settings passed from the row are disabled in the menu', async function () {
  1032. const data = initializeData();
  1033. const setRowChartSettings = jest.fn(() => {});
  1034. wrapper = render(
  1035. <WrappedComponent
  1036. data={data}
  1037. defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
  1038. setRowChartSettings={setRowChartSettings}
  1039. rowChartSettings={[
  1040. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  1041. PerformanceWidgetSetting.USER_MISERY_AREA,
  1042. ]}
  1043. />
  1044. );
  1045. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  1046. 'Failure Rate'
  1047. );
  1048. // Open context menu
  1049. await userEvent.click(await screen.findByLabelText('More'));
  1050. // Check that the the "User Misery" option is disabled by clicking on it,
  1051. // expecting that the selected option doesn't change
  1052. const userMiseryOption = await screen.findByRole('option', {name: 'User Misery'});
  1053. await userEvent.click(userMiseryOption);
  1054. expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
  1055. 'Failure Rate'
  1056. );
  1057. });
  1058. });