trace.spec.tsx 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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. // this is flakey
  640. // eslint-disable-next-line jest/no-disabled-tests
  641. it.skip('arrow right expands row and fetches data', async () => {
  642. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  643. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  644. mockSpansResponse(
  645. '0',
  646. {},
  647. {
  648. entries: [
  649. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  650. ],
  651. }
  652. );
  653. await userEvent.click(rows[1]);
  654. await waitFor(() => expect(rows[1]).toHaveFocus());
  655. await userEvent.keyboard('{arrowright}');
  656. expect(await screen.findByText('special-span')).toBeInTheDocument();
  657. });
  658. it('arrow left collapses row', async () => {
  659. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  660. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  661. mockSpansResponse(
  662. '0',
  663. {},
  664. {
  665. entries: [
  666. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  667. ],
  668. }
  669. );
  670. await userEvent.click(rows[1]);
  671. await waitFor(() => expect(rows[1]).toHaveFocus());
  672. await userEvent.keyboard('{arrowright}');
  673. expect(await screen.findByText('special-span')).toBeInTheDocument();
  674. await userEvent.keyboard('{arrowleft}');
  675. expect(screen.queryByText('special-span')).not.toBeInTheDocument();
  676. });
  677. it('roving updates the element in the drawer', async () => {
  678. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  679. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  680. mockSpansResponse(
  681. '0',
  682. {},
  683. {
  684. entries: [
  685. {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
  686. ],
  687. }
  688. );
  689. await userEvent.click(rows[1]);
  690. await waitFor(() => expect(rows[1]).toHaveFocus());
  691. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  692. 'transaction-op-0'
  693. );
  694. await userEvent.keyboard('{arrowright}');
  695. expect(await screen.findByText('special-span')).toBeInTheDocument();
  696. await userEvent.keyboard('{arrowdown}');
  697. await waitFor(() => expect(rows[2]).toHaveFocus());
  698. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  699. 'special-span'
  700. );
  701. });
  702. it('arrowup on first node jumps to start', async () => {
  703. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  704. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  705. await userEvent.click(rows[0]);
  706. await waitFor(() => expect(rows[0]).toHaveFocus());
  707. await userEvent.keyboard('{arrowup}');
  708. expect(
  709. await findByText(virtualizedContainer, /transaction-op-9999/i)
  710. ).toBeInTheDocument();
  711. await waitFor(() => {
  712. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  713. expect(rows[rows.length - 1]).toHaveFocus();
  714. });
  715. });
  716. it('arrowdown on last node jumps to start', async () => {
  717. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  718. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  719. await userEvent.click(rows[0]);
  720. await waitFor(() => expect(rows[0]).toHaveFocus());
  721. await userEvent.keyboard('{arrowup}');
  722. expect(
  723. await findByText(virtualizedContainer, /transaction-op-9999/i)
  724. ).toBeInTheDocument();
  725. await waitFor(() => {
  726. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  727. expect(rows[rows.length - 1]).toHaveFocus();
  728. });
  729. await userEvent.keyboard('{arrowdown}');
  730. expect(
  731. await findByText(virtualizedContainer, /transaction-op-0/i)
  732. ).toBeInTheDocument();
  733. await waitFor(() => {
  734. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  735. expect(rows[0]).toHaveFocus();
  736. });
  737. });
  738. it('tab scrolls to next node', async () => {
  739. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  740. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  741. await userEvent.click(rows[0]);
  742. await waitFor(() => expect(rows[0]).toHaveFocus());
  743. await userEvent.keyboard('{tab}');
  744. await waitFor(() => {
  745. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  746. expect(rows[1]).toHaveFocus();
  747. });
  748. });
  749. it('shift+tab scrolls to previous node', async () => {
  750. const {virtualizedContainer} = await keyboardNavigationTestSetup();
  751. let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  752. await userEvent.click(rows[1]);
  753. await waitFor(() => expect(rows[1]).toHaveFocus());
  754. await userEvent.keyboard('{Shift>}{tab}{/Shift}');
  755. await waitFor(() => {
  756. rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  757. expect(rows[0]).toHaveFocus();
  758. });
  759. });
  760. it('arrowdown+shift scrolls to the end of the list', async () => {
  761. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  762. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  763. await userEvent.click(rows[0]);
  764. await waitFor(() => expect(rows[0]).toHaveFocus());
  765. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  766. expect(
  767. await findByText(virtualizedContainer, /transaction-op-9999/i)
  768. ).toBeInTheDocument();
  769. await waitFor(() => {
  770. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  771. expect(rows[rows.length - 1]).toHaveFocus();
  772. });
  773. });
  774. it('arrowup+shift scrolls to the start of the list', async () => {
  775. const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
  776. let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  777. await userEvent.click(rows[0]);
  778. await waitFor(() => expect(rows[0]).toHaveFocus());
  779. await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
  780. expect(
  781. await findByText(virtualizedContainer, /transaction-op-9999/i)
  782. ).toBeInTheDocument();
  783. await waitFor(() => {
  784. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  785. expect(rows[rows.length - 1]).toHaveFocus();
  786. });
  787. await userEvent.keyboard('{Shift>}{arrowup}{/Shift}');
  788. expect(
  789. await findByText(virtualizedContainer, /transaction-op-0/i)
  790. ).toBeInTheDocument();
  791. await scrollToEnd();
  792. await waitFor(() => {
  793. rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  794. expect(rows[0]).toHaveFocus();
  795. });
  796. });
  797. });
  798. describe('search', () => {
  799. it('searches in transaction', async () => {
  800. const {container} = await searchTestSetup();
  801. let rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  802. const searchInput = await screen.findByPlaceholderText('Search in trace');
  803. await userEvent.click(searchInput);
  804. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  805. await waitFor(() => {
  806. const highlighted_row = container.querySelector(
  807. '.TraceRow:not(.Hidden).SearchResult.Highlight'
  808. );
  809. rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
  810. expect(rows.indexOf(highlighted_row!)).toBe(1);
  811. });
  812. });
  813. it('supports roving with arrowup and arrowdown', async () => {
  814. const {container} = await searchTestSetup();
  815. const searchInput = await screen.findByPlaceholderText('Search in trace');
  816. await userEvent.click(searchInput);
  817. // Fire change because userEvent triggers this letter by letter
  818. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  819. // Wait for the search results to resolve
  820. await searchToUpdate();
  821. for (const action of [
  822. // starting at the top, jumpt bottom with shift+arrowdown
  823. ['{Shift>}{arrowdown}{/Shift}', 9],
  824. // // move to row above with arrowup
  825. ['{arrowup}', 8],
  826. // // and jump back to top with shift+arrowup
  827. ['{Shift>}{arrowup}{/Shift}', 1],
  828. // // // and jump to next row with arrowdown
  829. ['{arrowdown}', 2],
  830. ] as const) {
  831. await userEvent.keyboard(action[0] as string);
  832. // assert that focus on search input is never lost
  833. expect(searchInput).toHaveFocus();
  834. await waitFor(() => {
  835. // Only a single row is highlighted, the rest are search results
  836. assertHighlightedRowAtIndex(container, action[1]);
  837. });
  838. }
  839. });
  840. // @TODO I am torn on this because left-right
  841. // should probably also move the input cursor...
  842. // it.todo("supports expanding with arrowright")
  843. // it.todo("supports collapsing with arrowleft")
  844. it('search roving updates the element in the drawer', async () => {
  845. await searchTestSetup();
  846. const searchInput = await screen.findByPlaceholderText('Search in trace');
  847. await userEvent.click(searchInput);
  848. // Fire change because userEvent triggers this letter by letter
  849. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  850. // Wait for the search results to resolve
  851. await searchToUpdate();
  852. expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
  853. 'transaction-op-0'
  854. );
  855. // assert that focus on search input is never lost
  856. expect(searchInput).toHaveFocus();
  857. await userEvent.keyboard('{arrowdown}');
  858. await waitFor(() => {
  859. expect(screen.getByTestId('trace-drawer-title')).toHaveTextContent(
  860. 'transaction-op-1'
  861. );
  862. });
  863. });
  864. it('highlighted node narrows down on the first result', async () => {
  865. const {container} = await searchTestSetup();
  866. const searchInput = await screen.findByPlaceholderText('Search in trace');
  867. await userEvent.click(searchInput);
  868. // Fire change because userEvent triggers this letter by letter
  869. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  870. // Wait for the search results to resolve
  871. await searchToUpdate();
  872. assertHighlightedRowAtIndex(container, 2);
  873. fireEvent.change(searchInput, {target: {value: 'transaction-op-10'}});
  874. await searchToUpdate();
  875. await waitFor(() => {
  876. assertHighlightedRowAtIndex(container, 9);
  877. });
  878. });
  879. it('highlighted is persisted on node while it is part of the search results', async () => {
  880. const {container} = await searchTestSetup();
  881. const searchInput = await screen.findByPlaceholderText('Search in trace');
  882. await userEvent.click(searchInput);
  883. // Fire change because userEvent triggers this letter by letter
  884. fireEvent.change(searchInput, {target: {value: 'trans'}});
  885. // Wait for the search results to resolve
  886. await searchToUpdate();
  887. await userEvent.keyboard('{arrowdown}');
  888. await searchToUpdate();
  889. assertHighlightedRowAtIndex(container, 2);
  890. fireEvent.change(searchInput, {target: {value: 'transa'}});
  891. await searchToUpdate();
  892. // Highlighting is persisted on the row
  893. assertHighlightedRowAtIndex(container, 2);
  894. fireEvent.change(searchInput, {target: {value: 'this wont match anything'}});
  895. await searchToUpdate();
  896. // When there is no match, the highlighting is removed
  897. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  898. });
  899. it('auto highlights the first result when search begins', async () => {
  900. const {container} = await searchTestSetup();
  901. const searchInput = await screen.findByPlaceholderText('Search in trace');
  902. await userEvent.click(searchInput);
  903. // Nothing is highlighted
  904. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  905. // Fire change because userEvent triggers this letter by letter
  906. fireEvent.change(searchInput, {target: {value: 't'}});
  907. // Wait for the search results to resolve
  908. await searchToUpdate();
  909. assertHighlightedRowAtIndex(container, 1);
  910. });
  911. it('clicking a row that is also a search result updates the result index', async () => {
  912. const {container} = await searchTestSetup();
  913. const searchInput = await screen.findByPlaceholderText('Search in trace');
  914. await userEvent.click(searchInput);
  915. // Fire change because userEvent triggers this letter by letter
  916. fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
  917. await searchToUpdate();
  918. assertHighlightedRowAtIndex(container, 2);
  919. const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  920. // By default, we highlight the first result
  921. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  922. '1/2'
  923. );
  924. await scrollToEnd();
  925. // Click on a random row in the list that is not a search result
  926. await userEvent.click(rows[5]);
  927. await waitFor(() => {
  928. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  929. '-/2'
  930. );
  931. });
  932. await scrollToEnd();
  933. // Click on a the row in the list that is a search result
  934. await userEvent.click(rows[2]);
  935. await waitFor(() => {
  936. expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
  937. '1/2'
  938. );
  939. });
  940. });
  941. it('during search, expanding a row retriggers search', async () => {
  942. mockTraceMetaResponse();
  943. mockTraceRootFacets();
  944. mockTraceRootEvent('0', {body: DetailedEventsFixture()[0]});
  945. mockTraceEventDetails();
  946. mockTraceResponse({
  947. body: {
  948. transactions: [
  949. makeTransaction({
  950. span_id: '0',
  951. event_id: '0',
  952. transaction: 'transaction-name-0',
  953. 'transaction.op': 'transaction-op-0',
  954. }),
  955. ],
  956. orphan_errors: [],
  957. },
  958. });
  959. mockSpansResponse(
  960. '0',
  961. {},
  962. {
  963. entries: [
  964. {
  965. type: EntryType.SPANS,
  966. data: [
  967. makeSpan({span_id: '0', description: 'span-description', op: 'op-0'}),
  968. ],
  969. },
  970. ],
  971. }
  972. );
  973. const value = render(<TraceViewWithProviders traceSlug="trace-id" />);
  974. // Awaits for the placeholder rendering rows to be removed
  975. expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
  976. const searchInput = await screen.findByPlaceholderText('Search in trace');
  977. await userEvent.click(searchInput);
  978. // Fire change because userEvent triggers this letter by letter
  979. fireEvent.change(searchInput, {target: {value: 'op-0'}});
  980. await searchToUpdate();
  981. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  982. '1/1'
  983. );
  984. const highlighted_row = value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
  985. await userEvent.click(await screen.findByRole('button', {name: '+'}));
  986. expect(await screen.findByText('span-description')).toBeInTheDocument();
  987. await searchToUpdate();
  988. // The search is retriggered, but highlighting of current row is preserved
  989. expect(value.container.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW)).toBe(
  990. highlighted_row
  991. );
  992. expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
  993. '1/2'
  994. );
  995. });
  996. it('during search, highlighting is persisted on the row', async () => {
  997. const {container} = await searchTestSetup();
  998. const searchInput = await screen.findByPlaceholderText('Search in trace');
  999. await userEvent.click(searchInput);
  1000. // Fire change because userEvent triggers this letter by letter
  1001. fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
  1002. await searchToUpdate();
  1003. assertHighlightedRowAtIndex(container, 1);
  1004. await searchToUpdate();
  1005. // User moves down the list using keyboard navigation
  1006. for (const _ of [1, 2, 3, 4, 5]) {
  1007. const initial = screen.getByTestId('trace-search-result-iterator').textContent;
  1008. await userEvent.keyboard('{arrowDown}');
  1009. await waitFor(() => {
  1010. expect(screen.getByTestId('trace-search-result-iterator')).not.toBe(initial);
  1011. });
  1012. }
  1013. // User clicks on an entry in the list, then proceeds to search
  1014. await waitFor(() => {
  1015. expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
  1016. '6/11'
  1017. );
  1018. });
  1019. // And then continues the query - the highlighting is preserved as long as the
  1020. // rwo is part of the search results
  1021. assertHighlightedRowAtIndex(container, 6);
  1022. fireEvent.change(searchInput, {target: {value: 'transaction-op-'}});
  1023. await searchToUpdate();
  1024. assertHighlightedRowAtIndex(container, 6);
  1025. fireEvent.change(searchInput, {target: {value: 'transaction-op-5'}});
  1026. await searchToUpdate();
  1027. assertHighlightedRowAtIndex(container, 6);
  1028. fireEvent.change(searchInput, {target: {value: 'transaction-op-none'}});
  1029. await searchToUpdate();
  1030. expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
  1031. });
  1032. });
  1033. describe('tabbing', () => {
  1034. beforeEach(() => {
  1035. jest.spyOn(console, 'error').mockImplementation();
  1036. });
  1037. afterEach(() => {
  1038. jest.restoreAllMocks();
  1039. });
  1040. it('clicking on a node spawns a new tab when none is selected', async () => {
  1041. const {virtualizedContainer} = await simpleTestSetup();
  1042. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1043. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1044. await userEvent.click(rows[5]);
  1045. await waitFor(() => {
  1046. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1047. });
  1048. });
  1049. it('clicking on a node replaces the previously selected tab', async () => {
  1050. const {virtualizedContainer} = await simpleTestSetup();
  1051. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1052. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1053. await userEvent.click(rows[5]);
  1054. await waitFor(() => {
  1055. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1056. expect(
  1057. screen
  1058. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1059. .textContent?.includes('transaction-op-4')
  1060. ).toBeTruthy();
  1061. });
  1062. await userEvent.click(rows[7]);
  1063. await waitFor(() => {
  1064. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1065. expect(
  1066. screen
  1067. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1068. .textContent?.includes('transaction-op-6')
  1069. ).toBeTruthy();
  1070. });
  1071. });
  1072. it('pinning a tab and clicking on a new node spawns a new tab', async () => {
  1073. const {virtualizedContainer} = await simpleTestSetup();
  1074. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1075. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1076. await userEvent.click(rows[5]);
  1077. await waitFor(() => {
  1078. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1079. });
  1080. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1081. await userEvent.click(rows[7]);
  1082. await waitFor(() => {
  1083. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1084. expect(
  1085. screen
  1086. .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
  1087. .textContent?.includes('transaction-op-4')
  1088. ).toBeTruthy();
  1089. expect(
  1090. screen
  1091. .queryAllByTestId(DRAWER_TABS_TEST_ID)[2]
  1092. .textContent?.includes('transaction-op-6')
  1093. ).toBeTruthy();
  1094. });
  1095. });
  1096. it('unpinning a tab removes it', async () => {
  1097. const {virtualizedContainer} = await simpleTestSetup();
  1098. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1099. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1100. await userEvent.click(rows[5]);
  1101. await waitFor(() => {
  1102. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1103. });
  1104. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1105. await userEvent.click(rows[7]);
  1106. await waitFor(() => {
  1107. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1108. });
  1109. const tabButtons = screen.queryAllByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID);
  1110. expect(tabButtons).toHaveLength(2);
  1111. await userEvent.click(tabButtons[0]);
  1112. await waitFor(() => {
  1113. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1114. });
  1115. });
  1116. it('clicking a node that is already open in a tab switches to that tab and persists the previous node', async () => {
  1117. const {virtualizedContainer} = await simpleTestSetup();
  1118. const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
  1119. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
  1120. await userEvent.click(rows[5]);
  1121. await waitFor(() => {
  1122. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
  1123. });
  1124. await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
  1125. await userEvent.click(rows[7]);
  1126. await waitFor(() => {
  1127. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1128. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[2]).toHaveAttribute(
  1129. 'aria-selected',
  1130. 'true'
  1131. );
  1132. });
  1133. await userEvent.click(rows[5]);
  1134. await waitFor(() => {
  1135. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[1]).toHaveAttribute(
  1136. 'aria-selected',
  1137. 'true'
  1138. );
  1139. expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
  1140. });
  1141. });
  1142. });
  1143. });