mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
Revamp KeypressContext (#12746)
This commit is contained in:
committed by
GitHub
parent
f649948713
commit
9e4ae214a8
@@ -55,7 +55,7 @@ describe('useFocus', () => {
|
||||
return null;
|
||||
}
|
||||
const { unmount } = render(
|
||||
<KeypressProvider kittyProtocolEnabled={false}>
|
||||
<KeypressProvider>
|
||||
<TestComponent />
|
||||
</KeypressProvider>,
|
||||
);
|
||||
@@ -84,7 +84,7 @@ describe('useFocus', () => {
|
||||
|
||||
// Simulate focus-out event
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[O'));
|
||||
stdin.emit('data', '\x1b[O');
|
||||
});
|
||||
|
||||
// State should now be unfocused
|
||||
@@ -96,13 +96,13 @@ describe('useFocus', () => {
|
||||
|
||||
// Simulate focus-out to set initial state to false
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[O'));
|
||||
stdin.emit('data', '\x1b[O');
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
// Simulate focus-in event
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[I'));
|
||||
stdin.emit('data', '\x1b[I');
|
||||
});
|
||||
|
||||
// State should now be focused
|
||||
@@ -128,22 +128,22 @@ describe('useFocus', () => {
|
||||
const { result } = renderFocusHook();
|
||||
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[O'));
|
||||
stdin.emit('data', '\x1b[O');
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[O'));
|
||||
stdin.emit('data', '\x1b[O');
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[I'));
|
||||
stdin.emit('data', '\x1b[I');
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[I'));
|
||||
stdin.emit('data', '\x1b[I');
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
@@ -153,13 +153,13 @@ describe('useFocus', () => {
|
||||
|
||||
// Simulate focus-out event
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('\x1b[O'));
|
||||
stdin.emit('data', '\x1b[O');
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
// Simulate a keypress
|
||||
act(() => {
|
||||
stdin.emit('data', Buffer.from('a'));
|
||||
stdin.emit('data', 'a');
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ class MockStdin extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
|
||||
describe(`useKeypress with useKitty=%s`, () => {
|
||||
let stdin: MockStdin;
|
||||
const mockSetRawMode = vi.fn();
|
||||
const onKeypress = vi.fn();
|
||||
@@ -50,7 +50,7 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
|
||||
return null;
|
||||
}
|
||||
return render(
|
||||
<KeypressProvider kittyProtocolEnabled={useKitty}>
|
||||
<KeypressProvider>
|
||||
<TestComponent />
|
||||
</KeypressProvider>,
|
||||
);
|
||||
@@ -196,20 +196,13 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
|
||||
stdin.write('do');
|
||||
});
|
||||
|
||||
if (useKitty) {
|
||||
vi.advanceTimersByTime(60); // wait for kitty timeout
|
||||
expect(onKeypress).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({ sequence: '\x1B[200do' }),
|
||||
);
|
||||
} else {
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sequence: '\x1B[200d' }),
|
||||
);
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sequence: 'o' }),
|
||||
);
|
||||
expect(onKeypress).toHaveBeenCalledTimes(2);
|
||||
}
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sequence: '\x1B[200d' }),
|
||||
);
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sequence: 'o' }),
|
||||
);
|
||||
expect(onKeypress).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should handle back to back pastes', () => {
|
||||
@@ -249,11 +242,11 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
|
||||
const pasteText = 'pasted';
|
||||
await act(async () => {
|
||||
stdin.write(PASTE_START.slice(0, 3));
|
||||
vi.advanceTimersByTime(50);
|
||||
vi.advanceTimersByTime(40);
|
||||
stdin.write(PASTE_START.slice(3) + pasteText.slice(0, 3));
|
||||
vi.advanceTimersByTime(50);
|
||||
vi.advanceTimersByTime(40);
|
||||
stdin.write(pasteText.slice(3) + PASTE_END.slice(0, 3));
|
||||
vi.advanceTimersByTime(50);
|
||||
vi.advanceTimersByTime(40);
|
||||
stdin.write(PASTE_END.slice(3));
|
||||
});
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
|
||||
Reference in New Issue
Block a user