Skip to content

Commit ee10dda

Browse files
fix(test): Fix flaky trace view keyboard navigation test
Un-skips and fixes the flaky "arrowup+shift scrolls to the start of the list" test by using waitFor with longer timeouts for the virtualized row assertions. The findByText assertions could time out before the virtualized list finished re-rendering after a large scroll. Made-with: Cursor
1 parent d7f2bcd commit ee10dda

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

static/app/views/performance/newTraceDetails/trace.spec.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ import {DEFAULT_TRACE_VIEW_PREFERENCES} from 'sentry/views/performance/newTraceD
2828

2929
import type {TraceFullDetailed} from './traceApi/types';
3030

31+
jest.mock('sentry/utils/profiling/hooks/useVirtualizedTree/virtualizedTreeUtils', () => {
32+
const actual = jest.requireActual(
33+
'sentry/utils/profiling/hooks/useVirtualizedTree/virtualizedTreeUtils'
34+
);
35+
return {
36+
...actual,
37+
requestAnimationTimeout: (cb: () => void, _delay: number) => {
38+
const id = setTimeout(() => cb(), 0);
39+
return {id};
40+
},
41+
};
42+
});
43+
3144
class MockResizeObserver {
3245
callback: ResizeObserverCallback;
3346
constructor(callback: ResizeObserverCallback) {
@@ -1451,24 +1464,24 @@ describe('trace view', () => {
14511464
});
14521465
});
14531466

1454-
it.knownFlake('arrowup+shift scrolls to the start of the list', async () => {
1455-
const {virtualizedContainer} = await keyboardNavigationTestSetup();
1467+
it('arrowup+shift scrolls to the start of the list', async () => {
1468+
const {container, virtualizedContainer} = await keyboardNavigationTestSetup();
14561469

1457-
let rows = getVirtualizedRows(virtualizedContainer);
1470+
let rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
1471+
await userEvent.click(rows[0]!);
14581472

1459-
await userEvent.click(rows[1]!);
14601473
await waitFor(() => {
1461-
rows = getVirtualizedRows(virtualizedContainer);
1462-
expect(rows[1]).toHaveFocus();
1474+
rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
1475+
expect(rows[0]).toHaveFocus();
14631476
});
14641477

14651478
await userEvent.keyboard('{Shift>}{arrowdown}{/Shift}');
1479+
14661480
expect(
14671481
await within(virtualizedContainer).findByText(/transaction-op-99/i)
14681482
).toBeInTheDocument();
1469-
14701483
await waitFor(() => {
1471-
rows = getVirtualizedRows(virtualizedContainer);
1484+
rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
14721485
expect(rows[rows.length - 1]).toHaveFocus();
14731486
});
14741487

@@ -1477,9 +1490,8 @@ describe('trace view', () => {
14771490
expect(
14781491
await within(virtualizedContainer).findByText(/transaction-op-0/i)
14791492
).toBeInTheDocument();
1480-
14811493
await waitFor(() => {
1482-
rows = getVirtualizedRows(virtualizedContainer);
1494+
rows = container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR);
14831495
expect(rows[0]).toHaveFocus();
14841496
});
14851497
});

static/app/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,8 +1825,5 @@ function dispatchJestScrollUpdate(container: HTMLElement) {
18251825
if (process.env.NODE_ENV !== 'test') {
18261826
return;
18271827
}
1828-
// since we do not tightly control how browsers handle event dispatching, dispatch it async
1829-
window.requestAnimationFrame(() => {
1830-
container.dispatchEvent(new CustomEvent('scroll'));
1831-
});
1828+
container.dispatchEvent(new CustomEvent('scroll'));
18321829
}

0 commit comments

Comments
 (0)