index.spec.tsx 23 KB

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