trace.spec.tsx 42 KB

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