mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 13:34:15 -07:00
Code review comments as a pr (#21209)
This commit is contained in:
@@ -81,6 +81,8 @@ describe('useSelectionList', () => {
|
||||
isFocused?: boolean;
|
||||
showNumbers?: boolean;
|
||||
wrapAround?: boolean;
|
||||
focusKey?: string;
|
||||
priority?: boolean;
|
||||
}) => {
|
||||
let hookResult: ReturnType<typeof useSelectionList>;
|
||||
function TestComponent(props: typeof initialProps) {
|
||||
@@ -771,6 +773,67 @@ describe('useSelectionList', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Programmatic Focus (focusKey)', () => {
|
||||
it('should change the activeIndex when a valid focusKey is provided', async () => {
|
||||
const { result, rerender, waitUntilReady } =
|
||||
await renderSelectionListHook({
|
||||
items,
|
||||
onSelect: mockOnSelect,
|
||||
});
|
||||
expect(result.current.activeIndex).toBe(0);
|
||||
|
||||
await rerender({ focusKey: 'C' });
|
||||
await waitUntilReady();
|
||||
expect(result.current.activeIndex).toBe(2);
|
||||
});
|
||||
|
||||
it('should ignore a focusKey that does not exist', async () => {
|
||||
const { result, rerender, waitUntilReady } =
|
||||
await renderSelectionListHook({
|
||||
items,
|
||||
onSelect: mockOnSelect,
|
||||
});
|
||||
expect(result.current.activeIndex).toBe(0);
|
||||
|
||||
await rerender({ focusKey: 'UNKNOWN' });
|
||||
await waitUntilReady();
|
||||
expect(result.current.activeIndex).toBe(0);
|
||||
});
|
||||
|
||||
it('should ignore a focusKey that points to a disabled item', async () => {
|
||||
const { result, rerender, waitUntilReady } =
|
||||
await renderSelectionListHook({
|
||||
items, // B is disabled
|
||||
onSelect: mockOnSelect,
|
||||
});
|
||||
expect(result.current.activeIndex).toBe(0);
|
||||
|
||||
await rerender({ focusKey: 'B' });
|
||||
await waitUntilReady();
|
||||
expect(result.current.activeIndex).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle clearing the focusKey', async () => {
|
||||
const { result, rerender, waitUntilReady } =
|
||||
await renderSelectionListHook({
|
||||
items,
|
||||
onSelect: mockOnSelect,
|
||||
focusKey: 'C',
|
||||
});
|
||||
expect(result.current.activeIndex).toBe(2);
|
||||
|
||||
await rerender({ focusKey: undefined });
|
||||
await waitUntilReady();
|
||||
// Should remain at 2
|
||||
expect(result.current.activeIndex).toBe(2);
|
||||
|
||||
// We can then change it again to something else
|
||||
await rerender({ focusKey: 'D' });
|
||||
await waitUntilReady();
|
||||
expect(result.current.activeIndex).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Reactivity (Dynamic Updates)', () => {
|
||||
it('should update activeIndex when initialIndex prop changes', async () => {
|
||||
const { result, rerender } = await renderSelectionListHook({
|
||||
|
||||
@@ -213,8 +213,7 @@ function selectionListReducer(
|
||||
case 'INITIALIZE': {
|
||||
const { initialIndex, items, wrapAround } = action.payload;
|
||||
const activeKey =
|
||||
initialIndex === state.initialIndex &&
|
||||
state.activeIndex !== state.initialIndex
|
||||
initialIndex === state.initialIndex
|
||||
? state.items[state.activeIndex]?.key
|
||||
: undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user