trace.spec.tsx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. import * as Sentry from '@sentry/react';
  2. import MockDate from 'mockdate';
  3. import {DetailedEventsFixture} from 'sentry-fixture/events';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {
  7. act,
  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. return;
  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 ?? {body: DetailedEventsFixture()[0]}),
  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 ?? {body: DetailedEventsFixture()[0]}),
  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&averageColumn=span.duration`,
  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. childTransactions: [],
  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({body: DetailedEventsFixture()[0]});
  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. // We are having replay errors about invalid stylesheets, though the CSS seems valid
  426. jest.spyOn(console, 'error').mockImplementation(() => {});
  427. Object.defineProperty(window, 'location', {
  428. value: {
  429. search: '',
  430. },
  431. });
  432. MockDate.reset();
  433. });
  434. afterEach(() => {
  435. // @ts-expect-error clear mock
  436. globalThis.ResizeObserver = undefined;
  437. // @ts-expect-error override it
  438. window.location = new URL('http://localhost/');
  439. });
  440. it('renders loading state', async () => {
  441. mockTraceResponse();
  442. mockTraceMetaResponse();
  443. mockTraceTagsResponse();
  444. render(<TraceViewWithProviders traceSlug="trace-id" />);
  445. expect(await screen.findByText(/assembling the trace/i)).toBeInTheDocument();
  446. });
  447. it('renders error state', async () => {
  448. mockTraceResponse({statusCode: 404});
  449. mockTraceMetaResponse({statusCode: 404});
  450. mockTraceTagsResponse({statusCode: 404});
  451. render(<TraceViewWithProviders traceSlug="trace-id" />);
  452. expect(await screen.findByText(/we failed to load your trace/i)).toBeInTheDocument();
  453. });
  454. it('renders empty state', async () => {
  455. mockTraceResponse({
  456. body: {
  457. transactions: [],
  458. orphan_errors: [],
  459. },
  460. });
  461. mockTraceMetaResponse();
  462. mockTraceTagsResponse();
  463. render(<TraceViewWithProviders traceSlug="trace-id" />);
  464. expect(
  465. await screen.findByText(/trace does not contain any data/i)
  466. ).toBeInTheDocument();
  467. });
  468. describe('pageload', () => {
  469. it('highlights row at load and sets it as focused', async () => {
  470. Object.defineProperty(window, 'location', {
  471. value: {
  472. search: '?node=txn-5',
  473. },
  474. });
  475. const {virtualizedContainer} = await pageloadTestSetup();
  476. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  477. 'transaction-op-5'
  478. );
  479. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  480. expect(rows[6]).toHaveFocus();
  481. });
  482. it('scrolls at transaction span', async () => {
  483. Object.defineProperty(window, 'location', {
  484. value: {
  485. search: '?node=span-5&node=txn-5',
  486. },
  487. });
  488. mockSpansResponse(
  489. '5',
  490. {},
  491. {
  492. entries: [
  493. {
  494. type: EntryType.SPANS,
  495. data: [makeSpan({span_id: '5', op: 'special-span'})],
  496. },
  497. ],
  498. }
  499. );
  500. const {virtualizedContainer} = await pageloadTestSetup();
  501. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  502. 'special-span'
  503. );
  504. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  505. expect(rows[7]).toHaveFocus();
  506. });
  507. it('scrolls far down the list of transactions', async () => {
  508. Object.defineProperty(window, 'location', {
  509. value: {
  510. search: '?node=txn-500',
  511. },
  512. });
  513. await pageloadTestSetup();
  514. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  515. 'transaction-op-500'
  516. );
  517. await act(async () => {
  518. await wait(1000);
  519. });
  520. await waitFor(() => {
  521. expect(document.activeElement).toHaveClass('TraceRow');
  522. expect(
  523. document.activeElement?.textContent?.includes('transaction-op-500')
  524. ).toBeTruthy();
  525. });
  526. });
  527. it('scrolls to event id query param and fetches its spans', async () => {
  528. Object.defineProperty(window, 'location', {
  529. value: {
  530. search: '?eventId=500',
  531. },
  532. });
  533. const spanRequest = mockSpansResponse(
  534. '500',
  535. {},
  536. {
  537. entries: [
  538. {
  539. type: EntryType.SPANS,
  540. data: [makeSpan({span_id: '1', op: 'special-span'})],
  541. },
  542. ],
  543. }
  544. );
  545. await pageloadTestSetup();
  546. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  547. 'transaction-op-500'
  548. );
  549. await waitFor(() => {
  550. expect(document.activeElement).toHaveClass('TraceRow');
  551. expect(
  552. document.activeElement?.textContent?.includes('transaction-op-500')
  553. ).toBeTruthy();
  554. });
  555. expect(spanRequest).toHaveBeenCalledTimes(1);
  556. expect(await screen.findByText('special-span')).toBeInTheDocument();
  557. });
  558. it('logs if path is not found', async () => {
  559. Object.defineProperty(window, 'location', {
  560. value: {
  561. search: '?eventId=bad_value',
  562. },
  563. });
  564. const sentrySpy = jest.spyOn(Sentry, 'captureMessage');
  565. await pageloadTestSetup();
  566. await waitFor(() => {
  567. expect(sentrySpy).toHaveBeenCalledWith(
  568. 'Failed to find and scroll to node in tree'
  569. );
  570. });
  571. });
  572. it('triggers search on load', async () => {
  573. Object.defineProperty(window, 'location', {
  574. value: {
  575. search: '?search=transaction-op-5',
  576. },
  577. });
  578. await pageloadTestSetup();
  579. const searchInput = await screen.findByPlaceholderText('Search in trace');
  580. expect(searchInput).toHaveValue('transaction-op-5');
  581. await waitFor(() => {
  582. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  583. '1/1'
  584. );
  585. });
  586. });
  587. it('triggers search on load but does not steal focus from node param', async () => {
  588. Object.defineProperty(window, 'location', {
  589. value: {
  590. search: '?search=transaction-op-9999&node=txn-0',
  591. },
  592. });
  593. const {container} = await pageloadTestSetup();
  594. const searchInput = await screen.findByPlaceholderText('Search in trace');
  595. expect(searchInput).toHaveValue('transaction-op-9999');
  596. await waitFor(() => {
  597. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  598. '-/1'
  599. );
  600. });
  601. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  602. expect(rows[1]).toHaveFocus();
  603. });
  604. it('if search on load does not match anything, it does not steal focus or highlight first result', async () => {
  605. Object.defineProperty(window, 'location', {
  606. value: {
  607. search: '?search=dead&node=txn-5',
  608. },
  609. });
  610. const {container} = await pageloadTestSetup();
  611. const searchInput = await screen.findByPlaceholderText('Search in trace');
  612. expect(searchInput).toHaveValue('dead');
  613. await waitFor(() => {
  614. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  615. 'no results'
  616. );
  617. });
  618. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  619. expect(rows[6]).toHaveFocus();
  620. });
  621. });
  622. describe('keyboard navigation', () => {
  623. it('arrow down', async () => {
  624. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  625. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  626. await userEvent.click(rows[0]);
  627. await waitFor(() => expect(rows[0]).toHaveFocus());
  628. await userEvent.keyboard('{arrowdown}');
  629. await waitFor(() => expect(rows[1]).toHaveFocus());
  630. });
  631. it('arrow up', async () => {
  632. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  633. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  634. await userEvent.click(rows[1]);
  635. await waitFor(() => expect(rows[1]).toHaveFocus());
  636. await userEvent.keyboard('{arrowup}');
  637. await waitFor(() => expect(rows[0]).toHaveFocus());
  638. });
  639. // biome-ignore lint/suspicious/noSkippedTests: Flaky test
  640. it.skip('arrow right expands row and fetches data', async () => {
  641. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  642. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  643. mockSpansResponse(
  644. '0',
  645. {},
  646. {
  647. entries: [
  648. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  649. ],
  650. }
  651. );
  652. await userEvent.click(rows[1]);
  653. await waitFor(() => expect(rows[1]).toHaveFocus());
  654. await userEvent.keyboard('{arrowright}');
  655. expect(await screen.findByText('special-span')).toBeInTheDocument();
  656. });
  657. it('arrow left collapses row', async () => {
  658. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  659. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  660. mockSpansResponse(
  661. '0',
  662. {},
  663. {
  664. entries: [
  665. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  666. ],
  667. }
  668. );
  669. await userEvent.click(rows[1]);
  670. await waitFor(() => expect(rows[1]).toHaveFocus());
  671. await userEvent.keyboard('{arrowright}');
  672. expect(await screen.findByText('special-span')).toBeInTheDocument();
  673. await userEvent.keyboard('{arrowleft}');
  674. expect(screen.queryByText('special-span')).not.toBeInTheDocument();
  675. });
  676. it('roving updates the element in the drawer', async () => {
  677. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  678. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  679. mockSpansResponse(
  680. '0',
  681. {},
  682. {
  683. entries: [
  684. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  685. ],
  686. }
  687. );
  688. await userEvent.click(rows[1]);
  689. await waitFor(() => expect(rows[1]).toHaveFocus());
  690. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  691. 'transaction-op-0'
  692. );
  693. await userEvent.keyboard('{arrowright}');
  694. expect(await screen.findByText('special-span')).toBeInTheDocument();
  695. await userEvent.keyboard('{arrowdown}');
  696. await waitFor(() => expect(rows[2]).toHaveFocus());
  697. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  698. 'special-span'
  699. );
  700. });
  701. it('arrowup on first node jumps to start', async () => {
  702. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  703. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  704. await userEvent.click(rows[0]);
  705. await waitFor(() => expect(rows[0]).toHaveFocus());
  706. await userEvent.keyboard('{arrowup}');
  707. expect(
  708. await findByText(virtualizedContainer, /transaction-op-9999/i)
  709. ).toBeInTheDocument();
  710. await waitFor(() => {
  711. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  712. expect(rows[rows.length - 1]).toHaveFocus();
  713. });
  714. });
  715. it('arrowdown on last node jumps to start', async () => {
  716. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  717. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  718. await userEvent.click(rows[0]);
  719. await waitFor(() => expect(rows[0]).toHaveFocus());
  720. await userEvent.keyboard('{arrowup}');
  721. expect(
  722. await findByText(virtualizedContainer, /transaction-op-9999/i)
  723. ).toBeInTheDocument();
  724. await waitFor(() => {
  725. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  726. expect(rows[rows.length - 1]).toHaveFocus();
  727. });
  728. await userEvent.keyboard('{arrowdown}');
  729. expect(
  730. await findByText(virtualizedContainer, /transaction-op-0/i)
  731. ).toBeInTheDocument();
  732. await waitFor(() => {
  733. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  734. expect(rows[0]).toHaveFocus();
  735. });
  736. });
  737. it('tab scrolls to next node', async () => {
  738. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  739. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  740. await userEvent.click(rows[0]);
  741. await waitFor(() => expect(rows[0]).toHaveFocus());
  742. await userEvent.keyboard('{tab}');
  743. await waitFor(() => {
  744. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  745. expect(rows[1]).toHaveFocus();
  746. });
  747. });
  748. it('shift+tab scrolls to previous node', async () => {
  749. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  750. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  751. await userEvent.click(rows[1]);
  752. await waitFor(() => expect(rows[1]).toHaveFocus());
  753. await userEvent.keyboard('{Shift>}{tab}{/Shift}');
  754. await waitFor(() => {
  755. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  756. expect(rows[0]).toHaveFocus();
  757. });
  758. });
  759. it('arrowdown+shift scrolls to the end of the list', async () => {
  760. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  761. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  762. await userEvent.click(rows[0]);
  763. await waitFor(() => expect(rows[0]).toHaveFocus());
  764. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  765. expect(
  766. await findByText(virtualizedContainer, /transaction-op-9999/i)
  767. ).toBeInTheDocument();
  768. await waitFor(() => {
  769. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  770. expect(rows[rows.length - 1]).toHaveFocus();
  771. });
  772. });
  773. it('arrowup+shift scrolls to the start of the list', async () => {
  774. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  775. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  776. await userEvent.click(rows[0]);
  777. await waitFor(() => expect(rows[0]).toHaveFocus());
  778. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  779. expect(
  780. await findByText(virtualizedContainer, /transaction-op-9999/i)
  781. ).toBeInTheDocument();
  782. await waitFor(() => {
  783. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  784. expect(rows[rows.length - 1]).toHaveFocus();
  785. });
  786. await userEvent.keyboard('{Shift>}{arrowup}{/Shift}');
  787. expect(
  788. await findByText(virtualizedContainer, /transaction-op-0/i)
  789. ).toBeInTheDocument();
  790. await scrollToEnd();
  791. await waitFor(() => {
  792. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  793. expect(rows[0]).toHaveFocus();
  794. });
  795. });
  796. });
  797. describe('search', () => {
  798. it('searches in transaction', async () => {
  799. const {container} = await searchTestSetup();
  800. let rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  801. const searchInput = await screen.findByPlaceholderText('Search in trace');
  802. await userEvent.click(searchInput);
  803. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  804. await waitFor(() => {
  805. const highlighted_row = container.querySelector(
  806. '.TraceRow:not(.Hidden).SearchResult.Highlight'
  807. );
  808. rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  809. expect(rows.indexOf(highlighted_row!)).toBe(1);
  810. });
  811. });
  812. it('supports roving with arrowup and arrowdown', async () => {
  813. const {container} = await searchTestSetup();
  814. const searchInput = await screen.findByPlaceholderText('Search in trace');
  815. await userEvent.click(searchInput);
  816. // Fire change because userEvent triggers this letter by letter
  817. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  818. // Wait for the search results to resolve
  819. await searchToUpdate();
  820. for (const action of [
  821. // starting at the top, jumpt bottom with shift+arrowdown
  822. ['{Shift>}{arrowdown}{/Shift}', 9],
  823. // // move to row above with arrowup
  824. ['{arrowup}', 8],
  825. // // and jump back to top with shift+arrowup
  826. ['{Shift>}{arrowup}{/Shift}', 1],
  827. // // // and jump to next row with arrowdown
  828. ['{arrowdown}', 2],
  829. ] as const) {
  830. await userEvent.keyboard(action[0] as string);
  831. // assert that focus on search input is never lost
  832. expect(searchInput).toHaveFocus();
  833. await waitFor(() => {
  834. // Only a single row is highlighted, the rest are search results
  835. assertHighlightedRowAtIndex(container, action[1]);
  836. });
  837. }
  838. });
  839. // @TODO I am torn on this because left-right
  840. // should probably also move the input cursor...
  841. // it.todo("supports expanding with arrowright")
  842. // it.todo("supports collapsing with arrowleft")
  843. it('search roving updates the element in the drawer', async () => {
  844. await searchTestSetup();
  845. const searchInput = await screen.findByPlaceholderText('Search in trace');
  846. await userEvent.click(searchInput);
  847. // Fire change because userEvent triggers this letter by letter
  848. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  849. // Wait for the search results to resolve
  850. await searchToUpdate();
  851. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  852. 'transaction-op-0'
  853. );
  854. // assert that focus on search input is never lost
  855. expect(searchInput).toHaveFocus();
  856. await userEvent.keyboard('{arrowdown}');
  857. await waitFor(() => {
  858. expect(screen.getByTestId('trace-drawer-title')).toHaveTextContent(
  859. 'transaction-op-1'
  860. );
  861. });
  862. });
  863. it('highlighted node narrows down on the first result', async () => {
  864. const {container} = await searchTestSetup();
  865. const searchInput = await screen.findByPlaceholderText('Search in trace');
  866. await userEvent.click(searchInput);
  867. // Fire change because userEvent triggers this letter by letter
  868. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  869. // Wait for the search results to resolve
  870. await searchToUpdate();
  871. assertHighlightedRowAtIndex(container, 2);
  872. fireEvent.change(searchInput, {target: {value: 'transaction-op-10'}});
  873. await searchToUpdate();
  874. await waitFor(() => {
  875. assertHighlightedRowAtIndex(container, 9);
  876. });
  877. });
  878. it('highlighted is persisted on node while it is part of the search results', async () => {
  879. const {container} = await searchTestSetup();
  880. const searchInput = await screen.findByPlaceholderText('Search in trace');
  881. await userEvent.click(searchInput);
  882. // Fire change because userEvent triggers this letter by letter
  883. fireEvent.change(searchInput, {target: {value: 'trans'}});
  884. // Wait for the search results to resolve
  885. await searchToUpdate();
  886. await userEvent.keyboard('{arrowdown}');
  887. await searchToUpdate();
  888. assertHighlightedRowAtIndex(container, 2);
  889. fireEvent.change(searchInput, {target: {value: 'transa'}});
  890. await searchToUpdate();
  891. // Highlighting is persisted on the row
  892. assertHighlightedRowAtIndex(container, 2);
  893. fireEvent.change(searchInput, {target: {value: 'this wont match anything'}});
  894. await searchToUpdate();
  895. // When there is no match, the highlighting is removed
  896. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  897. });
  898. it('auto highlights the first result when search begins', async () => {
  899. const {container} = await searchTestSetup();
  900. const searchInput = await screen.findByPlaceholderText('Search in trace');
  901. await userEvent.click(searchInput);
  902. // Nothing is highlighted
  903. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  904. // Fire change because userEvent triggers this letter by letter
  905. fireEvent.change(searchInput, {target: {value: 't'}});
  906. // Wait for the search results to resolve
  907. await searchToUpdate();
  908. assertHighlightedRowAtIndex(container, 1);
  909. });
  910. it('clicking a row that is also a search result updates the result index', async () => {
  911. const {container} = await searchTestSetup();
  912. const searchInput = await screen.findByPlaceholderText('Search in trace');
  913. await userEvent.click(searchInput);
  914. // Fire change because userEvent triggers this letter by letter
  915. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  916. await searchToUpdate();
  917. assertHighlightedRowAtIndex(container, 2);
  918. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  919. // By default, we highlight the first result
  920. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  921. '1/2'
  922. );
  923. await scrollToEnd();
  924. // Click on a random row in the list that is not a search result
  925. await userEvent.click(rows[5]);
  926. await waitFor(() => {
  927. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  928. '-/2'
  929. );
  930. });
  931. await scrollToEnd();
  932. // Click on a the row in the list that is a search result
  933. await userEvent.click(rows[2]);
  934. await waitFor(() => {
  935. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  936. '1/2'
  937. );
  938. });
  939. });
  940. it('during search, expanding a row retriggers search', async () => {
  941. mockTraceMetaResponse();
  942. mockTraceRootFacets();
  943. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  944. mockTraceEventDetails();
  945. mockTraceResponse({
  946. body: {
  947. transactions: [
  948. makeTransaction({
  949. span_id: '0',
  950. event_id: '0',
  951. transaction: 'transaction-name-0',
  952. 'transaction.op': 'transaction-op-0',
  953. }),
  954. ],
  955. orphan_errors: [],
  956. },
  957. });
  958. mockSpansResponse(
  959. '0',
  960. {},
  961. {
  962. entries: [
  963. {
  964. type: EntryType.SPANS,
  965. data: [
  966. makeSpan({span_id: '0', description: 'span-description', op: 'op-0'}),
  967. ],
  968. },
  969. ],
  970. }
  971. );
  972. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  973. // Awaits for the placeholder rendering rows to be removed
  974. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  975. const searchInput = await screen.findByPlaceholderText('Search in trace');
  976. await userEvent.click(searchInput);
  977. // Fire change because userEvent triggers this letter by letter
  978. fireEvent.change(searchInput, {target: {value: 'op-0'}});
  979. await searchToUpdate();
  980. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  981. '1/1'
  982. );
  983. const highlighted_row = value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
  984. await userEvent.click(await screen.findByRole('button', {name: '+'}));
  985. expect(await screen.findByText('span-description')).toBeInTheDocument();
  986. await searchToUpdate();
  987. // The search is retriggered, but highlighting of current row is preserved
  988. expect(value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW)).toBe(
  989. highlighted_row
  990. );
  991. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  992. '1/2'
  993. );
  994. });
  995. it('during search, highlighting is persisted on the row', async () => {
  996. const {container} = await searchTestSetup();
  997. const searchInput = await screen.findByPlaceholderText('Search in trace');
  998. await userEvent.click(searchInput);
  999. // Fire change because userEvent triggers this letter by letter
  1000. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  1001. await searchToUpdate();
  1002. assertHighlightedRowAtIndex(container, 1);
  1003. await searchToUpdate();
  1004. // User moves down the list using keyboard navigation
  1005. for (const _ of [1, 2, 3, 4, 5]) {
  1006. const initial = screen.getByTestId('trace-search-result-iterator').textContent;
  1007. await userEvent.keyboard('{arrowDown}');
  1008. await waitFor(() => {
  1009. expect(screen.getByTestId('trace-search-result-iterator')).not.toBe(initial);
  1010. });
  1011. }
  1012. // User clicks on an entry in the list, then proceeds to search
  1013. await waitFor(() => {
  1014. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  1015. '6/11'
  1016. );
  1017. });
  1018. // And then continues the query - the highlighting is preserved as long as the
  1019. // rwo is part of the search results
  1020. assertHighlightedRowAtIndex(container, 6);
  1021. fireEvent.change(searchInput, {target: {value: 'transaction-op-'}});
  1022. await searchToUpdate();
  1023. assertHighlightedRowAtIndex(container, 6);
  1024. fireEvent.change(searchInput, {target: {value: 'transaction-op-5'}});
  1025. await searchToUpdate();
  1026. assertHighlightedRowAtIndex(container, 6);
  1027. fireEvent.change(searchInput, {target: {value: 'transaction-op-none'}});
  1028. await searchToUpdate();
  1029. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  1030. });
  1031. });
  1032. describe('tabbing', () => {
  1033. beforeEach(() => {
  1034. jest.spyOn(console, 'error').mockImplementation();
  1035. });
  1036. afterEach(() => {
  1037. jest.restoreAllMocks();
  1038. });
  1039. it('clicking on a node spawns a new tab when none is selected', async () => {
  1040. const {virtualizedContainer} = await simpleTestSetup();
  1041. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1042. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1043. await userEvent.click(rows[5]);
  1044. await waitFor(() => {
  1045. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1046. });
  1047. });
  1048. it('clicking on a node replaces the previously selected tab', async () => {
  1049. const {virtualizedContainer} = await simpleTestSetup();
  1050. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1051. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1052. await userEvent.click(rows[5]);
  1053. await waitFor(() => {
  1054. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1055. expect(
  1056. screen
  1057. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1058. .textContent?.includes('transaction-op-4')
  1059. ).toBeTruthy();
  1060. });
  1061. await userEvent.click(rows[7]);
  1062. await waitFor(() => {
  1063. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1064. expect(
  1065. screen
  1066. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1067. .textContent?.includes('transaction-op-6')
  1068. ).toBeTruthy();
  1069. });
  1070. });
  1071. it('pinning a tab and clicking on a new node spawns a new tab', async () => {
  1072. const {virtualizedContainer} = await simpleTestSetup();
  1073. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1074. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1075. await userEvent.click(rows[5]);
  1076. await waitFor(() => {
  1077. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1078. });
  1079. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1080. await userEvent.click(rows[7]);
  1081. await waitFor(() => {
  1082. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1083. expect(
  1084. screen
  1085. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1086. .textContent?.includes('transaction-op-4')
  1087. ).toBeTruthy();
  1088. expect(
  1089. screen
  1090. .queryAllByTestId(DRAWER_TABS_TEST_ID)[2]
  1091. .textContent?.includes('transaction-op-6')
  1092. ).toBeTruthy();
  1093. });
  1094. });
  1095. it('unpinning a tab removes it', async () => {
  1096. const {virtualizedContainer} = await simpleTestSetup();
  1097. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1098. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1099. await userEvent.click(rows[5]);
  1100. await waitFor(() => {
  1101. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1102. });
  1103. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1104. await userEvent.click(rows[7]);
  1105. await waitFor(() => {
  1106. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1107. });
  1108. const tabButtons = screen.queryAllByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID);
  1109. expect(tabButtons).toHaveLength(2);
  1110. await userEvent.click(tabButtons[0]);
  1111. await waitFor(() => {
  1112. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1113. });
  1114. });
  1115. it('clicking a node that is already open in a tab switches to that tab and persists the previous node', async () => {
  1116. const {virtualizedContainer} = await simpleTestSetup();
  1117. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1118. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1119. await userEvent.click(rows[5]);
  1120. await waitFor(() => {
  1121. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1122. });
  1123. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1124. await userEvent.click(rows[7]);
  1125. await waitFor(() => {
  1126. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1127. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[2]).toHaveAttribute(
  1128. 'aria-selected',
  1129. 'true'
  1130. );
  1131. });
  1132. await userEvent.click(rows[5]);
  1133. await waitFor(() => {
  1134. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[1]).toHaveAttribute(
  1135. 'aria-selected',
  1136. 'true'
  1137. );
  1138. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1139. });
  1140. });
  1141. });
  1142. });