trace.spec.tsx 42 KB

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