1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804 |
- import * as Sentry from '@sentry/react';
- import MockDate from 'mockdate';
- import {TransactionEventFixture} from 'sentry-fixture/event';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- findAllByText,
- findByText,
- fireEvent,
- render,
- screen,
- userEvent,
- waitFor,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import {EntryType, type EventTransaction} from 'sentry/types/event';
- import type {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
- import {TraceView} from 'sentry/views/performance/newTraceDetails/index';
- import {
- makeEventTransaction,
- makeSpan,
- makeTraceError,
- makeTransaction,
- } from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeTestUtils';
- import type {TracePreferencesState} from 'sentry/views/performance/newTraceDetails/traceState/tracePreferences';
- import {DEFAULT_TRACE_VIEW_PREFERENCES} from 'sentry/views/performance/newTraceDetails/traceState/tracePreferences';
- class MockResizeObserver {
- callback: ResizeObserverCallback;
- constructor(callback: ResizeObserverCallback) {
- this.callback = callback;
- }
- unobserve(_element: HTMLElement) {
- return;
- }
- observe(element: HTMLElement) {
- // Executes in sync so we dont have to
- this.callback(
- [
- {
- target: element,
- // @ts-expect-error partial mock
- contentRect: {width: 1000, height: 24 * 20 - 1},
- },
- ],
- this
- );
- }
- disconnect() {}
- }
- type Arguments<F extends Function> = F extends (...args: infer A) => any ? A : never;
- type ResponseType = Arguments<typeof MockApiClient.addMockResponse>[0];
- function mockQueryString(queryString: string) {
- Object.defineProperty(window, 'location', {
- value: {
- search: queryString,
- },
- });
- }
- function mockTracePreferences(preferences: Partial<TracePreferencesState>) {
- const merged: TracePreferencesState = {
- ...DEFAULT_TRACE_VIEW_PREFERENCES,
- ...preferences,
- autogroup: {
- ...DEFAULT_TRACE_VIEW_PREFERENCES.autogroup,
- ...preferences.autogroup,
- },
- drawer: {
- ...DEFAULT_TRACE_VIEW_PREFERENCES.drawer,
- ...preferences.drawer,
- },
- list: {
- ...DEFAULT_TRACE_VIEW_PREFERENCES.list,
- ...preferences.list,
- },
- };
- localStorage.setItem('trace-view-preferences', JSON.stringify(merged));
- }
- function mockTraceResponse(resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-trace/trace-id/',
- method: 'GET',
- asyncDelay: 1,
- ...(resp ?? {body: {}}),
- });
- }
- function mockTraceMetaResponse(resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-trace-meta/trace-id/',
- method: 'GET',
- asyncDelay: 1,
- ...(resp ?? {
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: [],
- },
- }),
- });
- }
- function mockTraceTagsResponse(resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-facets/',
- method: 'GET',
- asyncDelay: 1,
- ...(resp ?? {body: []}),
- });
- }
- // function _mockTraceDetailsResponse(id: string, resp?: Partial<ResponseType>) {
- // MockApiClient.addMockResponse({
- // url: `/organizations/org-slug/events/project_slug:transaction-${id}`,
- // method: 'GET',
- // asyncDelay: 1,
- // ...(resp ?? {}),
- // });
- // }
- function mockTransactionDetailsResponse(id: string, resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events/project_slug:${id}/`,
- method: 'GET',
- asyncDelay: 1,
- ...(resp ?? {body: TransactionEventFixture()}),
- });
- }
- function mockTraceRootEvent(id: string, resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events/project_slug:${id}/`,
- method: 'GET',
- asyncDelay: 1,
- ...(resp ?? {body: TransactionEventFixture()}),
- });
- }
- function mockTraceRootFacets(resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events-facets/`,
- method: 'GET',
- asyncDelay: 1,
- body: {},
- ...(resp ?? {}),
- });
- }
- function mockTraceEventDetails(resp?: Partial<ResponseType>) {
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events/`,
- method: 'GET',
- asyncDelay: 1,
- body: {},
- ...(resp ?? {body: TransactionEventFixture()}),
- });
- }
- function mockSpansResponse(
- id: string,
- resp?: Partial<ResponseType>,
- body: Partial<EventTransaction> = {}
- ) {
- return MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events/project_slug:${id}/?averageColumn=span.self_time&averageColumn=span.duration`,
- method: 'GET',
- asyncDelay: 1,
- body,
- ...(resp ?? {}),
- });
- }
- function mockTransactionSpansResponse(
- id: string,
- resp?: Partial<ResponseType>,
- body: Partial<EventTransaction> = {}
- ) {
- return MockApiClient.addMockResponse({
- url: `/organizations/org-slug/events/project_slug:${id}/`,
- method: 'GET',
- asyncDelay: 1,
- body,
- ...(resp ?? {}),
- });
- }
- const {router} = initializeOrg({
- router: {
- params: {orgId: 'org-slug', traceSlug: 'trace-id'},
- },
- });
- function mockMetricsResponse() {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/query/',
- method: 'POST',
- body: {
- data: [],
- queries: [],
- },
- });
- }
- function getVirtualizedContainer(): HTMLElement {
- const virtualizedContainer = screen.queryByTestId('trace-virtualized-list');
- if (!virtualizedContainer) {
- throw new Error('Virtualized container not found');
- }
- return virtualizedContainer;
- }
- function getVirtualizedScrollContainer(): HTMLElement {
- const virtualizedScrollContainer = screen.queryByTestId(
- 'trace-virtualized-list-scroll-container'
- );
- if (!virtualizedScrollContainer) {
- throw new Error('Virtualized scroll container not found');
- }
- return virtualizedScrollContainer;
- }
- async function keyboardNavigationTestSetup() {
- const keyboard_navigation_transactions: TraceFullDetailed[] = [];
- for (let i = 0; i < 1e4; i++) {
- keyboard_navigation_transactions.push(
- makeTransaction({
- span_id: i + '',
- event_id: i + '',
- transaction: 'transaction-name-' + i,
- 'transaction.op': 'transaction-op-' + i,
- project_slug: 'project_slug',
- })
- );
- mockTransactionDetailsResponse(i.toString());
- }
- mockTraceResponse({
- body: {
- transactions: keyboard_navigation_transactions,
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: keyboard_navigation_transactions.map(t => ({
- 'transaction.id': t.event_id,
- count: 5,
- })),
- },
- });
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- async function pageloadTestSetup() {
- const pageloadTransactions: TraceFullDetailed[] = [];
- for (let i = 0; i < 1e3; i++) {
- pageloadTransactions.push(
- makeTransaction({
- span_id: i + '',
- event_id: i + '',
- transaction: 'transaction-name-' + i,
- 'transaction.op': 'transaction-op-' + i,
- project_slug: 'project_slug',
- })
- );
- mockTransactionDetailsResponse(i.toString());
- }
- mockTraceResponse({
- body: {
- transactions: pageloadTransactions,
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: pageloadTransactions.map(t => ({
- 'transaction.id': t.event_id,
- count: 5,
- })),
- },
- });
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect((await screen.findAllByText(/transaction-op-/i)).length).toBeGreaterThan(0);
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- async function nestedTransactionsTestSetup() {
- const transactions: TraceFullDetailed[] = [];
- let txn = makeTransaction({
- span_id: '0',
- event_id: '0',
- transaction: 'transaction-name-0',
- 'transaction.op': 'transaction-op-0',
- project_slug: 'project_slug',
- });
- transactions.push(txn);
- for (let i = 0; i < 100; i++) {
- const next = makeTransaction({
- span_id: i + '',
- event_id: i + '',
- transaction: 'transaction-name-' + i,
- 'transaction.op': 'transaction-op-' + i,
- project_slug: 'project_slug',
- });
- txn.children.push(next);
- txn = next;
- transactions.push(next);
- mockTransactionDetailsResponse(i.toString());
- }
- mockTraceResponse({
- body: {
- transactions: transactions,
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse();
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect((await screen.findAllByText(/transaction-op-/i)).length).toBeGreaterThan(0);
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- async function searchTestSetup() {
- const transactions: TraceFullDetailed[] = [];
- for (let i = 0; i < 11; i++) {
- transactions.push(
- makeTransaction({
- span_id: i + '',
- event_id: i + '',
- transaction: 'transaction-name' + i,
- 'transaction.op': 'transaction-op-' + i,
- project_slug: 'project_slug',
- })
- );
- mockTransactionDetailsResponse(i.toString());
- }
- mockTraceResponse({
- body: {
- transactions: transactions,
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: transactions.map(t => ({
- 'transaction.id': t.event_id,
- count: 5,
- })),
- },
- });
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- async function simpleTestSetup() {
- const transactions: TraceFullDetailed[] = [];
- let parent: any;
- for (let i = 0; i < 1e3; i++) {
- const next = makeTransaction({
- span_id: i + '',
- event_id: i + '',
- transaction: 'transaction-name' + i,
- 'transaction.op': 'transaction-op-' + i,
- project_slug: 'project_slug',
- });
- if (parent) {
- parent.children.push(next);
- } else {
- transactions.push(next);
- }
- parent = next;
- mockTransactionDetailsResponse(i.toString());
- }
- mockTraceResponse({
- body: {
- transactions: transactions,
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: transactions.map(t => ({
- 'transaction.id': t.event_id,
- count: 5,
- })),
- },
- });
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- async function completeTestSetup() {
- const start = Date.now() / 1e3;
- mockTraceResponse({
- body: {
- transactions: [
- makeTransaction({
- event_id: '0',
- transaction: 'transaction-name-0',
- 'transaction.op': 'transaction-op-0',
- project_slug: 'project_slug',
- start_timestamp: start,
- timestamp: start + 2,
- children: [
- makeTransaction({
- event_id: '1',
- transaction: 'transaction-name-1',
- 'transaction.op': 'transaction-op-1',
- project_slug: 'project_slug',
- start_timestamp: start,
- timestamp: start + 2,
- }),
- ],
- }),
- makeTransaction({
- event_id: '2',
- transaction: 'transaction-name-2',
- 'transaction.op': 'transaction-op-2',
- project_slug: 'project_slug',
- start_timestamp: start,
- timestamp: start + 2,
- }),
- makeTransaction({
- event_id: '3',
- transaction: 'transaction-name-3',
- 'transaction.op': 'transaction-op-3',
- project_slug: 'project_slug',
- start_timestamp: start,
- timestamp: start + 2,
- }),
- ],
- orphan_errors: [
- makeTraceError({
- event_id: 'error0',
- issue: 'error-issue',
- project_id: 0,
- project_slug: 'project_slug',
- issue_id: 0,
- title: 'error-title',
- level: 'fatal',
- timestamp: start + 2,
- }),
- ],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: [
- {
- 'transaction.id': '0',
- count: 2,
- },
- {
- 'transaction.id': '1',
- count: 2,
- },
- {
- 'transaction.id': '2',
- count: 2,
- },
- {
- 'transaction.id': '3',
- count: 2,
- },
- ],
- },
- });
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/project_slug:error0/',
- body: {
- tags: [],
- contexts: {},
- entries: [],
- },
- });
- const transactionWithSpans = makeEventTransaction({
- entries: [
- {
- type: EntryType.SPANS,
- data: [
- makeSpan({
- span_id: 'span0',
- op: 'http',
- description: 'request',
- start_timestamp: start,
- timestamp: start + 0.1,
- }),
- // Parent autogroup chain
- makeSpan({
- op: 'db',
- description: 'redis',
- parent_span_id: 'span0',
- span_id: 'redis0',
- start_timestamp: start + 0.1,
- timestamp: start + 0.2,
- }),
- makeSpan({
- op: 'db',
- description: 'redis',
- parent_span_id: 'redis0',
- span_id: 'redis1',
- start_timestamp: start + 0.2,
- timestamp: start + 0.3,
- }),
- // Sibling autogroup chain
- makeSpan({
- op: 'http',
- description: 'request',
- parent_span_id: 'span0',
- span_id: 'http0',
- start_timestamp: start + 0.3,
- timestamp: start + 0.4,
- }),
- makeSpan({
- op: 'http',
- description: 'request',
- parent_span_id: 'span0',
- span_id: 'http1',
- start_timestamp: start + 0.4,
- timestamp: start + 0.5,
- }),
- makeSpan({
- op: 'http',
- description: 'request',
- parent_span_id: 'span0',
- span_id: 'http2',
- start_timestamp: start + 0.5,
- timestamp: start + 0.6,
- }),
- makeSpan({
- op: 'http',
- description: 'request',
- parent_span_id: 'span0',
- span_id: 'http3',
- start_timestamp: start + 0.6,
- timestamp: start + 0.7,
- }),
- makeSpan({
- op: 'http',
- description: 'request',
- parent_span_id: 'span0',
- span_id: 'http4',
- start_timestamp: start + 0.7,
- timestamp: start + 0.8,
- }),
- // Missing instrumentation gap
- makeSpan({
- op: 'queue',
- description: 'process',
- parent_span_id: 'span0',
- span_id: 'queueprocess0',
- start_timestamp: start + 0.8,
- timestamp: start + 0.9,
- }),
- makeSpan({
- op: 'queue',
- description: 'process',
- parent_span_id: 'span0',
- span_id: 'queueprocess1',
- start_timestamp: start + 1.1,
- timestamp: start + 1.2,
- }),
- ],
- },
- ],
- });
- const transactionWithoutSpans = makeEventTransaction({});
- mockTransactionSpansResponse('1', {}, transactionWithSpans);
- mockSpansResponse('1', {}, transactionWithSpans);
- // Mock empty response for txn without spans
- mockTransactionSpansResponse('0', {}, transactionWithoutSpans);
- mockSpansResponse('0', {}, transactionWithoutSpans);
- const value = render(<TraceView />, {router});
- const virtualizedContainer = getVirtualizedContainer();
- const virtualizedScrollContainer = getVirtualizedScrollContainer();
- // Awaits for the placeholder rendering rows to be removed
- expect(await findByText(value.container, /transaction-op-0/i)).toBeInTheDocument();
- return {...value, virtualizedContainer, virtualizedScrollContainer};
- }
- const DRAWER_TABS_TEST_ID = 'trace-drawer-tab';
- const DRAWER_TABS_PIN_BUTTON_TEST_ID = 'trace-drawer-tab-pin-button';
- const VISIBLE_TRACE_ROW_SELECTOR = '.TraceRow:not(.Hidden)';
- const ACTIVE_SEARCH_HIGHLIGHT_ROW = '.TraceRow.SearchResult.Highlight:not(.Hidden)';
- const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
- const searchToUpdate = async (): Promise<void> => {
- await wait(500);
- };
- const scrollToEnd = async (): Promise<void> => {
- await wait(500);
- };
- // @ts-expect-error ignore this line
- // eslint-disable-next-line
- function printVirtualizedList(container: HTMLElement) {
- const stdout: string[] = [];
- const scrollContainer = screen.queryByTestId(
- 'trace-virtualized-list-scroll-container'
- )!;
- const rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
- const searchResultIterator = screen.queryByTestId('trace-search-result-iterator');
- stdout.push(
- 'Scroll Container: ' +
- 'top=' +
- scrollContainer.scrollTop +
- ' ' +
- 'left=' +
- scrollContainer.scrollLeft +
- ' ' +
- rows.length +
- ' ' +
- 'Search:' +
- (searchResultIterator?.textContent ?? '')
- );
- for (const r of [...rows]) {
- const count = (r.querySelector('.TraceChildrenCount') as HTMLElement)?.textContent;
- const op = (r.querySelector('.TraceOperation') as HTMLElement)?.textContent;
- const desc = (r.querySelector('.TraceDescription') as HTMLElement)?.textContent;
- let t = (count ?? '') + ' ' + (op ?? '') + ' — ' + (desc ?? '');
- if (r.classList.contains('SearchResult')) {
- t = t + ' search';
- }
- if (r.classList.contains('Highlight')) {
- t = t + ' highlight';
- }
- if (document.activeElement === r) {
- t = t + ' ⬅ focused ';
- }
- const leftColumn = r.querySelector('.TraceLeftColumnInner') as HTMLElement;
- const left = Math.round(parseInt(leftColumn.style.paddingLeft, 10) / 10);
- stdout.push(' '.repeat(left) + t);
- }
- // This is a debug fn, we need it to log
- // eslint-disable-next-line
- console.log(stdout.join('\n'));
- }
- // @ts-expect-error ignore this line
- // eslint-disable-next-line
- function printTabs() {
- const tabs = screen.queryAllByTestId(DRAWER_TABS_TEST_ID);
- const stdout: string[] = [];
- for (const tab of tabs) {
- let text = tab.textContent ?? 'empty tab??';
- if (tab.hasAttribute('aria-selected')) {
- text = 'active' + text;
- }
- stdout.push(text);
- }
- // This is a debug fn, we need it to log
- // eslint-disable-next-line
- console.log(stdout.join(' | '));
- }
- function assertHighlightedRowAtIndex(virtualizedContainer: HTMLElement, index: number) {
- expect(virtualizedContainer.querySelectorAll('.TraceRow.Highlight')).toHaveLength(1);
- const highlighted_row = virtualizedContainer.querySelector(ACTIVE_SEARCH_HIGHLIGHT_ROW);
- const r = Array.from(virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
- expect(r.indexOf(highlighted_row!)).toBe(index);
- }
- // biome-ignore lint/suspicious/noSkippedTests: <Flaky test>
- describe.skip('trace view', () => {
- beforeEach(() => {
- jest.spyOn(console, 'error').mockImplementation(() => {});
- globalThis.ResizeObserver = MockResizeObserver as any;
- mockQueryString('');
- MockDate.reset();
- });
- afterEach(() => {
- mockQueryString('');
- // @ts-expect-error clear mock
- globalThis.ResizeObserver = undefined;
- });
- it('renders loading state', async () => {
- mockTraceResponse();
- mockTraceMetaResponse();
- mockTraceTagsResponse();
- render(<TraceView />, {router});
- expect(await screen.findByText(/assembling the trace/i)).toBeInTheDocument();
- });
- it('renders error state if trace fails to load', async () => {
- mockTraceResponse({statusCode: 404});
- mockTraceMetaResponse({statusCode: 404});
- mockTraceTagsResponse({statusCode: 404});
- render(<TraceView />, {router});
- expect(await screen.findByText(/we failed to load your trace/i)).toBeInTheDocument();
- });
- it('renders error state if meta fails to load', async () => {
- mockTraceResponse({
- statusCode: 200,
- body: {
- transactions: [makeTransaction()],
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({statusCode: 404});
- mockTraceTagsResponse({statusCode: 404});
- render(<TraceView />, {router});
- expect(await screen.findByText(/we failed to load your trace/i)).toBeInTheDocument();
- });
- it('renders empty state', async () => {
- mockTraceResponse({
- body: {
- transactions: [],
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse();
- mockTraceTagsResponse();
- render(<TraceView />, {router});
- expect(
- await screen.findByText(/trace does not contain any data/i)
- ).toBeInTheDocument();
- });
- describe('pageload', () => {
- it('scrolls to trace root', async () => {
- mockQueryString('?node=trace-root');
- const {virtualizedContainer} = await completeTestSetup();
- await waitFor(() => {
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[0]).toHaveFocus();
- });
- });
- it('scrolls to transaction', async () => {
- mockQueryString('?node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await waitFor(() => {
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[2]).toHaveFocus();
- });
- });
- it('scrolls to span that is a child of transaction', async () => {
- mockQueryString('?node=span-span0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next tick
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[3]).toHaveFocus();
- expect(rows[3].textContent?.includes('http — request')).toBe(true);
- });
- });
- it('scrolls to parent autogroup node', async () => {
- mockQueryString('?node=ag-redis0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next tick
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[4]).toHaveFocus();
- expect(rows[4].textContent?.includes('Autogrouped')).toBe(true);
- });
- });
- it('scrolls to child of parent autogroup node', async () => {
- mockQueryString('?node=span-redis0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next tick
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[5]).toHaveFocus();
- expect(rows[5].textContent?.includes('db — redis')).toBe(true);
- });
- });
- it('scrolls to sibling autogroup node', async () => {
- mockQueryString('?node=ag-http0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next tick
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[5]).toHaveFocus();
- expect(rows[5].textContent?.includes('5Autogrouped')).toBe(true);
- });
- });
- it('scrolls to child of sibling autogroup node', async () => {
- mockQueryString('?node=span-http0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next tick
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[6]).toHaveFocus();
- expect(rows[6].textContent?.includes('http — request')).toBe(true);
- });
- });
- it('scrolls to missing instrumentation node', async () => {
- mockQueryString('?node=ms-queueprocess0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- // We need to await a tick because the row is not focused until the next ticks
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await waitFor(() => {
- expect(rows[7]).toHaveFocus();
- expect(rows[7].textContent?.includes('Missing instrumentation')).toBe(true);
- });
- });
- it('scrolls to trace error node', async () => {
- mockQueryString('?node=error-error0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- // We need to await a tick because the row is not focused until the next ticks
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[11]).toHaveFocus();
- expect(rows[11].textContent?.includes('error-title')).toBe(true);
- });
- });
- it('scrolls to event id query param', async () => {
- mockQueryString('?eventId=1');
- const {virtualizedContainer} = await completeTestSetup();
- await waitFor(() => {
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[2]).toHaveFocus();
- });
- });
- it('supports expanded node path', async () => {
- mockQueryString('?node=span-span0&node=txn-1&span-0&node=txn-0');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- await waitFor(() => {
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[3]).toHaveFocus();
- expect(rows[3].textContent?.includes('http — request')).toBe(true);
- });
- });
- it.each([
- '?eventId=doesnotexist',
- '?node=txn-doesnotexist',
- // Invalid path
- '?node=span-does-notexist',
- ])('logs if path is not found: %s', async path => {
- mockQueryString(path);
- const sentryScopeMock = {
- setFingerprint: jest.fn(),
- captureMessage: jest.fn(),
- } as any;
- jest.spyOn(Sentry, 'withScope').mockImplementation((f: any) => f(sentryScopeMock));
- await pageloadTestSetup();
- await waitFor(() => {
- expect(sentryScopeMock.captureMessage).toHaveBeenCalledWith(
- 'Failed to scroll to node in trace tree'
- );
- });
- });
- it('does not autogroup if user preference is disabled', async () => {
- mockTracePreferences({autogroup: {parent: false, sibling: false}});
- mockQueryString('?node=span-span0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /process/i);
- expect(screen.queryByText(/Autogrouped/i)).not.toBeInTheDocument();
- });
- it('does not inject missing instrumentation if user preference is disabled', async () => {
- mockTracePreferences({missing_instrumentation: false});
- mockQueryString('?node=span-span0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /process/i);
- expect(screen.queryByText(/Missing instrumentation/i)).not.toBeInTheDocument();
- });
- // biome-ignore lint/suspicious/noSkippedTests: @JonasBa will fix these flakey tests soon
- describe.skip('preferences', () => {
- it('toggles autogrouping', async () => {
- mockTracePreferences({autogroup: {parent: true, sibling: true}});
- mockQueryString('?node=span-span0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Autogrouped/i);
- const preferencesDropdownTrigger = screen.getByLabelText('Trace Preferences');
- await userEvent.click(preferencesDropdownTrigger);
- // Toggle autogrouping off
- await userEvent.click(await screen.findByText('Autogrouping'));
- await waitFor(() => {
- expect(screen.queryByText('Autogrouped')).not.toBeInTheDocument();
- });
- // Toggle autogrouping on
- await userEvent.click(await screen.findByText('Autogrouping'));
- await waitFor(() => {
- expect(screen.queryAllByText('Autogrouped')).toHaveLength(2);
- });
- });
- it('toggles missing instrumentation', async () => {
- mockTracePreferences({missing_instrumentation: true});
- mockQueryString('?node=span-span0&node=txn-1');
- const {virtualizedContainer} = await completeTestSetup();
- await findAllByText(virtualizedContainer, /Missing instrumentation/i);
- const preferencesDropdownTrigger = screen.getByLabelText('Trace Preferences');
- // Toggle missing instrumentation off
- await userEvent.click(preferencesDropdownTrigger);
- const missingInstrumentationOption = await screen.findByText(
- 'Missing Instrumentation'
- );
- // Toggle missing instrumentation off
- await userEvent.click(missingInstrumentationOption);
- await waitFor(() => {
- expect(screen.queryByText('Missing instrumentation')).not.toBeInTheDocument();
- });
- // Toggle missing instrumentation on
- await userEvent.click(missingInstrumentationOption);
- await waitFor(() => {
- expect(screen.queryByText('Missing instrumentation')).toBeInTheDocument();
- });
- });
- });
- it('triggers search on load but does not steal focus from node param', async () => {
- mockQueryString('?search=transaction-op-999&node=txn-0');
- const {virtualizedContainer} = await pageloadTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- expect(searchInput).toHaveValue('transaction-op-999');
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '-/1'
- );
- });
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[1]).toHaveFocus();
- });
- it('if search on load does not match anything, it does not steal focus or highlight first result', async () => {
- mockQueryString('?search=dead&node=txn-5');
- const {container} = await pageloadTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- expect(searchInput).toHaveValue('dead');
- await waitFor(() => {
- expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
- 'no results'
- );
- });
- const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[6]).toHaveFocus();
- });
- });
- describe('keyboard navigation', () => {
- it('arrow down', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{arrowdown}');
- await waitFor(() => expect(rows[1]).toHaveFocus());
- });
- it('arrow up', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- await userEvent.keyboard('{arrowup}');
- await waitFor(() => expect(rows[0]).toHaveFocus());
- });
- it('arrow right expands row and fetches data', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- mockSpansResponse(
- '0',
- {},
- {
- entries: [
- {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
- ],
- }
- );
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- await userEvent.keyboard('{arrowright}');
- await waitFor(() => {
- expect(screen.queryByText('special-span')).toBeInTheDocument();
- });
- });
- it('arrow left collapses row', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- const request = mockSpansResponse(
- '0',
- {},
- {
- entries: [
- {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
- ],
- }
- );
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- await userEvent.keyboard('{arrowright}');
- expect(request).toHaveBeenCalledTimes(1);
- expect(await screen.findByText('special-span')).toBeInTheDocument();
- await userEvent.keyboard('{arrowleft}');
- expect(screen.queryByText('special-span')).not.toBeInTheDocument();
- });
- it('arrow left does not collapse trace root row', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{arrowleft}');
- expect(await screen.findByText('transaction-name-1')).toBeInTheDocument();
- });
- it('arrow left on transaction row still renders transaction children', async () => {
- const {virtualizedContainer} = await nestedTransactionsTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- await userEvent.keyboard('{arrowleft}');
- expect(await screen.findByText('transaction-name-2')).toBeInTheDocument();
- });
- it('roving updates the element in the drawer', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- mockSpansResponse(
- '0',
- {},
- {
- entries: [
- {type: EntryType.SPANS, data: [makeSpan({span_id: '0', op: 'special-span'})]},
- ],
- }
- );
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
- 'transaction-op-0'
- );
- await userEvent.keyboard('{arrowright}');
- expect(await screen.findByText('special-span')).toBeInTheDocument();
- await userEvent.keyboard('{arrowdown}');
- await waitFor(() => {
- const updatedRows = virtualizedContainer.querySelectorAll(
- VISIBLE_TRACE_ROW_SELECTOR
- );
- expect(updatedRows[2]).toHaveFocus();
- });
- expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
- 'special-span'
- );
- });
- it('arrowup on first node jumps to end', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{arrowup}');
- expect(
- await findByText(virtualizedContainer, /transaction-op-9999/i)
- ).toBeInTheDocument();
- await waitFor(() => {
- rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[rows.length - 1]).toHaveFocus();
- });
- });
- it('arrowdown on last node jumps to start', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{arrowup}', {delay: null});
- await waitFor(() => {
- rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[rows.length - 1]).toHaveFocus();
- });
- expect(
- await within(virtualizedContainer).findByText(/transaction-op-9999/i)
- ).toBeInTheDocument();
- await userEvent.keyboard('{arrowdown}', {delay: null});
- await waitFor(() => {
- rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[0]).toHaveFocus();
- });
- expect(
- await within(virtualizedContainer).findByText(/transaction-op-0/i)
- ).toBeInTheDocument();
- });
- it('tab scrolls to next node', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{tab}');
- await waitFor(() => {
- rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[1]).toHaveFocus();
- });
- });
- it('shift+tab scrolls to previous node', async () => {
- const {virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[1]);
- await waitFor(() => expect(rows[1]).toHaveFocus());
- await userEvent.keyboard('{Shift>}{tab}{/Shift}');
- await waitFor(() => {
- rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[0]).toHaveFocus();
- });
- });
- it('arrowdown+shift scrolls to the end of the list', async () => {
- const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
- expect(
- await findByText(virtualizedContainer, /transaction-op-9999/i)
- ).toBeInTheDocument();
- await waitFor(() => {
- rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[rows.length - 1]).toHaveFocus();
- });
- });
- it('arrowup+shift scrolls to the start of the list', async () => {
- const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
- let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- await userEvent.click(rows[0]);
- await waitFor(() => expect(rows[0]).toHaveFocus());
- await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
- expect(
- await findByText(virtualizedContainer, /transaction-op-9999/i)
- ).toBeInTheDocument();
- await waitFor(() => {
- rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[rows.length - 1]).toHaveFocus();
- });
- await userEvent.keyboard('{Shift>}{arrowup}{/Shift}');
- expect(
- await findByText(virtualizedContainer, /transaction-op-0/i)
- ).toBeInTheDocument();
- await scrollToEnd();
- await waitFor(() => {
- rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(rows[0]).toHaveFocus();
- });
- });
- });
- describe('search', () => {
- it('searches in transaction', async () => {
- const {container} = await searchTestSetup();
- let rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
- await waitFor(() => {
- const highlighted_row = container.querySelector(
- '.TraceRow:not(.Hidden).SearchResult.Highlight'
- );
- rows = Array.from(container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR));
- expect(rows.indexOf(highlighted_row!)).toBe(1);
- });
- });
- it('supports roving with arrowup and arrowdown', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
- // Wait for the search results to resolve
- await searchToUpdate();
- for (const action of [
- // starting at the top, jumpt bottom with shift+arrowdown
- ['{Shift>}{arrowdown}{/Shift}', 11],
- // // move to row above with arrowup
- ['{arrowup}', 10],
- // // and jump back to top with shift+arrowup
- ['{Shift>}{arrowup}{/Shift}', 1],
- // // // and jump to next row with arrowdown
- ['{arrowdown}', 2],
- ] as const) {
- await userEvent.keyboard(action[0] as string);
- // assert that focus on search input is never lost
- expect(searchInput).toHaveFocus();
- await waitFor(() => {
- // Only a single row is highlighted, the rest are search results
- assertHighlightedRowAtIndex(container, action[1]);
- });
- }
- });
- it('search roving updates the element in the drawer', async () => {
- await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
- // Wait for the search results to resolve
- await searchToUpdate();
- expect(await screen.findByTestId('trace-drawer-title')).toHaveTextContent(
- 'transaction-op-0'
- );
- // assert that focus on search input is never lost
- expect(searchInput).toHaveFocus();
- await userEvent.keyboard('{arrowdown}');
- await waitFor(() => {
- expect(screen.getByTestId('trace-drawer-title')).toHaveTextContent(
- 'transaction-op-1'
- );
- });
- });
- it('highlighted node narrows down on the first result', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
- // Wait for the search results to resolve
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 2);
- fireEvent.change(searchInput, {target: {value: 'transaction-op-10'}});
- await searchToUpdate();
- await waitFor(() => {
- assertHighlightedRowAtIndex(container, 11);
- });
- });
- it('highlighted is persisted on node while it is part of the search results', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'trans'}});
- // Wait for the search results to resolve
- await searchToUpdate();
- await userEvent.keyboard('{arrowdown}');
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 2);
- fireEvent.change(searchInput, {target: {value: 'transa'}});
- await searchToUpdate();
- // Highlighting is persisted on the row
- assertHighlightedRowAtIndex(container, 2);
- fireEvent.change(searchInput, {target: {value: 'this wont match anything'}});
- await searchToUpdate();
- // When there is no match, the highlighting is removed
- expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
- });
- it('auto highlights the first result when search begins', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Nothing is highlighted
- expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 't'}});
- // Wait for the search results to resolve
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 1);
- });
- it('clicking a row that is also a search result updates the result index', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'transaction-op-1'}});
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 2);
- const rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- // By default, we highlight the first result
- expect(await screen.findByTestId('trace-search-result-iterator')).toHaveTextContent(
- '1/2'
- );
- await scrollToEnd();
- // Click on a random row in the list that is not a search result
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '-/2'
- );
- });
- await scrollToEnd();
- // Click on a the row in the list that is a search result
- await userEvent.click(rows[2]);
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '1/2'
- );
- });
- });
- it('during search, expanding a row retriggers search', async () => {
- mockTraceRootFacets();
- mockTraceRootEvent('0');
- mockTraceEventDetails();
- mockMetricsResponse();
- mockTraceResponse({
- body: {
- transactions: [
- makeTransaction({
- span_id: '0',
- event_id: '0',
- transaction: 'transaction-name-0',
- 'transaction.op': 'transaction-op-0',
- project_slug: 'project_slug',
- }),
- makeTransaction({
- span_id: '1',
- event_id: '1',
- transaction: 'transaction-name-1',
- 'transaction.op': 'transaction-op-1',
- project_slug: 'project_slug',
- }),
- makeTransaction({
- span_id: '2',
- event_id: '2',
- transaction: 'transaction-name-2',
- 'transaction.op': 'transaction-op-2',
- project_slug: 'project_slug',
- }),
- makeTransaction({
- span_id: '3',
- event_id: '3',
- transaction: 'transaction-name-3',
- 'transaction.op': 'transaction-op-3',
- project_slug: 'project_slug',
- }),
- ],
- orphan_errors: [],
- },
- });
- mockTraceMetaResponse({
- body: {
- errors: 0,
- performance_issues: 0,
- projects: 0,
- transactions: 0,
- transaction_child_count_map: [
- {
- 'transaction.id': '0',
- count: 5,
- },
- {
- 'transaction.id': '1',
- count: 5,
- },
- {
- 'transaction.id': '2',
- count: 5,
- },
- {
- 'transaction.id': '3',
- count: 5,
- },
- ],
- },
- });
- const spansRequest = mockSpansResponse(
- '0',
- {},
- {
- entries: [
- {
- type: EntryType.SPANS,
- data: [
- makeSpan({span_id: '0', description: 'span-description', op: 'op-0'}),
- ],
- },
- ],
- }
- );
- const {container} = render(<TraceView />, {router});
- // Awaits for the placeholder rendering rows to be removed
- expect(await findByText(container, /transaction-op-0/i)).toBeInTheDocument();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'op-0'}});
- await searchToUpdate();
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '1/1'
- );
- });
- const open = await screen.findAllByRole('button', {name: '+'});
- await userEvent.click(open[0]);
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '1/1'
- );
- });
- expect(await screen.findByText('span-description')).toBeInTheDocument();
- expect(spansRequest).toHaveBeenCalled();
- await waitFor(() => {
- expect(screen.queryByTestId('trace-search-result-iterator')).toHaveTextContent(
- '1/2'
- );
- });
- });
- it('during search, highlighting is persisted on the row', async () => {
- const {container} = await searchTestSetup();
- const searchInput = await screen.findByPlaceholderText('Search in trace');
- await userEvent.click(searchInput);
- // Fire change because userEvent triggers this letter by letter
- fireEvent.change(searchInput, {target: {value: 'transaction-op'}});
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 1);
- await searchToUpdate();
- // User moves down the list using keyboard navigation
- for (const _ of [1, 2, 3, 4, 5]) {
- const initial = screen.getByTestId('trace-search-result-iterator').textContent;
- await userEvent.keyboard('{arrowDown}');
- await waitFor(() => {
- expect(screen.getByTestId('trace-search-result-iterator')).not.toBe(initial);
- });
- }
- // User clicks on an entry in the list, then proceeds to search
- await waitFor(() => {
- expect(screen.getByTestId('trace-search-result-iterator')).toHaveTextContent(
- '6/11'
- );
- });
- // And then continues the query - the highlighting is preserved as long as the
- // rwo is part of the search results
- assertHighlightedRowAtIndex(container, 6);
- fireEvent.change(searchInput, {target: {value: 'transaction-op-'}});
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 6);
- fireEvent.change(searchInput, {target: {value: 'transaction-op-5'}});
- await searchToUpdate();
- assertHighlightedRowAtIndex(container, 6);
- fireEvent.change(searchInput, {target: {value: 'transaction-op-none'}});
- await searchToUpdate();
- expect(container.querySelectorAll('.TraceRow.Highlight')).toHaveLength(0);
- });
- });
- describe('tabbing', () => {
- beforeEach(() => {});
- afterEach(() => {
- jest.restoreAllMocks();
- });
- it('clicking on a node spawns a new tab when none is selected', async () => {
- const {virtualizedContainer} = await simpleTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- });
- });
- it('clicking on a node replaces the previously selected tab', async () => {
- const {virtualizedContainer} = await simpleTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- expect(
- screen
- .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
- .textContent?.includes('transaction-op-4')
- ).toBeTruthy();
- });
- await userEvent.click(rows[7]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- expect(
- screen
- .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
- .textContent?.includes('transaction-op-6')
- ).toBeTruthy();
- });
- });
- it('pinning a tab and clicking on a new node spawns a new tab', async () => {
- const {virtualizedContainer} = await simpleTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- });
- await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
- await userEvent.click(rows[7]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
- expect(
- screen
- .queryAllByTestId(DRAWER_TABS_TEST_ID)[1]
- .textContent?.includes('transaction-op-4')
- ).toBeTruthy();
- expect(
- screen
- .queryAllByTestId(DRAWER_TABS_TEST_ID)[2]
- .textContent?.includes('transaction-op-6')
- ).toBeTruthy();
- });
- });
- it('unpinning a tab removes it', async () => {
- const {virtualizedContainer} = await simpleTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- });
- await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
- await userEvent.click(rows[7]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
- });
- const tabButtons = screen.queryAllByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID);
- expect(tabButtons).toHaveLength(2);
- await userEvent.click(tabButtons[0]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- });
- });
- it('clicking a node that is already open in a tab switches to that tab and persists the previous node', async () => {
- const {virtualizedContainer} = await simpleTestSetup();
- const rows = virtualizedContainer.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(1);
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(2);
- });
- await userEvent.click(await screen.findByTestId(DRAWER_TABS_PIN_BUTTON_TEST_ID));
- await userEvent.click(rows[7]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[2]).toHaveAttribute(
- 'aria-selected',
- 'true'
- );
- });
- await userEvent.click(rows[5]);
- await waitFor(() => {
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)[1]).toHaveAttribute(
- 'aria-selected',
- 'true'
- );
- expect(screen.queryAllByTestId(DRAWER_TABS_TEST_ID)).toHaveLength(3);
- });
- });
- });
- });
|