trace.spec.tsx 42 KB

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