trace.spec.tsx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. import * as Sentry from '@sentry/react';
  2. import MockDate from 'mockdate';
  3. import {DetailedEventsFixture} from 'sentry-fixture/events';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {
  7. act,
  8. findByText,
  9. fireEvent,
  10. render,
  11. screen,
  12. userEvent,
  13. waitFor,
  14. } from 'sentry-test/reactTestingLibrary';
  15. import type {RawSpanType} from 'sentry/components/events/interfaces/spans/types';
  16. import {EntryType, type Event, type EventTransaction} from 'sentry/types';
  17. import type {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  18. import {TraceView} from 'sentry/views/performance/newTraceDetails/index';
  19. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  20. import {RouteContext} from 'sentry/views/routeContext';
  21. jest.mock('screenfull', () => ({
  22. enabled: true,
  23. get isFullscreen() {
  24. return false;
  25. },
  26. request: jest.fn(),
  27. exit: jest.fn(),
  28. on: jest.fn(),
  29. off: jest.fn(),
  30. }));
  31. class MockResizeObserver {
  32. callback: ResizeObserverCallback;
  33. constructor(callback: ResizeObserverCallback) {
  34. this.callback = callback;
  35. }
  36. unobserve(_element: HTMLElement) {
  37. return;
  38. }
  39. observe(element: HTMLElement) {
  40. // Executes in sync so we dont have to
  41. this.callback(
  42. [
  43. {
  44. target: element,
  45. // @ts-expect-error partial mock
  46. contentRect: {width: 1000, height: 24 * 10 - 1},
  47. },
  48. ],
  49. this
  50. );
  51. }
  52. disconnect() {}
  53. }
  54. function TraceViewWithProviders({traceSlug}: {traceSlug: string}) {
  55. const {router} = initializeOrg({
  56. project: ProjectFixture(),
  57. });
  58. return (
  59. <RouteContext.Provider
  60. value={{
  61. router,
  62. location: router.location,
  63. params: {...router.params, traceSlug},
  64. routes: router.routes,
  65. }}
  66. >
  67. <TraceView />
  68. </RouteContext.Provider>
  69. );
  70. }
  71. type Arguments<F extends Function> = F extends (...args: infer A) => any ? A : never;
  72. type ResponseType = Arguments<typeof MockApiClient.addMockResponse>[0];
  73. function mockTraceResponse(resp?: Partial<ResponseType>) {
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/events-trace/trace-id/',
  76. method: 'GET',
  77. asyncDelay: 1,
  78. ...(resp ?? {}),
  79. });
  80. }
  81. function mockTraceMetaResponse(resp?: Partial<ResponseType>) {
  82. MockApiClient.addMockResponse({
  83. url: '/organizations/org-slug/events-trace-meta/trace-id/',
  84. method: 'GET',
  85. asyncDelay: 1,
  86. ...(resp ?? {}),
  87. });
  88. }
  89. function mockTraceTagsResponse(resp?: Partial<ResponseType>) {
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/events-facets/',
  92. method: 'GET',
  93. asyncDelay: 1,
  94. ...(resp ?? {}),
  95. });
  96. }
  97. // function _mockTraceDetailsResponse(id: string, resp?: Partial<ResponseType>) {
  98. // MockApiClient.addMockResponse({
  99. // url: `/organizations/org-slug/events/project_slug:transaction-${id}`,
  100. // method: 'GET',
  101. // asyncDelay: 1,
  102. // ...(resp ?? {}),
  103. // });
  104. // }
  105. function mockTransactionDetailsResponse(id: string, resp?: Partial<ResponseType>) {
  106. MockApiClient.addMockResponse({
  107. url: `/organizations/org-slug/events/project_slug:${id}/`,
  108. method: 'GET',
  109. asyncDelay: 1,
  110. ...(resp ?? {body: DetailedEventsFixture()[0]}),
  111. });
  112. }
  113. function mockTraceRootEvent(id: string, resp?: Partial<ResponseType>) {
  114. MockApiClient.addMockResponse({
  115. url: `/organizations/org-slug/events/project_slug:${id}/`,
  116. method: 'GET',
  117. asyncDelay: 1,
  118. ...(resp ?? {body: DetailedEventsFixture()[0]}),
  119. });
  120. }
  121. function mockTraceRootFacets(resp?: Partial<ResponseType>) {
  122. MockApiClient.addMockResponse({
  123. url: `/organizations/org-slug/events-facets/`,
  124. method: 'GET',
  125. asyncDelay: 1,
  126. body: {},
  127. ...(resp ?? {}),
  128. });
  129. }
  130. function mockTraceEventDetails(resp?: Partial<ResponseType>) {
  131. MockApiClient.addMockResponse({
  132. url: `/organizations/org-slug/events/`,
  133. method: 'GET',
  134. asyncDelay: 1,
  135. body: {},
  136. ...(resp ?? {}),
  137. });
  138. }
  139. function mockSpansResponse(
  140. id: string,
  141. resp?: Partial<ResponseType>,
  142. body: Partial<EventTransaction> = {}
  143. ) {
  144. return MockApiClient.addMockResponse({
  145. url: `/organizations/org-slug/events/project_slug:${id}/?averageColumn=span.self_time&averageColumn=span.duration`,
  146. method: 'GET',
  147. asyncDelay: 1,
  148. body,
  149. ...(resp ?? {}),
  150. });
  151. }
  152. let sid = -1;
  153. let tid = -1;
  154. const span_id = () => `${++sid}`;
  155. const txn_id = () => `${++tid}`;
  156. function makeTransaction(overrides: Partial<TraceFullDetailed> = {}): TraceFullDetailed {
  157. const t = txn_id();
  158. const s = span_id();
  159. return {
  160. children: [],
  161. event_id: t,
  162. parent_event_id: 'parent_event_id',
  163. parent_span_id: 'parent_span_id',
  164. start_timestamp: 0,
  165. timestamp: 1,
  166. generation: 0,
  167. span_id: s,
  168. 'transaction.duration': 1,
  169. transaction: 'transaction-name' + t,
  170. 'transaction.op': 'transaction-op-' + t,
  171. 'transaction.status': '',
  172. project_id: 0,
  173. project_slug: 'project_slug',
  174. errors: [],
  175. performance_issues: [],
  176. ...overrides,
  177. };
  178. }
  179. function makeEvent(overrides: Partial<Event> = {}, spans: RawSpanType[] = []): Event {
  180. return {
  181. entries: [{type: EntryType.SPANS, data: spans}],
  182. ...overrides,
  183. } as Event;
  184. }
  185. function makeSpan(overrides: Partial<RawSpanType> = {}): TraceTree.Span {
  186. return {
  187. span_id: '',
  188. op: '',
  189. description: '',
  190. start_timestamp: 0,
  191. timestamp: 10,
  192. data: {},
  193. trace_id: '',
  194. childTransactions: [],
  195. event: makeEvent() as EventTransaction,
  196. ...overrides,
  197. };
  198. }
  199. async function keyboardNavigationTestSetup() {
  200. const keyboard_navigation_transactions: TraceFullDetailed[] = [];
  201. for (let i = 0; i < 1e4; i++) {
  202. keyboard_navigation_transactions.push(
  203. makeTransaction({
  204. span_id: i + '',
  205. event_id: i + '',
  206. transaction: 'transaction-name' + i,
  207. 'transaction.op': 'transaction-op-' + i,
  208. })
  209. );
  210. mockTransactionDetailsResponse(i.toString());
  211. }
  212. mockTraceResponse({
  213. body: {
  214. transactions: keyboard_navigation_transactions,
  215. orphan_errors: [],
  216. },
  217. });
  218. mockTraceMetaResponse();
  219. mockTraceRootFacets();
  220. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  221. mockTraceEventDetails();
  222. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  223. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  224. const virtualizedScrollContainer = screen.queryByTestId(
  225. 'trace-virtualized-list-scroll-container'
  226. );
  227. if (!virtualizedContainer) {
  228. throw new Error('Virtualized container not found');
  229. }
  230. if (!virtualizedScrollContainer) {
  231. throw new Error('Virtualized scroll container not found');
  232. }
  233. // Awaits for the placeholder rendering rows to be removed
  234. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  235. return {...value, virtualizedContainer, virtualizedScrollContainer};
  236. }
  237. async function pageloadTestSetup() {
  238. const keyboard_navigation_transactions: TraceFullDetailed[] = [];
  239. for (let i = 0; i < 1e4; i++) {
  240. keyboard_navigation_transactions.push(
  241. makeTransaction({
  242. span_id: i + '',
  243. event_id: i + '',
  244. transaction: 'transaction-name' + i,
  245. 'transaction.op': 'transaction-op-' + i,
  246. })
  247. );
  248. mockTransactionDetailsResponse(i.toString());
  249. }
  250. mockTraceResponse({
  251. body: {
  252. transactions: keyboard_navigation_transactions,
  253. orphan_errors: [],
  254. },
  255. });
  256. mockTraceMetaResponse();
  257. mockTraceRootFacets();
  258. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  259. mockTraceEventDetails();
  260. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  261. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  262. const virtualizedScrollContainer = screen.queryByTestId(
  263. 'trace-virtualized-list-scroll-container'
  264. );
  265. if (!virtualizedContainer) {
  266. throw new Error('Virtualized container not found');
  267. }
  268. if (!virtualizedScrollContainer) {
  269. throw new Error('Virtualized scroll container not found');
  270. }
  271. // Awaits for the placeholder rendering rows to be removed
  272. expect((await screen.findAllByText(/transaction-op-/i)).length).toBeGreaterThan(0);
  273. return {...value, virtualizedContainer, virtualizedScrollContainer};
  274. }
  275. async function searchTestSetup() {
  276. const transactions: TraceFullDetailed[] = [];
  277. for (let i = 0; i < 11; i++) {
  278. transactions.push(
  279. makeTransaction({
  280. span_id: i + '',
  281. event_id: i + '',
  282. transaction: 'transaction-name' + i,
  283. 'transaction.op': 'transaction-op-' + i,
  284. })
  285. );
  286. mockTransactionDetailsResponse(i.toString());
  287. }
  288. mockTraceResponse({
  289. body: {
  290. transactions: transactions,
  291. orphan_errors: [],
  292. },
  293. });
  294. mockTraceMetaResponse();
  295. mockTraceRootFacets();
  296. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  297. mockTraceEventDetails({body: DetailedEventsFixture()[0]});
  298. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  299. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  300. const virtualizedScrollContainer = screen.queryByTestId(
  301. 'trace-virtualized-list-scroll-container'
  302. );
  303. if (!virtualizedContainer) {
  304. throw new Error('Virtualized container not found');
  305. }
  306. if (!virtualizedScrollContainer) {
  307. throw new Error('Virtualized scroll container not found');
  308. }
  309. // Awaits for the placeholder rendering rows to be removed
  310. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  311. return {...value, virtualizedContainer, virtualizedScrollContainer};
  312. }
  313. async function simpleTestSetup() {
  314. const transactions: TraceFullDetailed[] = [];
  315. let parent: any;
  316. for (let i = 0; i < 1e3; i++) {
  317. const next = makeTransaction({
  318. span_id: i + '',
  319. event_id: i + '',
  320. transaction: 'transaction-name' + i,
  321. 'transaction.op': 'transaction-op-' + i,
  322. });
  323. if (parent) {
  324. parent.children.push(next);
  325. } else {
  326. transactions.push(next);
  327. }
  328. parent = next;
  329. mockTransactionDetailsResponse(i.toString());
  330. }
  331. mockTraceResponse({
  332. body: {
  333. transactions: transactions,
  334. orphan_errors: [],
  335. },
  336. });
  337. mockTraceMetaResponse();
  338. mockTraceRootFacets();
  339. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  340. mockTraceEventDetails();
  341. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  342. const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
  343. const virtualizedScrollContainer = screen.queryByTestId(
  344. 'trace-virtualized-list-scroll-container'
  345. );
  346. if (!virtualizedContainer) {
  347. throw new Error('Virtualized container not found');
  348. }
  349. if (!virtualizedScrollContainer) {
  350. throw new Error('Virtualized scroll container not found');
  351. }
  352. // Awaits for the placeholder rendering rows to be removed
  353. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  354. return {...value, virtualizedContainer, virtualizedScrollContainer};
  355. }
  356. const DRAWER_TABS_TEST_ID = 'trace-drawer-tab';
  357. const DRAWER_TABS_PIN_BUTTON_TEST_ID = 'trace-drawer-tab-pin-button';
  358. // @ts-expect-error ignore this line
  359. // eslint-disable-next-line
  360. const DRAWER_TABS_CONTAINER_TEST_ID = 'trace-drawer-tabs';
  361. const VISIBLE_TRACE_ROW_SELECTOR = '.TraceRow:not(.Hidden)';
  362. const ACTIVE_SEARCH_HIGHLIGHT_ROW = '.TraceRow.SearchResult.Highlight:not(.Hidden)';
  363. const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
  364. const searchToUpdate = (): Promise<void> => {
  365. return act(async () => {
  366. await wait(500);
  367. });
  368. };
  369. const scrollToEnd = (): Promise<void> => {
  370. return act(async () => {
  371. await wait(1000);
  372. });
  373. };
  374. // @ts-expect-error ignore this line
  375. // eslint-disable-next-line
  376. function printVirtualizedList(container: HTMLElement) {
  377. const stdout: string[] = [];
  378. const scrollContainer = screen.queryByTestId(
  379. 'trace-virtualized-list-scroll-container'
  380. )!;
  381. stdout.push(
  382. 'top:' + scrollContainer.scrollTop + ' ' + 'left:' + scrollContainer.scrollLeft
  383. );
  384. stdout.push('///////////////////');
  385. const rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  386. for (const r of [...rows]) {
  387. let t = r.textContent ?? '';
  388. if (r.classList.contains('SearchResult')) {
  389. t = 'search ' + t;
  390. }
  391. if (r.classList.contains('Highlight')) {
  392. t = 'highlight ' + t;
  393. }
  394. stdout.push(t);
  395. }
  396. // This is a debug fn, we need it to log
  397. // eslint-disable-next-line
  398. console.log(stdout.join('\n'));
  399. }
  400. // @ts-expect-error ignore this line
  401. // eslint-disable-next-line
  402. function printTabs() {
  403. const tabs = screen.queryAllByTestId(DRAWER_TABS_TEST_ID);
  404. const stdout: string[] = [];
  405. for (const tab of tabs) {
  406. let text = tab.textContent ?? 'empty tab??';
  407. if (tab.hasAttribute('aria-selected')) {
  408. text = 'active' + text;
  409. }
  410. stdout.push(text);
  411. }
  412. // This is a debug fn, we need it to log
  413. // eslint-disable-next-line
  414. console.log(stdout.join(' | '));
  415. }
  416. function assertHighlightedRowAtIndex(virtualizedContainer: HTMLElement, index: number) {
  417. expect(virtualizedContainer.querySelectorAll('.TraceRow.Highlight')).toHaveLength(1);
  418. const highlighted_row = virtualizedContainer.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
  419. const r = Array.from(virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  420. expect(r.indexOf(highlighted_row!)).toBe(index);
  421. }
  422. describe('trace view', () => {
  423. beforeEach(() => {
  424. globalThis.ResizeObserver = MockResizeObserver as any;
  425. // We are having replay errors about invalid stylesheets, though the CSS seems valid
  426. jest.spyOn(console, 'error').mockImplementation(() => {});
  427. Object.defineProperty(window, 'location', {
  428. value: {
  429. search: '',
  430. },
  431. });
  432. MockDate.reset();
  433. });
  434. afterEach(() => {
  435. // @ts-expect-error clear mock
  436. globalThis.ResizeObserver = undefined;
  437. // @ts-expect-error override it
  438. window.location = new URL('http://localhost/');
  439. });
  440. it('renders loading state', async () => {
  441. mockTraceResponse();
  442. mockTraceMetaResponse();
  443. mockTraceTagsResponse();
  444. render(<TraceViewWithProviders traceSlug="trace-id" />);
  445. expect(await screen.findByText(/assembling the trace/i)).toBeInTheDocument();
  446. });
  447. it('renders error state', async () => {
  448. mockTraceResponse({statusCode: 404});
  449. mockTraceMetaResponse({statusCode: 404});
  450. mockTraceTagsResponse({statusCode: 404});
  451. render(<TraceViewWithProviders traceSlug="trace-id" />);
  452. expect(await screen.findByText(/we failed to load your trace/i)).toBeInTheDocument();
  453. });
  454. it('renders empty state', async () => {
  455. mockTraceResponse({
  456. body: {
  457. transactions: [],
  458. orphan_errors: [],
  459. },
  460. });
  461. mockTraceMetaResponse();
  462. mockTraceTagsResponse({});
  463. render(<TraceViewWithProviders traceSlug="trace-id" />);
  464. expect(
  465. await screen.findByText(/trace does not contain any data/i)
  466. ).toBeInTheDocument();
  467. });
  468. describe('pageload', () => {
  469. it('highlights row at load and sets it as focused', async () => {
  470. Object.defineProperty(window, 'location', {
  471. value: {
  472. search: '?node=txn-5',
  473. },
  474. });
  475. const {virtualizedContainer} = await pageloadTestSetup();
  476. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  477. 'transaction-op-5'
  478. );
  479. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  480. expect(rows[6]).toHaveFocus();
  481. });
  482. it('scrolls at transaction span', async () => {
  483. Object.defineProperty(window, 'location', {
  484. value: {
  485. search: '?node=span-5&node=txn-5',
  486. },
  487. });
  488. mockSpansResponse(
  489. '5',
  490. {},
  491. {
  492. entries: [
  493. {
  494. type: EntryType.SPANS,
  495. data: [makeSpan({span_id: '5', op: 'special-span'})],
  496. },
  497. ],
  498. }
  499. );
  500. const {virtualizedContainer} = await pageloadTestSetup();
  501. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  502. 'special-span'
  503. );
  504. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  505. expect(rows[7]).toHaveFocus();
  506. });
  507. it('scrolls far down the list of transactions', async () => {
  508. Object.defineProperty(window, 'location', {
  509. value: {
  510. search: '?node=txn-500',
  511. },
  512. });
  513. await pageloadTestSetup();
  514. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  515. 'transaction-op-500'
  516. );
  517. await act(async () => {
  518. await wait(1000);
  519. });
  520. await waitFor(() => {
  521. expect(document.activeElement).toHaveClass('TraceRow');
  522. expect(
  523. document.activeElement?.textContent?.includes('transaction-op-500')
  524. ).toBeTruthy();
  525. });
  526. });
  527. it('scrolls to event id query param and fetches its spans', async () => {
  528. Object.defineProperty(window, 'location', {
  529. value: {
  530. search: '?eventId=500',
  531. },
  532. });
  533. const spanRequest = mockSpansResponse(
  534. '500',
  535. {},
  536. {
  537. entries: [
  538. {
  539. type: EntryType.SPANS,
  540. data: [makeSpan({span_id: '1', op: 'special-span'})],
  541. },
  542. ],
  543. }
  544. );
  545. await pageloadTestSetup();
  546. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  547. 'transaction-op-500'
  548. );
  549. await waitFor(() => {
  550. expect(document.activeElement).toHaveClass('TraceRow');
  551. expect(
  552. document.activeElement?.textContent?.includes('transaction-op-500')
  553. ).toBeTruthy();
  554. });
  555. expect(spanRequest).toHaveBeenCalledTimes(1);
  556. expect(await screen.findByText('special-span')).toBeInTheDocument();
  557. });
  558. it('logs if path is not found', async () => {
  559. Object.defineProperty(window, 'location', {
  560. value: {
  561. search: '?eventId=bad_value',
  562. },
  563. });
  564. const sentrySpy = jest.spyOn(Sentry, 'captureMessage');
  565. await pageloadTestSetup();
  566. await waitFor(() => {
  567. expect(sentrySpy).toHaveBeenCalledWith(
  568. 'Failed to find and scroll to node in tree'
  569. );
  570. });
  571. });
  572. it('triggers search on load', async () => {
  573. Object.defineProperty(window, 'location', {
  574. value: {
  575. search: '?search=transaction-op-5',
  576. },
  577. });
  578. await pageloadTestSetup();
  579. const searchInput = await screen.findByPlaceholderText('Search in trace');
  580. expect(searchInput).toHaveValue('transaction-op-5');
  581. await waitFor(() => {
  582. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  583. '1/1'
  584. );
  585. });
  586. });
  587. it('triggers search on load but does not steal focus from node param', async () => {
  588. Object.defineProperty(window, 'location', {
  589. value: {
  590. search: '?search=transaction-op-9999&node=txn-0',
  591. },
  592. });
  593. const {container} = await pageloadTestSetup();
  594. const searchInput = await screen.findByPlaceholderText('Search in trace');
  595. expect(searchInput).toHaveValue('transaction-op-9999');
  596. await waitFor(() => {
  597. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  598. '-/1'
  599. );
  600. });
  601. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  602. expect(rows[1]).toHaveFocus();
  603. });
  604. it('if search on load does not match anything, it does not steal focus or highlight first result', async () => {
  605. Object.defineProperty(window, 'location', {
  606. value: {
  607. search: '?search=dead&node=txn-5',
  608. },
  609. });
  610. const {container} = await pageloadTestSetup();
  611. const searchInput = await screen.findByPlaceholderText('Search in trace');
  612. expect(searchInput).toHaveValue('dead');
  613. await waitFor(() => {
  614. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  615. 'no results'
  616. );
  617. });
  618. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  619. expect(rows[6]).toHaveFocus();
  620. });
  621. });
  622. describe('keyboard navigation', () => {
  623. it('arrow down', async () => {
  624. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  625. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  626. await userEvent.click(rows[0]);
  627. await waitFor(() => expect(rows[0]).toHaveFocus());
  628. await userEvent.keyboard('{arrowdown}');
  629. await waitFor(() => expect(rows[1]).toHaveFocus());
  630. });
  631. it('arrow up', async () => {
  632. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  633. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  634. await userEvent.click(rows[1]);
  635. await waitFor(() => expect(rows[1]).toHaveFocus());
  636. await userEvent.keyboard('{arrowup}');
  637. await waitFor(() => expect(rows[0]).toHaveFocus());
  638. });
  639. 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. const tabButtons = screen.queryAllByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID);
  1108. expect(tabButtons).toHaveLength(2);
  1109. await userEvent.click(tabButtons[0]);
  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. });