trace.spec.tsx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. import {act} from 'react-dom/test-utils';
  2. import * as Sentry from '@sentry/react';
  3. import MockDate from 'mockdate';
  4. import {DetailedEventsFixture} from 'sentry-fixture/events';
  5. import {ProjectFixture} from 'sentry-fixture/project';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {
  8. findByText,
  9. fireEvent,
  10. render,
  11. screen,
  12. userEvent,
  13. waitFor,
  14. } from 'sentry-test/reactTestingLibrary';
  15. import type {RawSpanType} from 'sentry/components/events/interfaces/spans/types';
  16. import {EntryType, type Event, type EventTransaction} from 'sentry/types';
  17. import type {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  18. import {TraceView} from 'sentry/views/performance/newTraceDetails/index';
  19. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  20. import {RouteContext} from 'sentry/views/routeContext';
  21. jest.mock('screenfull', () => ({
  22. enabled: true,
  23. get isFullscreen() {
  24. return false;
  25. },
  26. request: jest.fn(),
  27. exit: jest.fn(),
  28. on: jest.fn(),
  29. off: jest.fn(),
  30. }));
  31. class MockResizeObserver {
  32. callback: ResizeObserverCallback;
  33. constructor(callback: ResizeObserverCallback) {
  34. this.callback = callback;
  35. }
  36. unobserve(_element: HTMLElement) {
  37. throw new Error('not implemented');
  38. }
  39. observe(element: HTMLElement) {
  40. // Executes in sync so we dont have to
  41. this.callback(
  42. [
  43. {
  44. target: element,
  45. // @ts-expect-error partial mock
  46. contentRect: {width: 1000, height: 24 * 10 - 1},
  47. },
  48. ],
  49. this
  50. );
  51. }
  52. disconnect() {}
  53. }
  54. function TraceViewWithProviders({traceSlug}: {traceSlug: string}) {
  55. const {router} = initializeOrg({
  56. project: ProjectFixture(),
  57. });
  58. return (
  59. <RouteContext.Provider
  60. value={{
  61. router,
  62. location: router.location,
  63. params: {...router.params, traceSlug},
  64. routes: router.routes,
  65. }}
  66. >
  67. <TraceView />
  68. </RouteContext.Provider>
  69. );
  70. }
  71. type Arguments<F extends Function> = F extends (...args: infer A) => any ? A : never;
  72. type ResponseType = Arguments<typeof MockApiClient.addMockResponse>[0];
  73. function mockTraceResponse(resp?: Partial<ResponseType>) {
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/events-trace/trace-id/',
  76. method: 'GET',
  77. asyncDelay: 1,
  78. ...(resp ?? {}),
  79. });
  80. }
  81. function mockTraceMetaResponse(resp?: Partial<ResponseType>) {
  82. MockApiClient.addMockResponse({
  83. url: '/organizations/org-slug/events-trace-meta/trace-id/',
  84. method: 'GET',
  85. asyncDelay: 1,
  86. ...(resp ?? {}),
  87. });
  88. }
  89. function mockTraceTagsResponse(resp?: Partial<ResponseType>) {
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/events-facets/',
  92. method: 'GET',
  93. asyncDelay: 1,
  94. ...(resp ?? {}),
  95. });
  96. }
  97. // function _mockTraceDetailsResponse(id: string, resp?: Partial<ResponseType>) {
  98. // MockApiClient.addMockResponse({
  99. // url: `/organizations/org-slug/events/project_slug:transaction-${id}`,
  100. // method: 'GET',
  101. // asyncDelay: 1,
  102. // ...(resp ?? {}),
  103. // });
  104. // }
  105. function mockTransactionDetailsResponse(id: string, resp?: Partial<ResponseType>) {
  106. MockApiClient.addMockResponse({
  107. url: `/organizations/org-slug/events/project_slug:${id}/`,
  108. method: 'GET',
  109. asyncDelay: 1,
  110. ...(resp ?? {}),
  111. });
  112. }
  113. function mockTraceRootEvent(id: string, resp?: Partial<ResponseType>) {
  114. MockApiClient.addMockResponse({
  115. url: `/organizations/org-slug/events/project_slug:${id}/`,
  116. method: 'GET',
  117. asyncDelay: 1,
  118. ...(resp ?? {}),
  119. });
  120. }
  121. function mockTraceRootFacets(resp?: Partial<ResponseType>) {
  122. MockApiClient.addMockResponse({
  123. url: `/organizations/org-slug/events-facets/`,
  124. method: 'GET',
  125. asyncDelay: 1,
  126. body: {},
  127. ...(resp ?? {}),
  128. });
  129. }
  130. function mockTraceEventDetails(resp?: Partial<ResponseType>) {
  131. MockApiClient.addMockResponse({
  132. url: `/organizations/org-slug/events/`,
  133. method: 'GET',
  134. asyncDelay: 1,
  135. body: {},
  136. ...(resp ?? {}),
  137. });
  138. }
  139. function mockSpansResponse(
  140. id: string,
  141. resp?: Partial<ResponseType>,
  142. body: Partial<EventTransaction> = {}
  143. ) {
  144. return MockApiClient.addMockResponse({
  145. url: `/organizations/org-slug/events/project_slug:${id}/?averageColumn=span.self_time`,
  146. method: 'GET',
  147. asyncDelay: 1,
  148. body,
  149. ...(resp ?? {}),
  150. });
  151. }
  152. let sid = -1;
  153. let tid = -1;
  154. const span_id = () => `${++sid}`;
  155. const txn_id = () => `${++tid}`;
  156. function makeTransaction(overrides: Partial<TraceFullDetailed> = {}): TraceFullDetailed {
  157. const t = txn_id();
  158. const s = span_id();
  159. return {
  160. children: [],
  161. event_id: t,
  162. parent_event_id: 'parent_event_id',
  163. parent_span_id: 'parent_span_id',
  164. start_timestamp: 0,
  165. timestamp: 1,
  166. generation: 0,
  167. span_id: s,
  168. 'transaction.duration': 1,
  169. transaction: 'transaction-name' + t,
  170. 'transaction.op': 'transaction-op-' + t,
  171. 'transaction.status': '',
  172. project_id: 0,
  173. project_slug: 'project_slug',
  174. errors: [],
  175. performance_issues: [],
  176. ...overrides,
  177. };
  178. }
  179. function makeEvent(overrides: Partial<Event> = {}, spans: RawSpanType[] = []): Event {
  180. return {
  181. entries: [{type: EntryType.SPANS, data: spans}],
  182. ...overrides,
  183. } as Event;
  184. }
  185. function makeSpan(overrides: Partial<RawSpanType> = {}): TraceTree.Span {
  186. return {
  187. span_id: '',
  188. op: '',
  189. description: '',
  190. start_timestamp: 0,
  191. timestamp: 10,
  192. data: {},
  193. trace_id: '',
  194. childTransaction: undefined,
  195. event: makeEvent() as EventTransaction,
  196. ...overrides,
  197. };
  198. }
  199. async function keyboardNavigationTestSetup() {
  200. const keyboard_navigation_transactions: TraceFullDetailed[] = [];
  201. for (let i = 0; i < 1e4; i++) {
  202. keyboard_navigation_transactions.push(
  203. makeTransaction({
  204. span_id: i + '',
  205. event_id: i + '',
  206. transaction: 'transaction-name' + i,
  207. 'transaction.op': 'transaction-op-' + i,
  208. })
  209. );
  210. mockTransactionDetailsResponse(i.toString());
  211. }
  212. mockTraceResponse({
  213. body: {
  214. transactions: keyboard_navigation_transactions,
  215. orphan_errors: [],
  216. },
  217. });
  218. mockTraceMetaResponse();
  219. mockTraceRootFacets();
  220. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  221. mockTraceEventDetails();
  222. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  223. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  224. const virtualizedScrollContainer = screen.queryByTestId(
  225. 'trace-virtualized-list-scroll-container'
  226. );
  227. if (!virtualizedContainer) {
  228. throw new Error('Virtualized container not found');
  229. }
  230. if (!virtualizedScrollContainer) {
  231. throw new Error('Virtualized scroll container not found');
  232. }
  233. // Awaits for the placeholder rendering rows to be removed
  234. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  235. return {...value, virtualizedContainer, virtualizedScrollContainer};
  236. }
  237. async function pageloadTestSetup() {
  238. const keyboard_navigation_transactions: TraceFullDetailed[] = [];
  239. for (let i = 0; i < 1e4; i++) {
  240. keyboard_navigation_transactions.push(
  241. makeTransaction({
  242. span_id: i + '',
  243. event_id: i + '',
  244. transaction: 'transaction-name' + i,
  245. 'transaction.op': 'transaction-op-' + i,
  246. })
  247. );
  248. mockTransactionDetailsResponse(i.toString());
  249. }
  250. mockTraceResponse({
  251. body: {
  252. transactions: keyboard_navigation_transactions,
  253. orphan_errors: [],
  254. },
  255. });
  256. mockTraceMetaResponse();
  257. mockTraceRootFacets();
  258. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  259. mockTraceEventDetails();
  260. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  261. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  262. const virtualizedScrollContainer = screen.queryByTestId(
  263. 'trace-virtualized-list-scroll-container'
  264. );
  265. if (!virtualizedContainer) {
  266. throw new Error('Virtualized container not found');
  267. }
  268. if (!virtualizedScrollContainer) {
  269. throw new Error('Virtualized scroll container not found');
  270. }
  271. // Awaits for the placeholder rendering rows to be removed
  272. expect((await screen.findAllByText(/transaction-op-/i)).length).toBeGreaterThan(0);
  273. return {...value, virtualizedContainer, virtualizedScrollContainer};
  274. }
  275. async function searchTestSetup() {
  276. const transactions: TraceFullDetailed[] = [];
  277. for (let i = 0; i < 11; i++) {
  278. transactions.push(
  279. makeTransaction({
  280. span_id: i + '',
  281. event_id: i + '',
  282. transaction: 'transaction-name' + i,
  283. 'transaction.op': 'transaction-op-' + i,
  284. })
  285. );
  286. mockTransactionDetailsResponse(i.toString());
  287. }
  288. mockTraceResponse({
  289. body: {
  290. transactions: transactions,
  291. orphan_errors: [],
  292. },
  293. });
  294. mockTraceMetaResponse();
  295. mockTraceRootFacets();
  296. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  297. mockTraceEventDetails();
  298. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  299. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  300. const virtualizedScrollContainer = screen.queryByTestId(
  301. 'trace-virtualized-list-scroll-container'
  302. );
  303. if (!virtualizedContainer) {
  304. throw new Error('Virtualized container not found');
  305. }
  306. if (!virtualizedScrollContainer) {
  307. throw new Error('Virtualized scroll container not found');
  308. }
  309. // Awaits for the placeholder rendering rows to be removed
  310. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  311. return {...value, virtualizedContainer, virtualizedScrollContainer};
  312. }
  313. async function simpleTestSetup() {
  314. const transactions: TraceFullDetailed[] = [];
  315. let parent: any;
  316. for (let i = 0; i < 1e3; i++) {
  317. const next = makeTransaction({
  318. span_id: i + '',
  319. event_id: i + '',
  320. transaction: 'transaction-name' + i,
  321. 'transaction.op': 'transaction-op-' + i,
  322. });
  323. if (parent) {
  324. parent.children.push(next);
  325. } else {
  326. transactions.push(next);
  327. }
  328. parent = next;
  329. mockTransactionDetailsResponse(i.toString());
  330. }
  331. mockTraceResponse({
  332. body: {
  333. transactions: transactions,
  334. orphan_errors: [],
  335. },
  336. });
  337. mockTraceMetaResponse();
  338. mockTraceRootFacets();
  339. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  340. mockTraceEventDetails();
  341. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  342. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  343. const virtualizedScrollContainer = screen.queryByTestId(
  344. 'trace-virtualized-list-scroll-container'
  345. );
  346. if (!virtualizedContainer) {
  347. throw new Error('Virtualized container not found');
  348. }
  349. if (!virtualizedScrollContainer) {
  350. throw new Error('Virtualized scroll container not found');
  351. }
  352. // Awaits for the placeholder rendering rows to be removed
  353. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  354. return {...value, virtualizedContainer, virtualizedScrollContainer};
  355. }
  356. const DRAWER_TABS_TEST_ID = 'trace-drawer-tab';
  357. const DRAWER_TABS_PIN_BUTTON_TEST_ID = 'trace-drawer-tab-pin-button';
  358. // @ts-expect-error ignore this line
  359. // eslint-disable-next-line
  360. const DRAWER_TABS_CONTAINER_TEST_ID = 'trace-drawer-tabs';
  361. const VISIBLE_TRACE_ROW_SELECTOR = '.TraceRow:not(.Hidden)';
  362. const ACTIVE_SEARCH_HIGHLIGHT_ROW = '.TraceRow.SearchResult.Highlight:not(.Hidden)';
  363. const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
  364. const searchToUpdate = (): Promise<void> => {
  365. return act(async () => {
  366. await wait(500);
  367. });
  368. };
  369. const scrollToEnd = (): Promise<void> => {
  370. return act(async () => {
  371. await wait(1000);
  372. });
  373. };
  374. // @ts-expect-error ignore this line
  375. // eslint-disable-next-line
  376. function printVirtualizedList(container: HTMLElement) {
  377. const stdout: string[] = [];
  378. const scrollContainer = screen.queryByTestId(
  379. 'trace-virtualized-list-scroll-container'
  380. )!;
  381. stdout.push(
  382. 'top:' + scrollContainer.scrollTop + ' ' + 'left:' + scrollContainer.scrollLeft
  383. );
  384. stdout.push('///////////////////');
  385. const rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  386. for (const r of [...rows]) {
  387. let t = r.textContent ?? '';
  388. if (r.classList.contains('SearchResult')) {
  389. t = 'search ' + t;
  390. }
  391. if (r.classList.contains('Highlight')) {
  392. t = 'highlight ' + t;
  393. }
  394. stdout.push(t);
  395. }
  396. // This is a debug fn, we need it to log
  397. // eslint-disable-next-line
  398. console.log(stdout.join('\n'));
  399. }
  400. // @ts-expect-error ignore this line
  401. // eslint-disable-next-line
  402. function printTabs() {
  403. const tabs = screen.queryAllByTestId(DRAWER_TABS_TEST_ID);
  404. const stdout: string[] = [];
  405. for (const tab of tabs) {
  406. let text = tab.textContent ?? 'empty tab??';
  407. if (tab.hasAttribute('aria-selected')) {
  408. text = 'active' + text;
  409. }
  410. stdout.push(text);
  411. }
  412. // This is a debug fn, we need it to log
  413. // eslint-disable-next-line
  414. console.log(stdout.join(' | '));
  415. }
  416. function assertHighlightedRowAtIndex(virtualizedContainer: HTMLElement, index: number) {
  417. expect(virtualizedContainer.querySelectorAll('.TraceRow.Highlight')).toHaveLength(1);
  418. const highlighted_row = virtualizedContainer.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
  419. const r = Array.from(virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  420. expect(r.indexOf(highlighted_row!)).toBe(index);
  421. }
  422. describe('trace view', () => {
  423. beforeEach(() => {
  424. globalThis.ResizeObserver = MockResizeObserver as any;
  425. Object.defineProperty(window, 'location', {
  426. value: {
  427. search: '',
  428. },
  429. });
  430. MockDate.reset();
  431. });
  432. afterEach(() => {
  433. // @ts-expect-error clear mock
  434. globalThis.ResizeObserver = undefined;
  435. // @ts-expect-error override it
  436. window.location = new URL('http://localhost/');
  437. });
  438. it('renders loading state', async () => {
  439. mockTraceResponse();
  440. mockTraceMetaResponse();
  441. mockTraceTagsResponse();
  442. render(<TraceViewWithProviders traceSlug="trace-id" />);
  443. expect(await screen.findByText(/assembling the trace/i)).toBeInTheDocument();
  444. });
  445. it('renders error state', async () => {
  446. mockTraceResponse({statusCode: 404});
  447. mockTraceMetaResponse({statusCode: 404});
  448. mockTraceTagsResponse({statusCode: 404});
  449. render(<TraceViewWithProviders traceSlug="trace-id" />);
  450. expect(await screen.findByText(/we failed to load your trace/i)).toBeInTheDocument();
  451. });
  452. it('renders empty state', async () => {
  453. mockTraceResponse({
  454. body: {
  455. transactions: [],
  456. orphan_errors: [],
  457. },
  458. });
  459. mockTraceMetaResponse();
  460. mockTraceTagsResponse({});
  461. render(<TraceViewWithProviders traceSlug="trace-id" />);
  462. expect(
  463. await screen.findByText(/trace does not contain any data/i)
  464. ).toBeInTheDocument();
  465. });
  466. describe('pageload', () => {
  467. it('highlights row at load and sets it as focused', async () => {
  468. Object.defineProperty(window, 'location', {
  469. value: {
  470. search: '?node=txn-5',
  471. },
  472. });
  473. const {virtualizedContainer} = await pageloadTestSetup();
  474. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  475. 'transaction-op-5'
  476. );
  477. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  478. expect(rows[6]).toHaveFocus();
  479. });
  480. it('scrolls at transaction span', async () => {
  481. Object.defineProperty(window, 'location', {
  482. value: {
  483. search: '?node=span-5&node=txn-5',
  484. },
  485. });
  486. mockSpansResponse(
  487. '5',
  488. {},
  489. {
  490. entries: [
  491. {
  492. type: EntryType.SPANS,
  493. data: [makeSpan({span_id: '5', op: 'special-span'})],
  494. },
  495. ],
  496. }
  497. );
  498. const {virtualizedContainer} = await pageloadTestSetup();
  499. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  500. 'special-span'
  501. );
  502. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  503. expect(rows[7]).toHaveFocus();
  504. });
  505. it('scrolls far down the list of transactions', async () => {
  506. Object.defineProperty(window, 'location', {
  507. value: {
  508. search: '?node=txn-500',
  509. },
  510. });
  511. await pageloadTestSetup();
  512. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  513. 'transaction-op-500'
  514. );
  515. await act(async () => {
  516. await wait(1000);
  517. });
  518. await waitFor(() => {
  519. expect(document.activeElement).toHaveClass('TraceRow');
  520. expect(
  521. document.activeElement?.textContent?.includes('transaction-op-500')
  522. ).toBeTruthy();
  523. });
  524. });
  525. it('scrolls to event id query param and fetches its spans', async () => {
  526. Object.defineProperty(window, 'location', {
  527. value: {
  528. search: '?eventId=500',
  529. },
  530. });
  531. const spanRequest = mockSpansResponse(
  532. '500',
  533. {},
  534. {
  535. entries: [
  536. {
  537. type: EntryType.SPANS,
  538. data: [makeSpan({span_id: '1', op: 'special-span'})],
  539. },
  540. ],
  541. }
  542. );
  543. await pageloadTestSetup();
  544. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  545. 'transaction-op-500'
  546. );
  547. await waitFor(() => {
  548. expect(document.activeElement).toHaveClass('TraceRow');
  549. expect(
  550. document.activeElement?.textContent?.includes('transaction-op-500')
  551. ).toBeTruthy();
  552. });
  553. expect(spanRequest).toHaveBeenCalledTimes(1);
  554. expect(await screen.findByText('special-span')).toBeInTheDocument();
  555. });
  556. it('logs if path is not found', async () => {
  557. Object.defineProperty(window, 'location', {
  558. value: {
  559. search: '?eventId=bad_value',
  560. },
  561. });
  562. const sentrySpy = jest.spyOn(Sentry, 'captureMessage');
  563. await pageloadTestSetup();
  564. await waitFor(() => {
  565. expect(sentrySpy).toHaveBeenCalledWith(
  566. 'Failed to find and scroll to node in tree'
  567. );
  568. });
  569. });
  570. it('triggers search on load', async () => {
  571. Object.defineProperty(window, 'location', {
  572. value: {
  573. search: '?search=transaction-op-5',
  574. },
  575. });
  576. await pageloadTestSetup();
  577. const searchInput = await screen.findByPlaceholderText('Search in trace');
  578. expect(searchInput).toHaveValue('transaction-op-5');
  579. await waitFor(() => {
  580. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  581. '1/1'
  582. );
  583. });
  584. });
  585. it('triggers search on load but does not steal focus from node param', async () => {
  586. Object.defineProperty(window, 'location', {
  587. value: {
  588. search: '?search=transaction-op-9999&node=txn-0',
  589. },
  590. });
  591. const {container} = await pageloadTestSetup();
  592. const searchInput = await screen.findByPlaceholderText('Search in trace');
  593. expect(searchInput).toHaveValue('transaction-op-9999');
  594. await waitFor(() => {
  595. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  596. '-/1'
  597. );
  598. });
  599. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  600. expect(rows[1]).toHaveFocus();
  601. });
  602. it('if search on load does not match anything, it does not steal focus or highlight first result', async () => {
  603. Object.defineProperty(window, 'location', {
  604. value: {
  605. search: '?search=dead&node=txn-5',
  606. },
  607. });
  608. const {container} = await pageloadTestSetup();
  609. const searchInput = await screen.findByPlaceholderText('Search in trace');
  610. expect(searchInput).toHaveValue('dead');
  611. await waitFor(() => {
  612. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  613. 'no results'
  614. );
  615. });
  616. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  617. expect(rows[6]).toHaveFocus();
  618. });
  619. });
  620. describe('keyboard navigation', () => {
  621. it('arrow down', async () => {
  622. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  623. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  624. await userEvent.click(rows[0]);
  625. await waitFor(() => expect(rows[0]).toHaveFocus());
  626. await userEvent.keyboard('{arrowdown}');
  627. await waitFor(() => expect(rows[1]).toHaveFocus());
  628. });
  629. it('arrow up', async () => {
  630. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  631. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  632. await userEvent.click(rows[1]);
  633. await waitFor(() => expect(rows[1]).toHaveFocus());
  634. await userEvent.keyboard('{arrowup}');
  635. await waitFor(() => expect(rows[0]).toHaveFocus());
  636. });
  637. it('arrow right expands row and fetches data', async () => {
  638. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  639. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  640. mockSpansResponse(
  641. '0',
  642. {},
  643. {
  644. entries: [
  645. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  646. ],
  647. }
  648. );
  649. await userEvent.click(rows[1]);
  650. await waitFor(() => expect(rows[1]).toHaveFocus());
  651. await userEvent.keyboard('{arrowright}');
  652. expect(await screen.findByText('special-span')).toBeInTheDocument();
  653. });
  654. it('arrow left collapses row', async () => {
  655. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  656. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  657. mockSpansResponse(
  658. '0',
  659. {},
  660. {
  661. entries: [
  662. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  663. ],
  664. }
  665. );
  666. await userEvent.click(rows[1]);
  667. await waitFor(() => expect(rows[1]).toHaveFocus());
  668. await userEvent.keyboard('{arrowright}');
  669. expect(await screen.findByText('special-span')).toBeInTheDocument();
  670. await userEvent.keyboard('{arrowleft}');
  671. expect(screen.queryByText('special-span')).not.toBeInTheDocument();
  672. });
  673. it('roving updates the element in the drawer', async () => {
  674. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  675. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  676. mockSpansResponse(
  677. '0',
  678. {},
  679. {
  680. entries: [
  681. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  682. ],
  683. }
  684. );
  685. await userEvent.click(rows[1]);
  686. await waitFor(() => expect(rows[1]).toHaveFocus());
  687. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  688. 'transaction-op-0'
  689. );
  690. await userEvent.keyboard('{arrowright}');
  691. expect(await screen.findByText('special-span')).toBeInTheDocument();
  692. await userEvent.keyboard('{arrowdown}');
  693. await waitFor(() => expect(rows[2]).toHaveFocus());
  694. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  695. 'special-span'
  696. );
  697. });
  698. it('arrowup on first node jumps to start', async () => {
  699. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  700. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  701. await userEvent.click(rows[0]);
  702. await waitFor(() => expect(rows[0]).toHaveFocus());
  703. await userEvent.keyboard('{arrowup}');
  704. expect(
  705. await findByText(virtualizedContainer, /transaction-op-9999/i)
  706. ).toBeInTheDocument();
  707. await waitFor(() => {
  708. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  709. expect(rows[rows.length - 1]).toHaveFocus();
  710. });
  711. });
  712. it('arrowdown on last node jumps to start', async () => {
  713. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  714. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  715. await userEvent.click(rows[0]);
  716. await waitFor(() => expect(rows[0]).toHaveFocus());
  717. await userEvent.keyboard('{arrowup}');
  718. expect(
  719. await findByText(virtualizedContainer, /transaction-op-9999/i)
  720. ).toBeInTheDocument();
  721. await waitFor(() => {
  722. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  723. expect(rows[rows.length - 1]).toHaveFocus();
  724. });
  725. await userEvent.keyboard('{arrowdown}');
  726. expect(
  727. await findByText(virtualizedContainer, /transaction-op-0/i)
  728. ).toBeInTheDocument();
  729. await waitFor(() => {
  730. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  731. expect(rows[0]).toHaveFocus();
  732. });
  733. });
  734. it('tab scrolls to next node', async () => {
  735. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  736. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  737. await userEvent.click(rows[0]);
  738. await waitFor(() => expect(rows[0]).toHaveFocus());
  739. await userEvent.keyboard('{tab}');
  740. await waitFor(() => {
  741. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  742. expect(rows[1]).toHaveFocus();
  743. });
  744. });
  745. it('shift+tab scrolls to previous node', async () => {
  746. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  747. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  748. await userEvent.click(rows[1]);
  749. await waitFor(() => expect(rows[1]).toHaveFocus());
  750. await userEvent.keyboard('{Shift>}{tab}{/Shift}');
  751. await waitFor(() => {
  752. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  753. expect(rows[0]).toHaveFocus();
  754. });
  755. });
  756. it('arrowdown+shift scrolls to the end of the list', async () => {
  757. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  758. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  759. await userEvent.click(rows[0]);
  760. await waitFor(() => expect(rows[0]).toHaveFocus());
  761. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  762. expect(
  763. await findByText(virtualizedContainer, /transaction-op-9999/i)
  764. ).toBeInTheDocument();
  765. await waitFor(() => {
  766. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  767. expect(rows[rows.length - 1]).toHaveFocus();
  768. });
  769. });
  770. it('arrowup+shift scrolls to the start of the list', async () => {
  771. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  772. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  773. await userEvent.click(rows[0]);
  774. await waitFor(() => expect(rows[0]).toHaveFocus());
  775. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  776. expect(
  777. await findByText(virtualizedContainer, /transaction-op-9999/i)
  778. ).toBeInTheDocument();
  779. await waitFor(() => {
  780. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  781. expect(rows[rows.length - 1]).toHaveFocus();
  782. });
  783. await userEvent.keyboard('{Shift>}{arrowup}{/Shift}');
  784. expect(
  785. await findByText(virtualizedContainer, /transaction-op-0/i)
  786. ).toBeInTheDocument();
  787. await scrollToEnd();
  788. await waitFor(() => {
  789. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  790. expect(rows[0]).toHaveFocus();
  791. });
  792. });
  793. });
  794. describe('search', () => {
  795. it('searches in transaction', async () => {
  796. const {container} = await searchTestSetup();
  797. let rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  798. const searchInput = await screen.findByPlaceholderText('Search in trace');
  799. await userEvent.click(searchInput);
  800. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  801. await waitFor(() => {
  802. const highlighted_row = container.querySelector(
  803. '.TraceRow:not(.Hidden).SearchResult.Highlight'
  804. );
  805. rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  806. expect(rows.indexOf(highlighted_row!)).toBe(1);
  807. });
  808. });
  809. it('supports roving with arrowup and arrowdown', async () => {
  810. const {container} = await searchTestSetup();
  811. const searchInput = await screen.findByPlaceholderText('Search in trace');
  812. await userEvent.click(searchInput);
  813. // Fire change because userEvent triggers this letter by letter
  814. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  815. // Wait for the search results to resolve
  816. await searchToUpdate();
  817. for (const action of [
  818. // starting at the top, jumpt bottom with shift+arrowdown
  819. ['{Shift>}{arrowdown}{/Shift}', 9],
  820. // // move to row above with arrowup
  821. ['{arrowup}', 8],
  822. // // and jump back to top with shift+arrowup
  823. ['{Shift>}{arrowup}{/Shift}', 1],
  824. // // // and jump to next row with arrowdown
  825. ['{arrowdown}', 2],
  826. ] as const) {
  827. await userEvent.keyboard(action[0] as string);
  828. // assert that focus on search input is never lost
  829. expect(searchInput).toHaveFocus();
  830. await waitFor(() => {
  831. // Only a single row is highlighted, the rest are search results
  832. assertHighlightedRowAtIndex(container, action[1]);
  833. });
  834. }
  835. });
  836. // @TODO I am torn on this because left-right
  837. // should probably also move the input cursor...
  838. // it.todo("supports expanding with arrowright")
  839. // it.todo("supports collapsing with arrowleft")
  840. it('search roving updates the element in the drawer', async () => {
  841. await searchTestSetup();
  842. const searchInput = await screen.findByPlaceholderText('Search in trace');
  843. await userEvent.click(searchInput);
  844. // Fire change because userEvent triggers this letter by letter
  845. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  846. // Wait for the search results to resolve
  847. await searchToUpdate();
  848. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  849. 'transaction-op-0'
  850. );
  851. // assert that focus on search input is never lost
  852. expect(searchInput).toHaveFocus();
  853. await userEvent.keyboard('{arrowdown}');
  854. await waitFor(() => {
  855. expect(screen.getByTestId('trace-drawer-title')).toHaveTextContent(
  856. 'transaction-op-1'
  857. );
  858. });
  859. });
  860. it('highlighted node narrows down on the first result', async () => {
  861. const {container} = await searchTestSetup();
  862. const searchInput = await screen.findByPlaceholderText('Search in trace');
  863. await userEvent.click(searchInput);
  864. // Fire change because userEvent triggers this letter by letter
  865. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  866. // Wait for the search results to resolve
  867. await searchToUpdate();
  868. assertHighlightedRowAtIndex(container, 2);
  869. fireEvent.change(searchInput, {target: {value: 'transaction-op-10'}});
  870. await searchToUpdate();
  871. await waitFor(() => {
  872. assertHighlightedRowAtIndex(container, 9);
  873. });
  874. });
  875. it('highlighted is persisted on node while it is part of the search results', async () => {
  876. const {container} = await searchTestSetup();
  877. const searchInput = await screen.findByPlaceholderText('Search in trace');
  878. await userEvent.click(searchInput);
  879. // Fire change because userEvent triggers this letter by letter
  880. fireEvent.change(searchInput, {target: {value: 'trans'}});
  881. // Wait for the search results to resolve
  882. await searchToUpdate();
  883. await userEvent.keyboard('{arrowdown}');
  884. await searchToUpdate();
  885. assertHighlightedRowAtIndex(container, 2);
  886. fireEvent.change(searchInput, {target: {value: 'transa'}});
  887. await searchToUpdate();
  888. // Highlighting is persisted on the row
  889. assertHighlightedRowAtIndex(container, 2);
  890. fireEvent.change(searchInput, {target: {value: 'this wont match anything'}});
  891. await searchToUpdate();
  892. // When there is no match, the highlighting is removed
  893. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  894. });
  895. it('auto highlights the first result when search begins', async () => {
  896. const {container} = await searchTestSetup();
  897. const searchInput = await screen.findByPlaceholderText('Search in trace');
  898. await userEvent.click(searchInput);
  899. // Nothing is highlighted
  900. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  901. // Fire change because userEvent triggers this letter by letter
  902. fireEvent.change(searchInput, {target: {value: 't'}});
  903. // Wait for the search results to resolve
  904. await searchToUpdate();
  905. assertHighlightedRowAtIndex(container, 1);
  906. });
  907. it('clicking a row that is also a search result updates the result index', async () => {
  908. const {container} = await searchTestSetup();
  909. const searchInput = await screen.findByPlaceholderText('Search in trace');
  910. await userEvent.click(searchInput);
  911. // Fire change because userEvent triggers this letter by letter
  912. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  913. await searchToUpdate();
  914. assertHighlightedRowAtIndex(container, 2);
  915. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  916. // By default, we highlight the first result
  917. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  918. '1/2'
  919. );
  920. await scrollToEnd();
  921. // Click on a random row in the list that is not a search result
  922. await userEvent.click(rows[5]);
  923. await waitFor(() => {
  924. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  925. '-/2'
  926. );
  927. });
  928. await scrollToEnd();
  929. // Click on a the row in the list that is a search result
  930. await userEvent.click(rows[2]);
  931. await waitFor(() => {
  932. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  933. '1/2'
  934. );
  935. });
  936. });
  937. it('during search, expanding a row retriggers search', async () => {
  938. mockTraceMetaResponse();
  939. mockTraceRootFacets();
  940. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  941. mockTraceEventDetails();
  942. mockTraceResponse({
  943. body: {
  944. transactions: [
  945. makeTransaction({
  946. span_id: '0',
  947. event_id: '0',
  948. transaction: 'transaction-name-0',
  949. 'transaction.op': 'transaction-op-0',
  950. }),
  951. ],
  952. orphan_errors: [],
  953. },
  954. });
  955. mockSpansResponse(
  956. '0',
  957. {},
  958. {
  959. entries: [
  960. {
  961. type: EntryType.SPANS,
  962. data: [
  963. makeSpan({span_id: '0', description: 'span-description', op: 'op-0'}),
  964. ],
  965. },
  966. ],
  967. }
  968. );
  969. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  970. // Awaits for the placeholder rendering rows to be removed
  971. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  972. const searchInput = await screen.findByPlaceholderText('Search in trace');
  973. await userEvent.click(searchInput);
  974. // Fire change because userEvent triggers this letter by letter
  975. fireEvent.change(searchInput, {target: {value: 'op-0'}});
  976. await searchToUpdate();
  977. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  978. '1/1'
  979. );
  980. const highlighted_row = value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
  981. await userEvent.click(await screen.findByRole('button', {name: '+'}));
  982. expect(await screen.findByText('span-description')).toBeInTheDocument();
  983. await searchToUpdate();
  984. // The search is retriggered, but highlighting of current row is preserved
  985. expect(value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW)).toBe(
  986. highlighted_row
  987. );
  988. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  989. '1/2'
  990. );
  991. });
  992. it('during search, highlighting is persisted on the row', async () => {
  993. const {container} = await searchTestSetup();
  994. const searchInput = await screen.findByPlaceholderText('Search in trace');
  995. await userEvent.click(searchInput);
  996. // Fire change because userEvent triggers this letter by letter
  997. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  998. await searchToUpdate();
  999. assertHighlightedRowAtIndex(container, 1);
  1000. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1001. await searchToUpdate();
  1002. // User moves down the list using keyboard navigation
  1003. while (container.querySelector('.TraceRow.Highlight') !== rows[6]) {
  1004. await userEvent.keyboard('{arrowDown}');
  1005. }
  1006. // User clicks on an entry in the list, then proceeds to search
  1007. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  1008. '6/11'
  1009. );
  1010. // And then continues the query - the highlighting is preserved as long as the
  1011. // rwo is part of the search results
  1012. assertHighlightedRowAtIndex(container, 6);
  1013. fireEvent.change(searchInput, {target: {value: 'transaction-op-'}});
  1014. await searchToUpdate();
  1015. assertHighlightedRowAtIndex(container, 6);
  1016. fireEvent.change(searchInput, {target: {value: 'transaction-op-5'}});
  1017. await searchToUpdate();
  1018. assertHighlightedRowAtIndex(container, 6);
  1019. fireEvent.change(searchInput, {target: {value: 'transaction-op-none'}});
  1020. await searchToUpdate();
  1021. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  1022. });
  1023. });
  1024. describe('tabbing', () => {
  1025. beforeEach(() => {
  1026. jest.spyOn(console, 'error').mockImplementation();
  1027. });
  1028. afterEach(() => {
  1029. jest.restoreAllMocks();
  1030. });
  1031. it('clicking on a node spawns a new tab when none is selected', async () => {
  1032. const {virtualizedContainer} = await simpleTestSetup();
  1033. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1034. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1035. await userEvent.click(rows[5]);
  1036. await waitFor(() => {
  1037. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1038. });
  1039. });
  1040. it('clicking on a node replaces the previously selected tab', async () => {
  1041. const {virtualizedContainer} = await simpleTestSetup();
  1042. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1043. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1044. await userEvent.click(rows[5]);
  1045. await waitFor(() => {
  1046. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1047. expect(
  1048. screen
  1049. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1050. .textContent?.includes('transaction-op-4')
  1051. ).toBeTruthy();
  1052. });
  1053. await userEvent.click(rows[7]);
  1054. await waitFor(() => {
  1055. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1056. expect(
  1057. screen
  1058. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1059. .textContent?.includes('transaction-op-6')
  1060. ).toBeTruthy();
  1061. });
  1062. });
  1063. it('pinning a tab and clicking on a new node spawns a new tab', async () => {
  1064. const {virtualizedContainer} = await simpleTestSetup();
  1065. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1066. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1067. await userEvent.click(rows[5]);
  1068. await waitFor(() => {
  1069. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1070. });
  1071. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1072. await userEvent.click(rows[7]);
  1073. await waitFor(() => {
  1074. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1075. expect(
  1076. screen
  1077. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1078. .textContent?.includes('transaction-op-4')
  1079. ).toBeTruthy();
  1080. expect(
  1081. screen
  1082. .queryAllByTestId(DRAWER_TABS_TEST_ID)[2]
  1083. .textContent?.includes('transaction-op-6')
  1084. ).toBeTruthy();
  1085. });
  1086. });
  1087. it('unpinning a tab removes it', async () => {
  1088. const {virtualizedContainer} = await simpleTestSetup();
  1089. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1090. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1091. await userEvent.click(rows[5]);
  1092. await waitFor(() => {
  1093. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1094. });
  1095. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1096. await userEvent.click(rows[7]);
  1097. await waitFor(() => {
  1098. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1099. });
  1100. await userEvent.click(
  1101. await screen.findAllByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID)[0]
  1102. );
  1103. await waitFor(() => {
  1104. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1105. });
  1106. });
  1107. it('clicking a node that is already open in a tab switches to that tab and persists the previous node', async () => {
  1108. const {virtualizedContainer} = await simpleTestSetup();
  1109. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1110. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1111. await userEvent.click(rows[5]);
  1112. await waitFor(() => {
  1113. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1114. });
  1115. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1116. await userEvent.click(rows[7]);
  1117. await waitFor(() => {
  1118. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1119. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[2]).toHaveAttribute(
  1120. 'aria-selected',
  1121. 'true'
  1122. );
  1123. });
  1124. await userEvent.click(rows[5]);
  1125. await waitFor(() => {
  1126. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[1]).toHaveAttribute(
  1127. 'aria-selected',
  1128. 'true'
  1129. );
  1130. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1131. });
  1132. });
  1133. });
  1134. });