mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-22 01:07:12 -07:00
fix(cli): ensure dialogs stay scrolled to bottom in alternate buffer mode (#20527)
This commit is contained in:
@@ -6,20 +6,11 @@
|
||||
|
||||
import { renderWithProviders } from '../../../test-utils/render.js';
|
||||
import { Scrollable } from './Scrollable.js';
|
||||
import { Text } from 'ink';
|
||||
import { Text, Box } from 'ink';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import * as ScrollProviderModule from '../../contexts/ScrollProvider.js';
|
||||
import { act } from 'react';
|
||||
|
||||
vi.mock('ink', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('ink')>();
|
||||
return {
|
||||
...actual,
|
||||
getInnerHeight: vi.fn(() => 5),
|
||||
getScrollHeight: vi.fn(() => 10),
|
||||
getBoundingBox: vi.fn(() => ({ x: 0, y: 0, width: 10, height: 5 })),
|
||||
};
|
||||
});
|
||||
import { waitFor } from '../../../test-utils/async.js';
|
||||
|
||||
vi.mock('../../hooks/useAnimatedScrollbar.js', () => ({
|
||||
useAnimatedScrollbar: (
|
||||
@@ -129,20 +120,26 @@ describe('<Scrollable />', () => {
|
||||
</Scrollable>,
|
||||
);
|
||||
await waitUntilReady2();
|
||||
expect(capturedEntry.getScrollState().scrollTop).toBe(5);
|
||||
await waitFor(() => {
|
||||
expect(capturedEntry?.getScrollState().scrollTop).toBe(5);
|
||||
});
|
||||
|
||||
// Call scrollBy multiple times (upwards) in the same tick
|
||||
await act(async () => {
|
||||
capturedEntry!.scrollBy(-1);
|
||||
capturedEntry!.scrollBy(-1);
|
||||
capturedEntry?.scrollBy(-1);
|
||||
capturedEntry?.scrollBy(-1);
|
||||
});
|
||||
// Should have moved up by 2 (5 -> 3)
|
||||
expect(capturedEntry.getScrollState().scrollTop).toBe(3);
|
||||
await waitFor(() => {
|
||||
expect(capturedEntry?.getScrollState().scrollTop).toBe(3);
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
capturedEntry!.scrollBy(-2);
|
||||
capturedEntry?.scrollBy(-2);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(capturedEntry?.getScrollState().scrollTop).toBe(1);
|
||||
});
|
||||
expect(capturedEntry.getScrollState().scrollTop).toBe(1);
|
||||
unmount2();
|
||||
});
|
||||
|
||||
@@ -191,10 +188,6 @@ describe('<Scrollable />', () => {
|
||||
keySequence,
|
||||
expectedScrollTop,
|
||||
}) => {
|
||||
// Dynamically import ink to mock getScrollHeight
|
||||
const ink = await import('ink');
|
||||
vi.mocked(ink.getScrollHeight).mockReturnValue(scrollHeight);
|
||||
|
||||
let capturedEntry: ScrollProviderModule.ScrollableEntry | undefined;
|
||||
vi.spyOn(ScrollProviderModule, 'useScrollable').mockImplementation(
|
||||
async (entry, isActive) => {
|
||||
@@ -206,7 +199,9 @@ describe('<Scrollable />', () => {
|
||||
|
||||
const { stdin, waitUntilReady, unmount } = renderWithProviders(
|
||||
<Scrollable hasFocus={true} height={5}>
|
||||
<Text>Content</Text>
|
||||
<Box height={scrollHeight}>
|
||||
<Text>Content</Text>
|
||||
</Box>
|
||||
</Scrollable>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
Reference in New Issue
Block a user