index.spec.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. import type {Location} from 'history';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import type {InitializeDataSettings} from 'sentry-test/performance/initializePerformanceData';
  6. import {initializeData} from 'sentry-test/performance/initializePerformanceData';
  7. import {
  8. act,
  9. fireEvent,
  10. render,
  11. screen,
  12. userEvent,
  13. waitFor,
  14. within,
  15. } from 'sentry-test/reactTestingLibrary';
  16. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  17. import ProjectsStore from 'sentry/stores/projectsStore';
  18. import {WebVital} from 'sentry/utils/fields';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import TrendsIndex from 'sentry/views/performance/trends/';
  21. import {defaultTrendsSelectionDate} from 'sentry/views/performance/trends/content';
  22. import {
  23. DEFAULT_MAX_DURATION,
  24. TRENDS_FUNCTIONS,
  25. TRENDS_PARAMETERS,
  26. } from 'sentry/views/performance/trends/utils';
  27. const trendsViewQuery = {
  28. query: `tpm():>0.01 transaction.duration:>0 transaction.duration:<${DEFAULT_MAX_DURATION}`,
  29. };
  30. jest.mock('sentry/utils/useLocation');
  31. const mockUseLocation = jest.mocked(useLocation);
  32. jest.mock('moment-timezone', () => {
  33. const moment = jest.requireActual('moment-timezone');
  34. moment.now = jest.fn().mockReturnValue(1601251200000);
  35. return moment;
  36. });
  37. async function getTrendDropdown() {
  38. const dropdown = await screen.findByRole('button', {name: /Percentile.+/});
  39. expect(dropdown).toBeInTheDocument();
  40. return dropdown;
  41. }
  42. async function getParameterDropdown() {
  43. const dropdown = await screen.findByRole('button', {name: /Parameter.+/});
  44. expect(dropdown).toBeInTheDocument();
  45. return dropdown;
  46. }
  47. async function waitForMockCall(mock: any) {
  48. await waitFor(() => {
  49. expect(mock).toHaveBeenCalled();
  50. });
  51. }
  52. function enterSearch(el: HTMLElement, text: string) {
  53. fireEvent.change(el, {target: {value: text}});
  54. fireEvent.submit(el);
  55. }
  56. // Might swap on/off the skiphover to check perf later.
  57. async function clickEl(el: HTMLElement) {
  58. await userEvent.click(el, {skipHover: true});
  59. }
  60. function _initializeData(
  61. settings: InitializeDataSettings,
  62. options?: {selectedProjectId?: string}
  63. ) {
  64. const newSettings = {...settings};
  65. newSettings.projects = settings.projects ?? [
  66. ProjectFixture({id: '1', firstTransactionEvent: false}),
  67. ProjectFixture({id: '2', firstTransactionEvent: true}),
  68. ];
  69. if (options?.selectedProjectId) {
  70. const selectedProject = newSettings.projects.find(
  71. p => p.id === options.selectedProjectId
  72. );
  73. if (!selectedProject) {
  74. throw new Error("Test is selecting project that isn't loaded");
  75. } else {
  76. PageFiltersStore.updateProjects(
  77. settings.selectedProject ? [Number(selectedProject)] : [],
  78. []
  79. );
  80. }
  81. newSettings.selectedProject = selectedProject.id;
  82. }
  83. newSettings.selectedProject = settings.selectedProject ?? newSettings.projects[0]!.id;
  84. const data = initializeData(newSettings);
  85. // Modify page filters store to stop rerendering due to the test harness.
  86. PageFiltersStore.onInitializeUrlState(
  87. {
  88. projects: [],
  89. environments: [],
  90. datetime: {start: null, end: null, period: '24h', utc: null},
  91. },
  92. new Set()
  93. );
  94. PageFiltersStore.updateDateTime(defaultTrendsSelectionDate);
  95. if (!options?.selectedProjectId) {
  96. PageFiltersStore.updateProjects(
  97. settings.selectedProject ? [Number(newSettings.projects[0]!.id)] : [],
  98. []
  99. );
  100. }
  101. act(() => ProjectsStore.loadInitialData(data.projects));
  102. return data;
  103. }
  104. function initializeTrendsData(
  105. projects: null | any[] = null,
  106. query = {},
  107. includeDefaultQuery = true,
  108. extraFeatures?: string[]
  109. ) {
  110. const _projects = Array.isArray(projects)
  111. ? projects
  112. : [
  113. ProjectFixture({id: '1', firstTransactionEvent: false}),
  114. ProjectFixture({id: '2', firstTransactionEvent: true}),
  115. ];
  116. const features = extraFeatures
  117. ? ['transaction-event', 'performance-view', ...extraFeatures]
  118. : ['transaction-event', 'performance-view'];
  119. const organization = OrganizationFixture({features});
  120. const newQuery = {...(includeDefaultQuery ? trendsViewQuery : {}), ...query};
  121. mockUseLocation.mockReturnValue({
  122. pathname: '/organizations/org-slug/performance/trends/',
  123. action: 'PUSH',
  124. hash: '',
  125. key: '',
  126. query: newQuery,
  127. search: '',
  128. state: undefined,
  129. });
  130. const initialData = initializeOrg({
  131. organization,
  132. router: {
  133. location: {
  134. pathname: '/trends/',
  135. query: newQuery,
  136. },
  137. },
  138. projects: _projects,
  139. });
  140. act(() => ProjectsStore.loadInitialData(initialData.projects));
  141. return initialData;
  142. }
  143. describe('Performance > Trends', function () {
  144. let trendsStatsMock: jest.Mock;
  145. beforeEach(function () {
  146. mockUseLocation.mockReturnValue({
  147. pathname: '/organizations/org-slug/performance/trends/',
  148. action: 'PUSH',
  149. hash: '',
  150. key: '',
  151. query: {},
  152. search: '',
  153. state: undefined,
  154. });
  155. MockApiClient.addMockResponse({
  156. url: '/organizations/org-slug/projects/',
  157. body: [],
  158. });
  159. MockApiClient.addMockResponse({
  160. url: '/organizations/org-slug/tags/',
  161. body: [],
  162. });
  163. MockApiClient.addMockResponse({
  164. url: '/organizations/org-slug/users/',
  165. body: [],
  166. });
  167. MockApiClient.addMockResponse({
  168. url: '/organizations/org-slug/recent-searches/',
  169. body: [],
  170. });
  171. MockApiClient.addMockResponse({
  172. url: '/organizations/org-slug/recent-searches/',
  173. method: 'POST',
  174. body: [],
  175. });
  176. MockApiClient.addMockResponse({
  177. url: '/organizations/org-slug/sdk-updates/',
  178. body: [],
  179. });
  180. MockApiClient.addMockResponse({
  181. url: '/organizations/org-slug/prompts-activity/',
  182. body: {},
  183. });
  184. MockApiClient.addMockResponse({
  185. url: '/organizations/org-slug/releases/stats/',
  186. body: [],
  187. });
  188. MockApiClient.addMockResponse({
  189. url: '/organizations/org-slug/tags/transaction.duration/values/',
  190. body: [],
  191. });
  192. trendsStatsMock = MockApiClient.addMockResponse({
  193. url: '/organizations/org-slug/events-trends-stats/',
  194. body: {
  195. stats: {
  196. 'internal,/organizations/:orgId/performance/': {
  197. data: [[123, []]],
  198. },
  199. order: 0,
  200. },
  201. events: {
  202. meta: {
  203. count_range_1: 'integer',
  204. count_range_2: 'integer',
  205. count_percentage: 'percentage',
  206. breakpoint: 'number',
  207. trend_percentage: 'percentage',
  208. trend_difference: 'number',
  209. aggregate_range_1: 'duration',
  210. aggregate_range_2: 'duration',
  211. transaction: 'string',
  212. },
  213. data: [
  214. {
  215. count: 8,
  216. project: 'internal',
  217. count_range_1: 2,
  218. count_range_2: 6,
  219. count_percentage: 3,
  220. breakpoint: 1686967200,
  221. trend_percentage: 1.9235225955967554,
  222. trend_difference: 797,
  223. aggregate_range_1: 863,
  224. aggregate_range_2: 1660,
  225. transaction: '/organizations/:orgId/performance/',
  226. },
  227. {
  228. count: 60,
  229. project: 'internal',
  230. count_range_1: 20,
  231. count_range_2: 40,
  232. count_percentage: 2,
  233. breakpoint: 1686967200,
  234. trend_percentage: 1.204968944099379,
  235. trend_difference: 66,
  236. aggregate_range_1: 322,
  237. aggregate_range_2: 388,
  238. transaction: '/api/0/internal/health/',
  239. },
  240. ],
  241. },
  242. },
  243. });
  244. MockApiClient.addMockResponse({
  245. url: '/organizations/org-slug/events-spans-performance/',
  246. body: [],
  247. });
  248. });
  249. afterEach(function () {
  250. MockApiClient.clearMockResponses();
  251. act(() => ProjectsStore.reset());
  252. });
  253. it('renders basic UI elements', async function () {
  254. const data = _initializeData({});
  255. render(
  256. <TrendsIndex location={data.router.location} organization={data.organization} />,
  257. {
  258. router: data.router,
  259. organization: data.organization,
  260. }
  261. );
  262. expect(await getTrendDropdown()).toBeInTheDocument();
  263. expect(await getParameterDropdown()).toBeInTheDocument();
  264. expect(screen.getAllByTestId('changed-transactions')).toHaveLength(2);
  265. });
  266. it('transaction list items are rendered', async function () {
  267. const data = _initializeData({});
  268. render(
  269. <TrendsIndex location={data.router.location} organization={data.organization} />,
  270. {
  271. router: data.router,
  272. organization: data.organization,
  273. }
  274. );
  275. expect(await screen.findAllByTestId('trends-list-item-regression')).toHaveLength(2);
  276. expect(await screen.findAllByTestId('trends-list-item-improved')).toHaveLength(2);
  277. });
  278. it('view summary menu action links to the correct view', async function () {
  279. const projects = [ProjectFixture({id: '1', slug: 'internal'}), ProjectFixture()];
  280. const data = initializeTrendsData(projects, {project: ['1']});
  281. render(
  282. <TrendsIndex location={data.router.location} organization={data.organization} />,
  283. {
  284. router: data.router,
  285. organization: data.organization,
  286. }
  287. );
  288. const transactions = await screen.findAllByTestId('trends-list-item-improved');
  289. expect(transactions).toHaveLength(2);
  290. const firstTransaction = transactions[0]!;
  291. const summaryLink = within(firstTransaction).getByTestId('item-transaction-name');
  292. expect(summaryLink.closest('a')).toHaveAttribute(
  293. 'href',
  294. '/organizations/org-slug/performance/summary/?display=trend&project=1&query=tpm%28%29%3A%3E0.01%20transaction.duration%3A%3E0%20transaction.duration%3A%3C15min%20count_percentage%28%29%3A%3E0.25%20count_percentage%28%29%3A%3C4%20trend_percentage%28%29%3A%3E0%25%20confidence%28%29%3A%3E6&referrer=performance-transaction-summary&statsPeriod=14d&transaction=%2Forganizations%2F%3AorgId%2Fperformance%2F&trendFunction=p95&unselectedSeries=p100%28%29&unselectedSeries=avg%28%29'
  295. );
  296. });
  297. it('hide from list menu action modifies query', async function () {
  298. const projects = [ProjectFixture({id: '1', slug: 'internal'}), ProjectFixture()];
  299. const data = initializeTrendsData(projects, {project: ['1']});
  300. render(
  301. <TrendsIndex location={data.router.location} organization={data.organization} />,
  302. {
  303. router: data.router,
  304. organization: data.organization,
  305. }
  306. );
  307. const transactions = await screen.findAllByTestId('trends-list-item-improved');
  308. expect(transactions).toHaveLength(2);
  309. const firstTransaction = transactions[0]!;
  310. await userEvent.click(
  311. within(firstTransaction).getByRole('button', {name: 'Actions'})
  312. );
  313. await waitFor(() => {
  314. const menuActions = within(firstTransaction).getAllByRole('menuitemradio');
  315. expect(menuActions).toHaveLength(3);
  316. });
  317. const menuAction = within(firstTransaction).getAllByRole('menuitemradio')[2]!;
  318. await clickEl(menuAction);
  319. expect(data.router.push).toHaveBeenCalledWith({
  320. pathname: '/trends/',
  321. query: expect.objectContaining({
  322. project: expect.anything(),
  323. query: `tpm():>0.01 transaction.duration:>0 transaction.duration:<${DEFAULT_MAX_DURATION} !transaction:/organizations/:orgId/performance/`,
  324. }),
  325. });
  326. });
  327. it('Changing search causes cursors to be reset', async function () {
  328. const projects = [ProjectFixture({id: '1', slug: 'internal'}), ProjectFixture()];
  329. const data = initializeTrendsData(projects, {project: ['1']});
  330. render(
  331. <TrendsIndex location={data.router.location} organization={data.organization} />,
  332. {
  333. router: data.router,
  334. organization: data.organization,
  335. }
  336. );
  337. const input = await screen.findByTestId('smart-search-input');
  338. enterSearch(input, 'transaction.duration:>9000');
  339. await waitFor(() =>
  340. expect(data.router.push).toHaveBeenCalledWith({
  341. pathname: '/trends/',
  342. query: expect.objectContaining({
  343. project: ['1'],
  344. query: 'transaction.duration:>9000',
  345. improvedCursor: undefined,
  346. regressionCursor: undefined,
  347. }),
  348. })
  349. );
  350. });
  351. it('exclude greater than list menu action modifies query', async function () {
  352. const projects = [ProjectFixture({id: '1', slug: 'internal'}), ProjectFixture()];
  353. const data = initializeTrendsData(projects, {project: ['1']});
  354. render(
  355. <TrendsIndex location={data.router.location} organization={data.organization} />,
  356. {
  357. router: data.router,
  358. organization: data.organization,
  359. }
  360. );
  361. const transactions = await screen.findAllByTestId('trends-list-item-improved');
  362. expect(transactions).toHaveLength(2);
  363. const firstTransaction = transactions[0]!;
  364. await userEvent.click(
  365. within(firstTransaction).getByRole('button', {name: 'Actions'})
  366. );
  367. await waitFor(() => {
  368. const menuActions = within(firstTransaction).getAllByRole('menuitemradio');
  369. expect(menuActions).toHaveLength(3);
  370. });
  371. const menuAction = within(firstTransaction).getAllByRole('menuitemradio')[0]!;
  372. await clickEl(menuAction);
  373. expect(data.router.push).toHaveBeenCalledWith({
  374. pathname: '/trends/',
  375. query: expect.objectContaining({
  376. project: expect.anything(),
  377. query: 'tpm():>0.01 transaction.duration:>0 transaction.duration:<=863',
  378. }),
  379. });
  380. });
  381. it('exclude less than list menu action modifies query', async function () {
  382. const projects = [ProjectFixture({id: '1', slug: 'internal'}), ProjectFixture()];
  383. const data = initializeTrendsData(projects, {project: ['1']});
  384. render(
  385. <TrendsIndex location={data.router.location} organization={data.organization} />,
  386. {
  387. router: data.router,
  388. organization: data.organization,
  389. }
  390. );
  391. const transactions = await screen.findAllByTestId('trends-list-item-improved');
  392. expect(transactions).toHaveLength(2);
  393. const firstTransaction = transactions[0]!;
  394. await userEvent.click(
  395. within(firstTransaction).getByRole('button', {name: 'Actions'})
  396. );
  397. await waitFor(() => {
  398. const menuActions = within(firstTransaction).getAllByRole('menuitemradio');
  399. expect(menuActions).toHaveLength(3);
  400. });
  401. const menuAction = within(firstTransaction).getAllByRole('menuitemradio')[1]!;
  402. await clickEl(menuAction);
  403. expect(data.router.push).toHaveBeenCalledWith({
  404. pathname: '/trends/',
  405. query: expect.objectContaining({
  406. project: expect.anything(),
  407. query: 'tpm():>0.01 transaction.duration:<15min transaction.duration:>=863',
  408. }),
  409. });
  410. });
  411. it('choosing a trend function changes location', async function () {
  412. const projects = [ProjectFixture()];
  413. const data = initializeTrendsData(projects, {project: ['-1']});
  414. render(
  415. <TrendsIndex location={data.router.location} organization={data.organization} />,
  416. {
  417. router: data.router,
  418. organization: data.organization,
  419. }
  420. );
  421. for (const trendFunction of TRENDS_FUNCTIONS) {
  422. // Open dropdown
  423. const dropdown = await getTrendDropdown();
  424. await clickEl(dropdown);
  425. // Select function
  426. const option = screen.getByRole('option', {name: trendFunction.label});
  427. await clickEl(option);
  428. expect(data.router.push).toHaveBeenCalledWith({
  429. pathname: '/trends/',
  430. query: expect.objectContaining({
  431. regressionCursor: undefined,
  432. improvedCursor: undefined,
  433. trendFunction: trendFunction.field,
  434. }),
  435. });
  436. }
  437. });
  438. it('sets LCP as a default trend parameter for frontend project if query does not specify trend parameter', async function () {
  439. const projects = [ProjectFixture({id: '1', platform: 'javascript'})];
  440. const data = initializeTrendsData(projects, {project: [1]});
  441. render(
  442. <TrendsIndex location={data.router.location} organization={data.organization} />,
  443. {
  444. router: data.router,
  445. organization: data.organization,
  446. }
  447. );
  448. const trendDropdownButton = await getTrendDropdown();
  449. expect(trendDropdownButton).toHaveTextContent('Percentilep95');
  450. });
  451. it('sets duration as a default trend parameter for backend project if query does not specify trend parameter', async function () {
  452. const projects = [ProjectFixture({id: '1', platform: 'python'})];
  453. const data = initializeTrendsData(projects, {project: [1]});
  454. render(
  455. <TrendsIndex location={data.router.location} organization={data.organization} />,
  456. {
  457. router: data.router,
  458. organization: data.organization,
  459. }
  460. );
  461. const parameterDropdownButton = await getParameterDropdown();
  462. expect(parameterDropdownButton).toHaveTextContent('ParameterDuration');
  463. });
  464. it('sets trend parameter from query and ignores default trend parameter', async function () {
  465. const projects = [ProjectFixture({id: '1', platform: 'javascript'})];
  466. const data = initializeTrendsData(projects, {project: [1], trendParameter: 'FCP'});
  467. render(
  468. <TrendsIndex location={data.router.location} organization={data.organization} />,
  469. {
  470. router: data.router,
  471. organization: data.organization,
  472. }
  473. );
  474. const parameterDropdownButton = await getParameterDropdown();
  475. expect(parameterDropdownButton).toHaveTextContent('ParameterFCP');
  476. });
  477. it('choosing a parameter changes location', async function () {
  478. const projects = [ProjectFixture()];
  479. const data = initializeTrendsData(projects, {project: ['-1']});
  480. render(
  481. <TrendsIndex location={data.router.location} organization={data.organization} />,
  482. {
  483. router: data.router,
  484. organization: data.organization,
  485. }
  486. );
  487. for (const parameter of TRENDS_PARAMETERS) {
  488. // Open dropdown
  489. const dropdown = await getParameterDropdown();
  490. await clickEl(dropdown);
  491. // Select parameter
  492. const option = screen.getByRole('option', {name: parameter.label});
  493. await clickEl(option);
  494. expect(data.router.push).toHaveBeenCalledWith({
  495. pathname: '/trends/',
  496. query: expect.objectContaining({
  497. trendParameter: parameter.label,
  498. }),
  499. });
  500. }
  501. });
  502. it('choosing a web vitals parameter adds it as an additional condition to the query', async function () {
  503. const projects = [ProjectFixture()];
  504. const data = initializeTrendsData(projects, {project: ['-1']});
  505. const {rerender} = render(
  506. <TrendsIndex location={data.router.location} organization={data.organization} />,
  507. {
  508. router: data.router,
  509. organization: data.organization,
  510. }
  511. );
  512. for (const parameter of TRENDS_PARAMETERS) {
  513. if (Object.values(WebVital).includes(parameter.column as string as WebVital)) {
  514. trendsStatsMock.mockReset();
  515. const newLocation = {
  516. query: {...trendsViewQuery, trendParameter: parameter.label},
  517. };
  518. rerender(
  519. <TrendsIndex
  520. location={newLocation as unknown as Location}
  521. organization={data.organization}
  522. />
  523. );
  524. await waitForMockCall(trendsStatsMock);
  525. expect(trendsStatsMock).toHaveBeenCalledTimes(2);
  526. // Improved transactions call
  527. expect(trendsStatsMock).toHaveBeenNthCalledWith(
  528. 1,
  529. expect.anything(),
  530. expect.objectContaining({
  531. query: expect.objectContaining({
  532. query: expect.stringContaining(`has:${parameter.column}`),
  533. }),
  534. })
  535. );
  536. // Regression transactions call
  537. expect(trendsStatsMock).toHaveBeenNthCalledWith(
  538. 2,
  539. expect.anything(),
  540. expect.objectContaining({
  541. query: expect.objectContaining({
  542. query: expect.stringContaining(`has:${parameter.column}`),
  543. }),
  544. })
  545. );
  546. }
  547. }
  548. });
  549. it('trend functions in location make api calls', async function () {
  550. const projects = [ProjectFixture(), ProjectFixture()];
  551. const data = initializeTrendsData(projects, {project: ['-1']});
  552. const {rerender} = render(
  553. <TrendsIndex location={data.router.location} organization={data.organization} />,
  554. {
  555. router: data.router,
  556. organization: data.organization,
  557. }
  558. );
  559. for (const trendFunction of TRENDS_FUNCTIONS) {
  560. trendsStatsMock.mockReset();
  561. const newLocation = {
  562. query: {...trendsViewQuery, trendFunction: trendFunction.field},
  563. };
  564. rerender(
  565. <TrendsIndex
  566. location={newLocation as unknown as Location}
  567. organization={data.organization}
  568. />
  569. );
  570. await waitForMockCall(trendsStatsMock);
  571. expect(trendsStatsMock).toHaveBeenCalledTimes(2);
  572. const sort = 'trend_percentage()';
  573. const defaultTrendsFields = ['project'];
  574. const transactionFields = ['transaction', ...defaultTrendsFields];
  575. const projectFields = [...defaultTrendsFields];
  576. expect(transactionFields).toHaveLength(2);
  577. expect(projectFields).toHaveLength(transactionFields.length - 1);
  578. // Improved transactions call
  579. expect(trendsStatsMock).toHaveBeenNthCalledWith(
  580. 1,
  581. expect.anything(),
  582. expect.objectContaining({
  583. query: expect.objectContaining({
  584. trendFunction: `${trendFunction.field}(transaction.duration)`,
  585. sort,
  586. query: expect.stringContaining('trend_percentage():>0%'),
  587. interval: '1h',
  588. field: transactionFields,
  589. statsPeriod: '14d',
  590. }),
  591. })
  592. );
  593. // Regression transactions call
  594. expect(trendsStatsMock).toHaveBeenNthCalledWith(
  595. 2,
  596. expect.anything(),
  597. expect.objectContaining({
  598. query: expect.objectContaining({
  599. trendFunction: `${trendFunction.field}(transaction.duration)`,
  600. sort: '-' + sort,
  601. query: expect.stringContaining('trend_percentage():>0%'),
  602. interval: '1h',
  603. field: transactionFields,
  604. statsPeriod: '14d',
  605. }),
  606. })
  607. );
  608. }
  609. });
  610. it('Visiting trends with trends feature will update filters if none are set', async function () {
  611. const data = initializeTrendsData(undefined, {}, false);
  612. render(
  613. <TrendsIndex location={data.router.location} organization={data.organization} />,
  614. {
  615. router: data.router,
  616. organization: data.organization,
  617. }
  618. );
  619. await waitFor(() =>
  620. expect(data.router.push).toHaveBeenNthCalledWith(
  621. 1,
  622. expect.objectContaining({
  623. query: {
  624. query: `tpm():>0.01 transaction.duration:>0 transaction.duration:<${DEFAULT_MAX_DURATION}`,
  625. },
  626. })
  627. )
  628. );
  629. });
  630. it('Navigating away from trends will remove extra tags from query', async function () {
  631. const data = initializeTrendsData(
  632. undefined,
  633. {
  634. query: `device.family:Mac tpm():>0.01 transaction.duration:>0 transaction.duration:<${DEFAULT_MAX_DURATION}`,
  635. },
  636. false
  637. );
  638. render(
  639. <TrendsIndex location={data.router.location} organization={data.organization} />,
  640. {
  641. router: data.router,
  642. organization: data.organization,
  643. }
  644. );
  645. jest.mocked(data.router.push).mockReset();
  646. const byTransactionLink = await screen.findByTestId('breadcrumb-link');
  647. expect(byTransactionLink.closest('a')).toHaveAttribute(
  648. 'href',
  649. '/organizations/org-slug/performance/?query=device.family%3AMac'
  650. );
  651. });
  652. });