trace.spec.tsx 42 KB

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