mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-14 13:27:38 -07:00
test(cli): refactor tests for async render utilities (#23252)
This commit is contained in:
committed by
GitHub
parent
86a3a913b5
commit
6c78eb7a39
@@ -129,14 +129,13 @@ describe('TextInput', () => {
|
||||
handleInput: vi.fn(),
|
||||
setText: vi.fn(),
|
||||
};
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
const { lastFrame, unmount } = await render(
|
||||
<TextInput
|
||||
buffer={buffer as unknown as TextBuffer}
|
||||
onSubmit={onSubmit}
|
||||
onCancel={onCancel}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('test');
|
||||
unmount();
|
||||
});
|
||||
@@ -151,7 +150,7 @@ describe('TextInput', () => {
|
||||
handleInput: vi.fn(),
|
||||
setText: vi.fn(),
|
||||
};
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
const { lastFrame, unmount } = await render(
|
||||
<TextInput
|
||||
buffer={buffer as unknown as TextBuffer}
|
||||
placeholder="testing"
|
||||
@@ -159,16 +158,14 @@ describe('TextInput', () => {
|
||||
onCancel={onCancel}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('testing');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('handles character input', async () => {
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -197,10 +194,9 @@ describe('TextInput', () => {
|
||||
|
||||
it('handles backspace', async () => {
|
||||
mockBuffer.setText('test');
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -229,10 +225,9 @@ describe('TextInput', () => {
|
||||
|
||||
it('handles left arrow', async () => {
|
||||
mockBuffer.setText('test');
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -255,10 +250,9 @@ describe('TextInput', () => {
|
||||
it('handles right arrow', async () => {
|
||||
mockBuffer.setText('test');
|
||||
mockBuffer.visualCursor[1] = 2; // Set initial cursor for right arrow test
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -279,10 +273,9 @@ describe('TextInput', () => {
|
||||
|
||||
it('calls onSubmit on return', async () => {
|
||||
mockBuffer.setText('test');
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -306,10 +299,9 @@ describe('TextInput', () => {
|
||||
const realContent = 'line1\nline2\nline3\nline4\nline5\nline6';
|
||||
mockBuffer.setText(placeholder);
|
||||
mockBuffer.pastedContent = { [placeholder]: realContent };
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -331,10 +323,9 @@ describe('TextInput', () => {
|
||||
it('submits text unchanged when pastedContent is empty', async () => {
|
||||
mockBuffer.setText('normal text');
|
||||
mockBuffer.pastedContent = {};
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -355,10 +346,9 @@ describe('TextInput', () => {
|
||||
|
||||
it('calls onCancel on escape', async () => {
|
||||
vi.useFakeTimers();
|
||||
const { waitUntilReady, unmount } = render(
|
||||
const { waitUntilReady, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onCancel={onCancel} onSubmit={onSubmit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -385,17 +375,16 @@ describe('TextInput', () => {
|
||||
|
||||
it('renders the input value', async () => {
|
||||
mockBuffer.setText('secret');
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
const { lastFrame, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('secret');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('does not show cursor when not focused', async () => {
|
||||
mockBuffer.setText('test');
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
const { lastFrame, unmount } = await render(
|
||||
<TextInput
|
||||
buffer={mockBuffer}
|
||||
focus={false}
|
||||
@@ -403,7 +392,6 @@ describe('TextInput', () => {
|
||||
onCancel={onCancel}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).not.toContain('\u001b[7m'); // Inverse video chalk
|
||||
unmount();
|
||||
});
|
||||
@@ -412,10 +400,9 @@ describe('TextInput', () => {
|
||||
mockBuffer.text = 'line1\nline2';
|
||||
mockBuffer.viewportVisualLines = ['line1', 'line2'];
|
||||
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
const { lastFrame, unmount } = await render(
|
||||
<TextInput buffer={mockBuffer} onSubmit={onSubmit} onCancel={onCancel} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('line1');
|
||||
expect(lastFrame()).toContain('line2');
|
||||
|
||||
Reference in New Issue
Block a user