mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 10:34:35 -07:00
test(cli): refactor tests for async render utilities (#23252)
This commit is contained in:
committed by
GitHub
parent
86a3a913b5
commit
6c78eb7a39
@@ -48,10 +48,9 @@ describe('FolderTrustDialog', () => {
|
||||
});
|
||||
|
||||
it('should render the dialog with title and description', async () => {
|
||||
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('Do you trust the files in this folder?');
|
||||
expect(lastFrame()).toContain(
|
||||
@@ -72,7 +71,7 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -85,7 +84,6 @@ describe('FolderTrustDialog', () => {
|
||||
},
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('This folder contains:');
|
||||
expect(lastFrame()).toContain('hidden');
|
||||
unmount();
|
||||
@@ -103,7 +101,7 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -116,7 +114,6 @@ describe('FolderTrustDialog', () => {
|
||||
},
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
// With maxHeight=4, the intro text (4 lines) will take most of the space.
|
||||
// The discovery results will likely be hidden.
|
||||
expect(lastFrame()).toContain('hidden');
|
||||
@@ -135,7 +132,7 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -148,7 +145,6 @@ describe('FolderTrustDialog', () => {
|
||||
},
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('hidden');
|
||||
unmount();
|
||||
});
|
||||
@@ -182,9 +178,7 @@ describe('FolderTrustDialog', () => {
|
||||
// Initial state: truncated
|
||||
await waitFor(() => {
|
||||
expect(lastFrame()).toContain('Do you trust the files in this folder?');
|
||||
// In standard terminal mode, the expansion hint is handled globally by ToastDisplay
|
||||
// via AppContainer, so it should not be present in the dialog's local frame.
|
||||
expect(lastFrame()).not.toContain('Press Ctrl+O');
|
||||
expect(lastFrame()).toContain('Press Ctrl+O');
|
||||
expect(lastFrame()).toContain('hidden');
|
||||
});
|
||||
|
||||
@@ -221,7 +215,6 @@ describe('FolderTrustDialog', () => {
|
||||
await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={onSelect} isRestarting={false} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u001b[27u'); // Press kitty escape key
|
||||
@@ -246,10 +239,9 @@ describe('FolderTrustDialog', () => {
|
||||
});
|
||||
|
||||
it('should display restart message when isRestarting is true', async () => {
|
||||
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} isRestarting={true} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('Gemini CLI is restarting');
|
||||
unmount();
|
||||
@@ -260,10 +252,9 @@ describe('FolderTrustDialog', () => {
|
||||
const relaunchApp = vi
|
||||
.spyOn(processUtils, 'relaunchApp')
|
||||
.mockResolvedValue(undefined);
|
||||
const { waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} isRestarting={true} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
await vi.advanceTimersByTimeAsync(250);
|
||||
expect(relaunchApp).toHaveBeenCalled();
|
||||
unmount();
|
||||
@@ -275,10 +266,9 @@ describe('FolderTrustDialog', () => {
|
||||
const relaunchApp = vi
|
||||
.spyOn(processUtils, 'relaunchApp')
|
||||
.mockResolvedValue(undefined);
|
||||
const { waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} isRestarting={true} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
// Unmount immediately (before 250ms)
|
||||
unmount();
|
||||
@@ -292,7 +282,6 @@ describe('FolderTrustDialog', () => {
|
||||
const { stdin, waitUntilReady, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} isRestarting={false} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('r');
|
||||
@@ -308,30 +297,27 @@ describe('FolderTrustDialog', () => {
|
||||
describe('directory display', () => {
|
||||
it('should correctly display the folder name for a nested directory', async () => {
|
||||
mockedCwd.mockReturnValue('/home/user/project');
|
||||
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Trust folder (project)');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should correctly display the parent folder name for a nested directory', async () => {
|
||||
mockedCwd.mockReturnValue('/home/user/project');
|
||||
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Trust parent folder (user)');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should correctly display an empty parent folder name for a directory directly under root', async () => {
|
||||
mockedCwd.mockReturnValue('/project');
|
||||
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Trust parent folder ()');
|
||||
unmount();
|
||||
});
|
||||
@@ -348,7 +334,7 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -356,7 +342,6 @@ describe('FolderTrustDialog', () => {
|
||||
{ width: 80 },
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('This folder contains:');
|
||||
expect(lastFrame()).toContain('• Commands (2):');
|
||||
expect(lastFrame()).toContain('- cmd1');
|
||||
@@ -386,14 +371,13 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: ['Dangerous setting detected!'],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
/>,
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Security Warnings:');
|
||||
expect(lastFrame()).toContain('Dangerous setting detected!');
|
||||
unmount();
|
||||
@@ -410,14 +394,13 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: ['Failed to load custom commands'],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
/>,
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Discovery Errors:');
|
||||
expect(lastFrame()).toContain('Failed to load custom commands');
|
||||
unmount();
|
||||
@@ -434,7 +417,7 @@ describe('FolderTrustDialog', () => {
|
||||
discoveryErrors: [],
|
||||
securityWarnings: [],
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -447,7 +430,6 @@ describe('FolderTrustDialog', () => {
|
||||
},
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
// In alternate buffer + expanded, the title should be visible (StickyHeader)
|
||||
expect(lastFrame()).toContain('Do you trust the files in this folder?');
|
||||
// And it should NOT use MaxSizedBox truncation
|
||||
@@ -470,7 +452,7 @@ describe('FolderTrustDialog', () => {
|
||||
securityWarnings: [`${ansiRed}warning-with-ansi${ansiReset}`],
|
||||
};
|
||||
|
||||
const { lastFrame, unmount, waitUntilReady } = await renderWithProviders(
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<FolderTrustDialog
|
||||
onSelect={vi.fn()}
|
||||
discoveryResults={discoveryResults}
|
||||
@@ -478,7 +460,6 @@ describe('FolderTrustDialog', () => {
|
||||
{ width: 100, uiState: { terminalHeight: 40 } },
|
||||
);
|
||||
|
||||
await waitUntilReady();
|
||||
const output = lastFrame();
|
||||
|
||||
expect(output).toContain('cmd-with-ansi');
|
||||
|
||||
Reference in New Issue
Block a user