transactionSummary.spec.tsx 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. import {browserHistory} from 'react-router';
  2. import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import TeamStore from 'sentry/stores/teamStore';
  7. import {Project} from 'sentry/types';
  8. import {
  9. MEPSetting,
  10. MEPState,
  11. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  12. import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';
  13. const teams = [
  14. TestStubs.Team({id: '1', slug: 'team1', name: 'Team 1'}),
  15. TestStubs.Team({id: '2', slug: 'team2', name: 'Team 2'}),
  16. ];
  17. function initializeData({
  18. features: additionalFeatures = [],
  19. query = {},
  20. project: prj,
  21. }: {features?: string[]; project?: Project; query?: Record<string, any>} = {}) {
  22. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  23. const project = prj ?? TestStubs.Project({teams});
  24. const organization = TestStubs.Organization({
  25. features,
  26. projects: [project],
  27. apdexThreshold: 400,
  28. });
  29. const initialData = initializeOrg({
  30. ...initializeOrg(),
  31. organization,
  32. router: {
  33. location: {
  34. query: {
  35. transaction: '/performance',
  36. project: project.id,
  37. transactionCursor: '1:0:0',
  38. ...query,
  39. },
  40. },
  41. },
  42. });
  43. ProjectsStore.loadInitialData(initialData.organization.projects);
  44. TeamStore.loadInitialData(teams, false, null);
  45. return initialData;
  46. }
  47. const TestComponent = ({...props}: React.ComponentProps<typeof TransactionSummary>) => {
  48. const client = new QueryClient();
  49. return (
  50. <QueryClientProvider client={client}>
  51. <TransactionSummary {...props} />
  52. </QueryClientProvider>
  53. );
  54. };
  55. describe('Performance > TransactionSummary', function () {
  56. beforeEach(function () {
  57. // @ts-ignore no-console
  58. // eslint-disable-next-line no-console
  59. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  60. MockApiClient.clearMockResponses();
  61. MockApiClient.addMockResponse({
  62. url: '/organizations/org-slug/projects/',
  63. body: [],
  64. });
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/tags/',
  67. body: [],
  68. });
  69. MockApiClient.addMockResponse({
  70. url: '/organizations/org-slug/tags/user.email/values/',
  71. body: [],
  72. });
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/events-stats/',
  75. body: {data: [[123, []]]},
  76. });
  77. MockApiClient.addMockResponse({
  78. url: '/organizations/org-slug/releases/stats/',
  79. body: [],
  80. });
  81. MockApiClient.addMockResponse({
  82. url: '/organizations/org-slug/issues/?limit=5&project=2&query=is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  83. body: [],
  84. });
  85. MockApiClient.addMockResponse({
  86. url: '/organizations/org-slug/users/',
  87. body: [],
  88. });
  89. MockApiClient.addMockResponse({
  90. url: '/organizations/org-slug/recent-searches/',
  91. body: [],
  92. });
  93. MockApiClient.addMockResponse({
  94. url: '/organizations/org-slug/recent-searches/',
  95. method: 'POST',
  96. body: [],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: '/organizations/org-slug/sdk-updates/',
  100. body: [],
  101. });
  102. MockApiClient.addMockResponse({
  103. url: '/prompts-activity/',
  104. body: {},
  105. });
  106. MockApiClient.addMockResponse({
  107. url: '/organizations/org-slug/events-facets-performance/',
  108. body: {},
  109. });
  110. // Mock totals for the sidebar and other summary data
  111. MockApiClient.addMockResponse({
  112. url: '/organizations/org-slug/eventsv2/',
  113. body: {
  114. meta: {
  115. count: 'number',
  116. apdex: 'number',
  117. count_miserable_user: 'number',
  118. user_misery: 'number',
  119. count_unique_user: 'number',
  120. p95: 'number',
  121. failure_rate: 'number',
  122. tpm: 'number',
  123. project_threshold_config: 'string',
  124. },
  125. data: [
  126. {
  127. count: 2,
  128. apdex: 0.6,
  129. count_miserable_user: 122,
  130. user_misery: 0.114,
  131. count_unique_user: 1,
  132. p95: 750.123,
  133. failure_rate: 1,
  134. tpm: 1,
  135. project_threshold_config: ['duration', 300],
  136. },
  137. ],
  138. },
  139. match: [
  140. (_url, options) => {
  141. return options.query?.field?.includes('p95()');
  142. },
  143. ],
  144. });
  145. // Eventsv2 Transaction list response
  146. MockApiClient.addMockResponse({
  147. url: '/organizations/org-slug/eventsv2/',
  148. headers: {
  149. Link:
  150. '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  151. '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  152. },
  153. body: {
  154. meta: {
  155. id: 'string',
  156. 'user.display': 'string',
  157. 'transaction.duration': 'duration',
  158. 'project.id': 'integer',
  159. timestamp: 'date',
  160. },
  161. data: [
  162. {
  163. id: 'deadbeef',
  164. 'user.display': 'uhoh@example.com',
  165. 'transaction.duration': 400,
  166. 'project.id': 2,
  167. timestamp: '2020-05-21T15:31:18+00:00',
  168. },
  169. ],
  170. },
  171. match: [
  172. (_url, options) => {
  173. return options.query?.field?.includes('user.display');
  174. },
  175. ],
  176. });
  177. // Eventsv2 Mock totals for status breakdown
  178. MockApiClient.addMockResponse({
  179. url: '/organizations/org-slug/eventsv2/',
  180. body: {
  181. meta: {
  182. 'transaction.status': 'string',
  183. count: 'number',
  184. },
  185. data: [
  186. {
  187. count: 2,
  188. 'transaction.status': 'ok',
  189. },
  190. ],
  191. },
  192. match: [
  193. (_url, options) => {
  194. return options.query?.field?.includes('transaction.status');
  195. },
  196. ],
  197. });
  198. // Events Mock totals for the sidebar and other summary data
  199. MockApiClient.addMockResponse({
  200. url: '/organizations/org-slug/events/',
  201. body: {
  202. meta: {
  203. fields: {
  204. 'count()': 'number',
  205. 'apdex()': 'number',
  206. 'count_miserable_user()': 'number',
  207. 'user_misery()': 'number',
  208. 'count_unique_user()': 'number',
  209. 'p95()': 'number',
  210. 'failure_rate()': 'number',
  211. 'tpm()': 'number',
  212. project_threshold_config: 'string',
  213. },
  214. },
  215. data: [
  216. {
  217. 'count()': 2,
  218. 'apdex()': 0.6,
  219. 'count_miserable_user()': 122,
  220. 'user_misery()': 0.114,
  221. 'count_unique_user()': 1,
  222. 'p95()': 750.123,
  223. 'failure_rate()': 1,
  224. 'tpm()': 1,
  225. project_threshold_config: ['duration', 300],
  226. },
  227. ],
  228. },
  229. match: [
  230. (_url, options) => {
  231. return options.query?.field?.includes('p95()');
  232. },
  233. ],
  234. });
  235. // Events Transaction list response
  236. MockApiClient.addMockResponse({
  237. url: '/organizations/org-slug/events/',
  238. headers: {
  239. Link:
  240. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  241. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  242. },
  243. body: {
  244. meta: {
  245. fields: {
  246. id: 'string',
  247. 'user.display': 'string',
  248. 'transaction.duration': 'duration',
  249. 'project.id': 'integer',
  250. timestamp: 'date',
  251. },
  252. },
  253. data: [
  254. {
  255. id: 'deadbeef',
  256. 'user.display': 'uhoh@example.com',
  257. 'transaction.duration': 400,
  258. 'project.id': 2,
  259. timestamp: '2020-05-21T15:31:18+00:00',
  260. },
  261. ],
  262. },
  263. match: [
  264. (_url, options) => {
  265. return options.query?.field?.includes('user.display');
  266. },
  267. ],
  268. });
  269. // Events Mock totals for status breakdown
  270. MockApiClient.addMockResponse({
  271. url: '/organizations/org-slug/events/',
  272. body: {
  273. meta: {
  274. fields: {
  275. 'transaction.status': 'string',
  276. 'count()': 'number',
  277. },
  278. },
  279. data: [
  280. {
  281. 'count()': 2,
  282. 'transaction.status': 'ok',
  283. },
  284. ],
  285. },
  286. match: [
  287. (_url, options) => {
  288. return options.query?.field?.includes('transaction.status');
  289. },
  290. ],
  291. });
  292. MockApiClient.addMockResponse({
  293. url: '/organizations/org-slug/events-facets/',
  294. body: [
  295. {
  296. key: 'release',
  297. topValues: [{count: 3, value: 'abcd123', name: 'abcd123'}],
  298. },
  299. {
  300. key: 'environment',
  301. topValues: [{count: 2, value: 'dev', name: 'dev'}],
  302. },
  303. {
  304. key: 'foo',
  305. topValues: [{count: 1, value: 'bar', name: 'bar'}],
  306. },
  307. ],
  308. });
  309. MockApiClient.addMockResponse({
  310. url: '/organizations/org-slug/project-transaction-threshold-override/',
  311. method: 'GET',
  312. body: {
  313. threshold: '800',
  314. metric: 'lcp',
  315. },
  316. });
  317. MockApiClient.addMockResponse({
  318. url: '/organizations/org-slug/events-vitals/',
  319. body: {
  320. 'measurements.fcp': {
  321. poor: 3,
  322. meh: 100,
  323. good: 47,
  324. total: 150,
  325. p75: 1500,
  326. },
  327. 'measurements.lcp': {
  328. poor: 2,
  329. meh: 38,
  330. good: 40,
  331. total: 80,
  332. p75: 2750,
  333. },
  334. 'measurements.fid': {
  335. poor: 2,
  336. meh: 53,
  337. good: 5,
  338. total: 60,
  339. p75: 1000,
  340. },
  341. 'measurements.cls': {
  342. poor: 3,
  343. meh: 10,
  344. good: 4,
  345. total: 17,
  346. p75: 0.2,
  347. },
  348. },
  349. });
  350. MockApiClient.addMockResponse({
  351. method: 'GET',
  352. url: `/organizations/org-slug/key-transactions-list/`,
  353. body: teams.map(({id}) => ({
  354. team: id,
  355. count: 0,
  356. keyed: [],
  357. })),
  358. });
  359. MockApiClient.addMockResponse({
  360. url: '/organizations/org-slug/events-has-measurements/',
  361. body: {measurements: false},
  362. });
  363. jest.spyOn(MEPSetting, 'get').mockImplementation(() => MEPState.auto);
  364. });
  365. afterEach(function () {
  366. MockApiClient.clearMockResponses();
  367. ProjectsStore.reset();
  368. jest.clearAllMocks();
  369. // @ts-ignore no-console
  370. // eslint-disable-next-line no-console
  371. console.error.mockRestore();
  372. });
  373. describe('with eventsv2', function () {
  374. it('renders basic UI elements', async function () {
  375. const {organization, router, routerContext} = initializeData();
  376. render(<TestComponent location={router.location} />, {
  377. context: routerContext,
  378. organization,
  379. });
  380. // It shows the header
  381. await screen.findByText('Transaction Summary');
  382. expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
  383. // It shows a chart
  384. expect(
  385. screen.getByRole('button', {name: 'Display Duration Breakdown'})
  386. ).toBeInTheDocument();
  387. // It shows a searchbar
  388. expect(screen.getByLabelText('Search events')).toBeInTheDocument();
  389. // It shows a table
  390. expect(screen.getByTestId('transactions-table')).toBeInTheDocument();
  391. // Ensure open in discover button exists.
  392. expect(screen.getByTestId('transaction-events-open')).toBeInTheDocument();
  393. // Ensure open issues button exists.
  394. expect(screen.getByRole('button', {name: 'Open in Issues'})).toBeInTheDocument();
  395. // Ensure transaction filter button exists
  396. expect(screen.getByText('Filter').closest('button')).toBeInTheDocument();
  397. // Ensure create alert from discover is hidden without metric alert
  398. expect(
  399. screen.queryByRole('button', {name: 'Create Alert'})
  400. ).not.toBeInTheDocument();
  401. // Ensure status breakdown exists
  402. expect(screen.getByText('Status Breakdown')).toBeInTheDocument();
  403. });
  404. it('renders feature flagged UI elements', function () {
  405. const {organization, router, routerContext} = initializeData({
  406. features: ['incidents'],
  407. });
  408. render(<TestComponent location={router.location} />, {
  409. context: routerContext,
  410. organization,
  411. });
  412. // Ensure create alert from discover is shown with metric alerts
  413. expect(screen.getByRole('button', {name: 'Create Alert'})).toBeInTheDocument();
  414. });
  415. it('renders Web Vitals widget', async function () {
  416. const {organization, router, routerContext} = initializeData({
  417. project: TestStubs.Project({teams, platform: 'javascript'}),
  418. query: {
  419. query:
  420. 'transaction.duration:<15m transaction.op:pageload event.type:transaction transaction:/organizations/:orgId/issues/',
  421. },
  422. });
  423. render(<TestComponent location={router.location} />, {
  424. context: routerContext,
  425. organization,
  426. });
  427. // It renders the web vitals widget
  428. await screen.findByRole('heading', {name: 'Web Vitals'});
  429. const vitalStatues = screen.getAllByTestId('vital-status');
  430. expect(vitalStatues).toHaveLength(3);
  431. expect(vitalStatues[0]).toHaveTextContent('31%');
  432. expect(vitalStatues[1]).toHaveTextContent('65%');
  433. expect(vitalStatues[2]).toHaveTextContent('3%');
  434. });
  435. it('renders sidebar widgets', async function () {
  436. const {organization, router, routerContext} = initializeData();
  437. render(<TestComponent location={router.location} />, {
  438. context: routerContext,
  439. organization,
  440. });
  441. // Renders Apdex widget
  442. await screen.findByRole('heading', {name: 'Apdex'});
  443. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  444. // Renders Failure Rate widget
  445. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  446. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  447. // Renders TPM widget
  448. expect(screen.getByRole('heading', {name: 'TPM'})).toBeInTheDocument();
  449. expect(screen.getByTestId('tpm-summary-value')).toHaveTextContent('1 tpm');
  450. });
  451. it('fetches transaction threshold', function () {
  452. const {organization, router, routerContext} = initializeData();
  453. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  454. url: '/organizations/org-slug/project-transaction-threshold-override/',
  455. method: 'GET',
  456. body: {
  457. threshold: '800',
  458. metric: 'lcp',
  459. },
  460. });
  461. const getProjectThresholdMock = MockApiClient.addMockResponse({
  462. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  463. method: 'GET',
  464. body: {
  465. threshold: '200',
  466. metric: 'duration',
  467. },
  468. });
  469. render(<TestComponent location={router.location} />, {
  470. context: routerContext,
  471. organization,
  472. });
  473. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  474. expect(getProjectThresholdMock).not.toHaveBeenCalled();
  475. });
  476. it('fetches project transaction threshdold', async function () {
  477. const {organization, router, routerContext} = initializeData();
  478. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  479. url: '/organizations/org-slug/project-transaction-threshold-override/',
  480. method: 'GET',
  481. statusCode: 404,
  482. });
  483. const getProjectThresholdMock = MockApiClient.addMockResponse({
  484. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  485. method: 'GET',
  486. body: {
  487. threshold: '200',
  488. metric: 'duration',
  489. },
  490. });
  491. render(<TestComponent location={router.location} />, {
  492. context: routerContext,
  493. organization,
  494. });
  495. await screen.findByText('Transaction Summary');
  496. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  497. expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
  498. });
  499. it('triggers a navigation on search', function () {
  500. const {organization, router, routerContext} = initializeData();
  501. render(<TestComponent location={router.location} />, {
  502. context: routerContext,
  503. organization,
  504. });
  505. // Fill out the search box, and submit it.
  506. userEvent.type(screen.getByLabelText('Search events'), 'user.email:uhoh*{enter}');
  507. // Check the navigation.
  508. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  509. expect(browserHistory.push).toHaveBeenCalledWith({
  510. pathname: undefined,
  511. query: {
  512. transaction: '/performance',
  513. project: '2',
  514. statsPeriod: '14d',
  515. query: 'user.email:uhoh*',
  516. transactionCursor: '1:0:0',
  517. },
  518. });
  519. });
  520. it('can mark a transaction as key', async function () {
  521. const {organization, router, routerContext} = initializeData();
  522. render(<TestComponent location={router.location} />, {
  523. context: routerContext,
  524. organization,
  525. });
  526. const mockUpdate = MockApiClient.addMockResponse({
  527. url: `/organizations/org-slug/key-transactions/`,
  528. method: 'POST',
  529. body: {},
  530. });
  531. await screen.findByRole('button', {name: 'Star for Team'});
  532. // Click the key transaction button
  533. userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
  534. userEvent.click(screen.getByText('team1'), undefined, {
  535. skipPointerEventsCheck: true,
  536. });
  537. // Ensure request was made.
  538. expect(mockUpdate).toHaveBeenCalled();
  539. });
  540. it('triggers a navigation on transaction filter', async function () {
  541. const {organization, router, routerContext} = initializeData();
  542. render(<TestComponent location={router.location} />, {
  543. context: routerContext,
  544. organization,
  545. });
  546. await screen.findByText('Transaction Summary');
  547. // Open the transaction filter dropdown
  548. userEvent.click(
  549. screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
  550. );
  551. userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
  552. // Check the navigation.
  553. expect(browserHistory.push).toHaveBeenCalledWith({
  554. pathname: undefined,
  555. query: {
  556. transaction: '/performance',
  557. project: '2',
  558. showTransactions: 'slow',
  559. transactionCursor: undefined,
  560. },
  561. });
  562. });
  563. it('renders pagination buttons', async function () {
  564. const {organization, router, routerContext} = initializeData();
  565. render(<TestComponent location={router.location} />, {
  566. context: routerContext,
  567. organization,
  568. });
  569. await screen.findByText('Transaction Summary');
  570. expect(await screen.findByLabelText('Previous')).toBeInTheDocument();
  571. // Click the 'next' button
  572. userEvent.click(screen.getByLabelText('Next'));
  573. // Check the navigation.
  574. expect(browserHistory.push).toHaveBeenCalledWith({
  575. pathname: undefined,
  576. query: {
  577. transaction: '/performance',
  578. project: '2',
  579. transactionCursor: '2:0:0',
  580. },
  581. });
  582. });
  583. it('forwards conditions to related issues', async function () {
  584. const issueGet = MockApiClient.addMockResponse({
  585. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  586. body: [],
  587. });
  588. const {organization, router, routerContext} = initializeData({
  589. query: {query: 'tag:value'},
  590. });
  591. render(<TestComponent location={router.location} />, {
  592. context: routerContext,
  593. organization,
  594. });
  595. await screen.findByText('Transaction Summary');
  596. expect(issueGet).toHaveBeenCalled();
  597. });
  598. it('does not forward event type to related issues', async function () {
  599. const issueGet = MockApiClient.addMockResponse({
  600. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  601. body: [],
  602. match: [
  603. (_, options) => {
  604. // event.type must NOT be in the query params
  605. return !options.query?.query?.includes('event.type');
  606. },
  607. ],
  608. });
  609. const {organization, router, routerContext} = initializeData({
  610. query: {query: 'tag:value event.type:transaction'},
  611. });
  612. render(<TestComponent location={router.location} />, {
  613. context: routerContext,
  614. organization,
  615. });
  616. await screen.findByText('Transaction Summary');
  617. expect(issueGet).toHaveBeenCalled();
  618. });
  619. it('renders the suspect spans table if the feature is enabled', async function () {
  620. MockApiClient.addMockResponse({
  621. url: '/organizations/org-slug/events-spans-performance/',
  622. body: [],
  623. });
  624. const {organization, router, routerContext} = initializeData({
  625. features: ['performance-suspect-spans-view'],
  626. });
  627. render(<TestComponent location={router.location} />, {
  628. context: routerContext,
  629. organization,
  630. });
  631. expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
  632. });
  633. it('adds search condition on transaction status when clicking on status breakdown', async function () {
  634. const {organization, router, routerContext} = initializeData();
  635. render(<TestComponent location={router.location} />, {
  636. context: routerContext,
  637. organization,
  638. });
  639. await screen.findByTestId('status-ok');
  640. userEvent.click(screen.getByTestId('status-ok'));
  641. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  642. expect(browserHistory.push).toHaveBeenCalledWith(
  643. expect.objectContaining({
  644. query: expect.objectContaining({
  645. query: expect.stringContaining('transaction.status:ok'),
  646. }),
  647. })
  648. );
  649. });
  650. it('appends tag value to existing query when clicked', async function () {
  651. const {organization, router, routerContext} = initializeData();
  652. render(<TestComponent location={router.location} />, {
  653. context: routerContext,
  654. organization,
  655. });
  656. await screen.findByText('Tag Summary');
  657. userEvent.click(
  658. screen.getByLabelText('Add the dev segment tag to the search query')
  659. );
  660. userEvent.click(
  661. screen.getByLabelText('Add the bar segment tag to the search query')
  662. );
  663. expect(router.push).toHaveBeenCalledTimes(2);
  664. expect(router.push).toHaveBeenNthCalledWith(1, {
  665. query: {
  666. project: '2',
  667. query: 'tags[environment]:dev',
  668. transaction: '/performance',
  669. transactionCursor: '1:0:0',
  670. },
  671. });
  672. expect(router.push).toHaveBeenNthCalledWith(2, {
  673. query: {
  674. project: '2',
  675. query: 'foo:bar',
  676. transaction: '/performance',
  677. transactionCursor: '1:0:0',
  678. },
  679. });
  680. });
  681. });
  682. describe('with events', function () {
  683. it('renders basic UI elements', async function () {
  684. const {organization, router, routerContext} = initializeData({
  685. features: ['performance-frontend-use-events-endpoint'],
  686. });
  687. render(<TestComponent location={router.location} />, {
  688. context: routerContext,
  689. organization,
  690. });
  691. // It shows the header
  692. await screen.findByText('Transaction Summary');
  693. expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
  694. // It shows a chart
  695. expect(
  696. screen.getByRole('button', {name: 'Display Duration Breakdown'})
  697. ).toBeInTheDocument();
  698. // It shows a searchbar
  699. expect(screen.getByLabelText('Search events')).toBeInTheDocument();
  700. // It shows a table
  701. expect(screen.getByTestId('transactions-table')).toBeInTheDocument();
  702. // Ensure open in discover button exists.
  703. expect(screen.getByTestId('transaction-events-open')).toBeInTheDocument();
  704. // Ensure open issues button exists.
  705. expect(screen.getByRole('button', {name: 'Open in Issues'})).toBeInTheDocument();
  706. // Ensure transaction filter button exists
  707. expect(screen.getByText('Filter').closest('button')).toBeInTheDocument();
  708. // Ensure create alert from discover is hidden without metric alert
  709. expect(
  710. screen.queryByRole('button', {name: 'Create Alert'})
  711. ).not.toBeInTheDocument();
  712. // Ensure status breakdown exists
  713. expect(screen.getByText('Status Breakdown')).toBeInTheDocument();
  714. });
  715. it('renders feature flagged UI elements', function () {
  716. const {organization, router, routerContext} = initializeData({
  717. features: ['incidents', 'performance-frontend-use-events-endpoint'],
  718. });
  719. render(<TestComponent location={router.location} />, {
  720. context: routerContext,
  721. organization,
  722. });
  723. // Ensure create alert from discover is shown with metric alerts
  724. expect(screen.getByRole('button', {name: 'Create Alert'})).toBeInTheDocument();
  725. });
  726. it('renders Web Vitals widget', async function () {
  727. const {organization, router, routerContext} = initializeData({
  728. features: ['performance-frontend-use-events-endpoint'],
  729. project: TestStubs.Project({teams, platform: 'javascript'}),
  730. query: {
  731. query:
  732. 'transaction.duration:<15m transaction.op:pageload event.type:transaction transaction:/organizations/:orgId/issues/',
  733. },
  734. });
  735. render(<TestComponent location={router.location} />, {
  736. context: routerContext,
  737. organization,
  738. });
  739. // It renders the web vitals widget
  740. await screen.findByRole('heading', {name: 'Web Vitals'});
  741. const vitalStatues = screen.getAllByTestId('vital-status');
  742. expect(vitalStatues).toHaveLength(3);
  743. expect(vitalStatues[0]).toHaveTextContent('31%');
  744. expect(vitalStatues[1]).toHaveTextContent('65%');
  745. expect(vitalStatues[2]).toHaveTextContent('3%');
  746. });
  747. it('renders sidebar widgets', async function () {
  748. const {organization, router, routerContext} = initializeData({
  749. features: ['performance-frontend-use-events-endpoint'],
  750. });
  751. render(<TestComponent location={router.location} />, {
  752. context: routerContext,
  753. organization,
  754. });
  755. // Renders Apdex widget
  756. await screen.findByRole('heading', {name: 'Apdex'});
  757. expect(await screen.findByTestId('apdex-summary-value')).toHaveTextContent('0.6');
  758. // Renders Failure Rate widget
  759. expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
  760. expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
  761. // Renders TPM widget
  762. expect(screen.getByRole('heading', {name: 'TPM'})).toBeInTheDocument();
  763. expect(screen.getByTestId('tpm-summary-value')).toHaveTextContent('1 tpm');
  764. });
  765. it('fetches transaction threshold', function () {
  766. const {organization, router, routerContext} = initializeData({
  767. features: ['performance-frontend-use-events-endpoint'],
  768. });
  769. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  770. url: '/organizations/org-slug/project-transaction-threshold-override/',
  771. method: 'GET',
  772. body: {
  773. threshold: '800',
  774. metric: 'lcp',
  775. },
  776. });
  777. const getProjectThresholdMock = MockApiClient.addMockResponse({
  778. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  779. method: 'GET',
  780. body: {
  781. threshold: '200',
  782. metric: 'duration',
  783. },
  784. });
  785. render(<TestComponent location={router.location} />, {
  786. context: routerContext,
  787. organization,
  788. });
  789. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  790. expect(getProjectThresholdMock).not.toHaveBeenCalled();
  791. });
  792. it('fetches project transaction threshdold', async function () {
  793. const {organization, router, routerContext} = initializeData({
  794. features: ['performance-frontend-use-events-endpoint'],
  795. });
  796. const getTransactionThresholdMock = MockApiClient.addMockResponse({
  797. url: '/organizations/org-slug/project-transaction-threshold-override/',
  798. method: 'GET',
  799. statusCode: 404,
  800. });
  801. const getProjectThresholdMock = MockApiClient.addMockResponse({
  802. url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
  803. method: 'GET',
  804. body: {
  805. threshold: '200',
  806. metric: 'duration',
  807. },
  808. });
  809. render(<TestComponent location={router.location} />, {
  810. context: routerContext,
  811. organization,
  812. });
  813. await screen.findByText('Transaction Summary');
  814. expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
  815. expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
  816. });
  817. it('triggers a navigation on search', function () {
  818. const {organization, router, routerContext} = initializeData({
  819. features: ['performance-frontend-use-events-endpoint'],
  820. });
  821. render(<TestComponent location={router.location} />, {
  822. context: routerContext,
  823. organization,
  824. });
  825. // Fill out the search box, and submit it.
  826. userEvent.type(screen.getByLabelText('Search events'), 'user.email:uhoh*{enter}');
  827. // Check the navigation.
  828. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  829. expect(browserHistory.push).toHaveBeenCalledWith({
  830. pathname: undefined,
  831. query: {
  832. transaction: '/performance',
  833. project: '2',
  834. statsPeriod: '14d',
  835. query: 'user.email:uhoh*',
  836. transactionCursor: '1:0:0',
  837. },
  838. });
  839. });
  840. it('can mark a transaction as key', async function () {
  841. const {organization, router, routerContext} = initializeData({
  842. features: ['performance-frontend-use-events-endpoint'],
  843. });
  844. render(<TestComponent location={router.location} />, {
  845. context: routerContext,
  846. organization,
  847. });
  848. const mockUpdate = MockApiClient.addMockResponse({
  849. url: `/organizations/org-slug/key-transactions/`,
  850. method: 'POST',
  851. body: {},
  852. });
  853. await screen.findByRole('button', {name: 'Star for Team'});
  854. // Click the key transaction button
  855. userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
  856. userEvent.click(screen.getByText('team1'), undefined, {
  857. skipPointerEventsCheck: true,
  858. });
  859. // Ensure request was made.
  860. expect(mockUpdate).toHaveBeenCalled();
  861. });
  862. it('triggers a navigation on transaction filter', async function () {
  863. const {organization, router, routerContext} = initializeData({
  864. features: ['performance-frontend-use-events-endpoint'],
  865. });
  866. render(<TestComponent location={router.location} />, {
  867. context: routerContext,
  868. organization,
  869. });
  870. await screen.findByText('Transaction Summary');
  871. // Open the transaction filter dropdown
  872. userEvent.click(
  873. screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
  874. );
  875. userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
  876. // Check the navigation.
  877. expect(browserHistory.push).toHaveBeenCalledWith({
  878. pathname: undefined,
  879. query: {
  880. transaction: '/performance',
  881. project: '2',
  882. showTransactions: 'slow',
  883. transactionCursor: undefined,
  884. },
  885. });
  886. });
  887. it('renders pagination buttons', async function () {
  888. const {organization, router, routerContext} = initializeData({
  889. features: ['performance-frontend-use-events-endpoint'],
  890. });
  891. render(<TestComponent location={router.location} />, {
  892. context: routerContext,
  893. organization,
  894. });
  895. await screen.findByText('Transaction Summary');
  896. expect(await screen.findByLabelText('Previous')).toBeInTheDocument();
  897. // Click the 'next' button
  898. userEvent.click(screen.getByLabelText('Next'));
  899. // Check the navigation.
  900. expect(browserHistory.push).toHaveBeenCalledWith({
  901. pathname: undefined,
  902. query: {
  903. transaction: '/performance',
  904. project: '2',
  905. transactionCursor: '2:0:0',
  906. },
  907. });
  908. });
  909. it('forwards conditions to related issues', async function () {
  910. const issueGet = MockApiClient.addMockResponse({
  911. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  912. body: [],
  913. });
  914. const {organization, router, routerContext} = initializeData({
  915. features: ['performance-frontend-use-events-endpoint'],
  916. query: {query: 'tag:value'},
  917. });
  918. render(<TestComponent location={router.location} />, {
  919. context: routerContext,
  920. organization,
  921. });
  922. await screen.findByText('Transaction Summary');
  923. expect(issueGet).toHaveBeenCalled();
  924. });
  925. it('does not forward event type to related issues', async function () {
  926. const issueGet = MockApiClient.addMockResponse({
  927. url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
  928. body: [],
  929. match: [
  930. (_, options) => {
  931. // event.type must NOT be in the query params
  932. return !options.query?.query?.includes('event.type');
  933. },
  934. ],
  935. });
  936. const {organization, router, routerContext} = initializeData({
  937. features: ['performance-frontend-use-events-endpoint'],
  938. query: {query: 'tag:value event.type:transaction'},
  939. });
  940. render(<TestComponent location={router.location} />, {
  941. context: routerContext,
  942. organization,
  943. });
  944. await screen.findByText('Transaction Summary');
  945. expect(issueGet).toHaveBeenCalled();
  946. });
  947. it('renders the suspect spans table if the feature is enabled', async function () {
  948. MockApiClient.addMockResponse({
  949. url: '/organizations/org-slug/events-spans-performance/',
  950. body: [],
  951. });
  952. const {organization, router, routerContext} = initializeData({
  953. features: [
  954. 'performance-suspect-spans-view',
  955. 'performance-frontend-use-events-endpoint',
  956. ],
  957. });
  958. render(<TestComponent location={router.location} />, {
  959. context: routerContext,
  960. organization,
  961. });
  962. expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
  963. });
  964. it('adds search condition on transaction status when clicking on status breakdown', async function () {
  965. const {organization, router, routerContext} = initializeData({
  966. features: ['performance-frontend-use-events-endpoint'],
  967. });
  968. render(<TestComponent location={router.location} />, {
  969. context: routerContext,
  970. organization,
  971. });
  972. await screen.findByTestId('status-ok');
  973. userEvent.click(screen.getByTestId('status-ok'));
  974. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  975. expect(browserHistory.push).toHaveBeenCalledWith(
  976. expect.objectContaining({
  977. query: expect.objectContaining({
  978. query: expect.stringContaining('transaction.status:ok'),
  979. }),
  980. })
  981. );
  982. });
  983. it('appends tag value to existing query when clicked', async function () {
  984. const {organization, router, routerContext} = initializeData({
  985. features: ['performance-frontend-use-events-endpoint'],
  986. });
  987. render(<TestComponent location={router.location} />, {
  988. context: routerContext,
  989. organization,
  990. });
  991. await screen.findByText('Tag Summary');
  992. userEvent.click(
  993. screen.getByLabelText('Add the dev segment tag to the search query')
  994. );
  995. userEvent.click(
  996. screen.getByLabelText('Add the bar segment tag to the search query')
  997. );
  998. expect(router.push).toHaveBeenCalledTimes(2);
  999. expect(router.push).toHaveBeenNthCalledWith(1, {
  1000. query: {
  1001. project: '2',
  1002. query: 'tags[environment]:dev',
  1003. transaction: '/performance',
  1004. transactionCursor: '1:0:0',
  1005. },
  1006. });
  1007. expect(router.push).toHaveBeenNthCalledWith(2, {
  1008. query: {
  1009. project: '2',
  1010. query: 'foo:bar',
  1011. transaction: '/performance',
  1012. transactionCursor: '1:0:0',
  1013. },
  1014. });
  1015. });
  1016. });
  1017. });