mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
refactor(cli): integrate real config loading into async test utils (#23040)
This commit is contained in:
committed by
GitHub
parent
7de0616229
commit
23264ced9a
@@ -43,7 +43,7 @@ describe(`useKeypress`, () => {
|
||||
const onKeypress = vi.fn();
|
||||
let originalNodeVersion: string;
|
||||
|
||||
const renderKeypressHook = (isActive = true) =>
|
||||
const renderKeypressHook = async (isActive = true) =>
|
||||
renderHookWithProviders(() => useKeypress(onKeypress, { isActive }));
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -66,8 +66,8 @@ describe(`useKeypress`, () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not listen if isActive is false', () => {
|
||||
renderKeypressHook(false);
|
||||
it('should not listen if isActive is false', async () => {
|
||||
await renderKeypressHook(false);
|
||||
act(() => stdin.write('a'));
|
||||
expect(onKeypress).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -79,28 +79,31 @@ describe(`useKeypress`, () => {
|
||||
{ key: { name: 'up', sequence: '\x1b[A' } },
|
||||
{ key: { name: 'down', sequence: '\x1b[B' } },
|
||||
{ key: { name: 'tab', sequence: '\x1b[Z', shift: true } },
|
||||
])('should listen for keypress when active for key $key.name', ({ key }) => {
|
||||
renderKeypressHook(true);
|
||||
act(() => stdin.write(key.sequence));
|
||||
expect(onKeypress).toHaveBeenCalledWith(expect.objectContaining(key));
|
||||
});
|
||||
])(
|
||||
'should listen for keypress when active for key $key.name',
|
||||
async ({ key }) => {
|
||||
await renderKeypressHook(true);
|
||||
act(() => stdin.write(key.sequence));
|
||||
expect(onKeypress).toHaveBeenCalledWith(expect.objectContaining(key));
|
||||
},
|
||||
);
|
||||
|
||||
it('should set and release raw mode', () => {
|
||||
const { unmount } = renderKeypressHook(true);
|
||||
it('should set and release raw mode', async () => {
|
||||
const { unmount } = await renderKeypressHook(true);
|
||||
expect(mockSetRawMode).toHaveBeenCalledWith(true);
|
||||
unmount();
|
||||
expect(mockSetRawMode).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it('should stop listening after being unmounted', () => {
|
||||
const { unmount } = renderKeypressHook(true);
|
||||
it('should stop listening after being unmounted', async () => {
|
||||
const { unmount } = await renderKeypressHook(true);
|
||||
unmount();
|
||||
act(() => stdin.write('a'));
|
||||
expect(onKeypress).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should correctly identify alt+enter (meta key)', () => {
|
||||
renderKeypressHook(true);
|
||||
it('should correctly identify alt+enter (meta key)', async () => {
|
||||
await renderKeypressHook(true);
|
||||
const key = { name: 'enter', sequence: '\x1B\r' };
|
||||
act(() => stdin.write(key.sequence));
|
||||
expect(onKeypress).toHaveBeenCalledWith(
|
||||
@@ -128,8 +131,8 @@ describe(`useKeypress`, () => {
|
||||
setup();
|
||||
});
|
||||
|
||||
it('should process a paste as a single event', () => {
|
||||
renderKeypressHook(true);
|
||||
it('should process a paste as a single event', async () => {
|
||||
await renderKeypressHook(true);
|
||||
const pasteText = 'hello world';
|
||||
act(() => stdin.write(PASTE_START + pasteText + PASTE_END));
|
||||
|
||||
@@ -145,8 +148,8 @@ describe(`useKeypress`, () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle keypress interspersed with pastes', () => {
|
||||
renderKeypressHook(true);
|
||||
it('should handle keypress interspersed with pastes', async () => {
|
||||
await renderKeypressHook(true);
|
||||
|
||||
const keyA = { name: 'a', sequence: 'a' };
|
||||
act(() => stdin.write('a'));
|
||||
@@ -169,8 +172,8 @@ describe(`useKeypress`, () => {
|
||||
expect(onKeypress).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('should handle lone pastes', () => {
|
||||
renderKeypressHook(true);
|
||||
it('should handle lone pastes', async () => {
|
||||
await renderKeypressHook(true);
|
||||
|
||||
const pasteText = 'pasted';
|
||||
act(() => {
|
||||
@@ -184,7 +187,7 @@ describe(`useKeypress`, () => {
|
||||
});
|
||||
|
||||
it('should handle paste false alarm', async () => {
|
||||
renderKeypressHook(true);
|
||||
await renderKeypressHook(true);
|
||||
|
||||
act(() => {
|
||||
stdin.write(PASTE_START.slice(0, 5));
|
||||
@@ -200,8 +203,8 @@ describe(`useKeypress`, () => {
|
||||
expect(onKeypress).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should handle back to back pastes', () => {
|
||||
renderKeypressHook(true);
|
||||
it('should handle back to back pastes', async () => {
|
||||
await renderKeypressHook(true);
|
||||
|
||||
const pasteText1 = 'herp';
|
||||
const pasteText2 = 'derp';
|
||||
@@ -226,7 +229,7 @@ describe(`useKeypress`, () => {
|
||||
});
|
||||
|
||||
it('should handle pastes split across writes', async () => {
|
||||
renderKeypressHook(true);
|
||||
await renderKeypressHook(true);
|
||||
|
||||
const keyA = { name: 'a', sequence: 'a' };
|
||||
act(() => stdin.write('a'));
|
||||
|
||||
Reference in New Issue
Block a user