summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-08-12 14:05:49 -0700
committerGitHub <[email protected]>2025-08-12 21:05:49 +0000
commitd219f9013206aad5a1361e436ad4a45114e9cd49 (patch)
tree58216dc659e809bc896b03de21a9a1c713126d6b /packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts
parent74fd0841d0d7148127e586fce4c550a01ff40e90 (diff)
Switch from useInput to useKeypress. (#6056)
Diffstat (limited to 'packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts70
1 files changed, 47 insertions, 23 deletions
diff --git a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts
index bda6c259..657d792b 100644
--- a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts
+++ b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.test.ts
@@ -21,9 +21,9 @@ import {
Config as ActualConfigType,
ApprovalMode,
} from '@google/gemini-cli-core';
-import { useInput, type Key as InkKey } from 'ink';
+import { useKeypress, Key } from './useKeypress.js';
-vi.mock('ink');
+vi.mock('./useKeypress.js');
vi.mock('@google/gemini-cli-core', async () => {
const actualServerModule = (await vi.importActual(
@@ -53,13 +53,12 @@ interface MockConfigInstanceShape {
getToolRegistry: Mock<() => { discoverTools: Mock<() => void> }>;
}
-type UseInputKey = InkKey;
-type UseInputHandler = (input: string, key: UseInputKey) => void;
+type UseKeypressHandler = (key: Key) => void;
describe('useAutoAcceptIndicator', () => {
let mockConfigInstance: MockConfigInstanceShape;
- let capturedUseInputHandler: UseInputHandler;
- let mockedInkUseInput: MockedFunction<typeof useInput>;
+ let capturedUseKeypressHandler: UseKeypressHandler;
+ let mockedUseKeypress: MockedFunction<typeof useKeypress>;
beforeEach(() => {
vi.resetAllMocks();
@@ -111,10 +110,12 @@ describe('useAutoAcceptIndicator', () => {
return instance;
});
- mockedInkUseInput = useInput as MockedFunction<typeof useInput>;
- mockedInkUseInput.mockImplementation((handler: UseInputHandler) => {
- capturedUseInputHandler = handler;
- });
+ mockedUseKeypress = useKeypress as MockedFunction<typeof useKeypress>;
+ mockedUseKeypress.mockImplementation(
+ (handler: UseKeypressHandler, _options) => {
+ capturedUseKeypressHandler = handler;
+ },
+ );
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mockConfigInstance = new (Config as any)() as MockConfigInstanceShape;
@@ -163,7 +164,10 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.DEFAULT);
act(() => {
- capturedUseInputHandler('', { tab: true, shift: true } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'tab',
+ shift: true,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.AUTO_EDIT,
@@ -171,7 +175,7 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.AUTO_EDIT);
act(() => {
- capturedUseInputHandler('y', { ctrl: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'y', ctrl: true } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.YOLO,
@@ -179,7 +183,7 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.YOLO);
act(() => {
- capturedUseInputHandler('y', { ctrl: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'y', ctrl: true } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.DEFAULT,
@@ -187,7 +191,7 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.DEFAULT);
act(() => {
- capturedUseInputHandler('y', { ctrl: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'y', ctrl: true } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.YOLO,
@@ -195,7 +199,10 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.YOLO);
act(() => {
- capturedUseInputHandler('', { tab: true, shift: true } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'tab',
+ shift: true,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.AUTO_EDIT,
@@ -203,7 +210,10 @@ describe('useAutoAcceptIndicator', () => {
expect(result.current).toBe(ApprovalMode.AUTO_EDIT);
act(() => {
- capturedUseInputHandler('', { tab: true, shift: true } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'tab',
+ shift: true,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).toHaveBeenCalledWith(
ApprovalMode.DEFAULT,
@@ -220,37 +230,51 @@ describe('useAutoAcceptIndicator', () => {
);
act(() => {
- capturedUseInputHandler('', { tab: true, shift: false } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'tab',
+ shift: false,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('', { tab: false, shift: true } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'unknown',
+ shift: true,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('a', { tab: false, shift: false } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'a',
+ shift: false,
+ ctrl: false,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('y', { tab: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'y', ctrl: false } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('a', { ctrl: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'a', ctrl: true } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('y', { shift: true } as InkKey);
+ capturedUseKeypressHandler({ name: 'y', shift: true } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
act(() => {
- capturedUseInputHandler('a', { ctrl: true, shift: true } as InkKey);
+ capturedUseKeypressHandler({
+ name: 'a',
+ ctrl: true,
+ shift: true,
+ } as Key);
});
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
});