mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
Migrate core render util to use xterm.js as part of the rendering loop. (#19044)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { CloudFreePrivacyNotice } from './CloudFreePrivacyNotice.js';
|
||||
import { usePrivacySettings } from '../hooks/usePrivacySettings.js';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
@@ -75,17 +76,19 @@ describe('CloudFreePrivacyNotice', () => {
|
||||
mockState: { isFreeTier: true },
|
||||
expectedText: 'Gemini Code Assist for Individuals Privacy Notice',
|
||||
},
|
||||
])('renders correctly in $stateName', ({ mockState, expectedText }) => {
|
||||
])('renders correctly in $stateName', async ({ mockState, expectedText }) => {
|
||||
mockedUsePrivacySettings.mockReturnValue({
|
||||
privacyState: { ...defaultState, ...mockState },
|
||||
updateDataCollectionOptIn,
|
||||
});
|
||||
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
<CloudFreePrivacyNotice config={mockConfig} onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain(expectedText);
|
||||
unmount();
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -106,22 +109,32 @@ describe('CloudFreePrivacyNotice', () => {
|
||||
},
|
||||
])(
|
||||
'exits on Escape in $stateName: $shouldExit',
|
||||
({ mockState, shouldExit }) => {
|
||||
async ({ mockState, shouldExit }) => {
|
||||
mockedUsePrivacySettings.mockReturnValue({
|
||||
privacyState: { ...defaultState, ...mockState },
|
||||
updateDataCollectionOptIn,
|
||||
});
|
||||
|
||||
render(<CloudFreePrivacyNotice config={mockConfig} onExit={onExit} />);
|
||||
const { waitUntilReady, unmount } = render(
|
||||
<CloudFreePrivacyNotice config={mockConfig} onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
keypressHandler({ name: 'escape' });
|
||||
await act(async () => {
|
||||
keypressHandler({ name: 'escape' });
|
||||
});
|
||||
// Escape key has a 50ms timeout in KeypressContext, so we need to wrap waitUntilReady in act
|
||||
await act(async () => {
|
||||
await waitUntilReady();
|
||||
});
|
||||
|
||||
if (shouldExit) {
|
||||
expect(onExit).toHaveBeenCalled();
|
||||
} else {
|
||||
expect(onExit).not.toHaveBeenCalled();
|
||||
}
|
||||
unmount();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -129,14 +142,25 @@ describe('CloudFreePrivacyNotice', () => {
|
||||
it.each([
|
||||
{ selection: true, label: 'Yes' },
|
||||
{ selection: false, label: 'No' },
|
||||
])('calls correct functions on selecting "$label"', ({ selection }) => {
|
||||
render(<CloudFreePrivacyNotice config={mockConfig} onExit={onExit} />);
|
||||
])(
|
||||
'calls correct functions on selecting "$label"',
|
||||
async ({ selection }) => {
|
||||
const { waitUntilReady, unmount } = render(
|
||||
<CloudFreePrivacyNotice config={mockConfig} onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
const onSelectHandler = mockedRadioButtonSelect.mock.calls[0][0].onSelect;
|
||||
onSelectHandler(selection);
|
||||
const onSelectHandler =
|
||||
mockedRadioButtonSelect.mock.calls[0][0].onSelect;
|
||||
await act(async () => {
|
||||
onSelectHandler(selection);
|
||||
});
|
||||
await waitUntilReady();
|
||||
|
||||
expect(updateDataCollectionOptIn).toHaveBeenCalledWith(selection);
|
||||
expect(onExit).toHaveBeenCalled();
|
||||
});
|
||||
expect(updateDataCollectionOptIn).toHaveBeenCalledWith(selection);
|
||||
expect(onExit).toHaveBeenCalled();
|
||||
unmount();
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { CloudPaidPrivacyNotice } from './CloudPaidPrivacyNotice.js';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
|
||||
@@ -23,20 +24,34 @@ describe('CloudPaidPrivacyNotice', () => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('renders correctly', () => {
|
||||
const { lastFrame } = render(<CloudPaidPrivacyNotice onExit={onExit} />);
|
||||
it('renders correctly', async () => {
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
<CloudPaidPrivacyNotice onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('Vertex AI Notice');
|
||||
expect(lastFrame()).toContain('Service Specific Terms');
|
||||
expect(lastFrame()).toContain('Press Esc to exit');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('exits on Escape', () => {
|
||||
render(<CloudPaidPrivacyNotice onExit={onExit} />);
|
||||
it('exits on Escape', async () => {
|
||||
const { waitUntilReady, unmount } = render(
|
||||
<CloudPaidPrivacyNotice onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
keypressHandler({ name: 'escape' });
|
||||
await act(async () => {
|
||||
keypressHandler({ name: 'escape' });
|
||||
});
|
||||
// Escape key has a 50ms timeout in KeypressContext, so we need to wrap waitUntilReady in act
|
||||
await act(async () => {
|
||||
await waitUntilReady();
|
||||
});
|
||||
|
||||
expect(onExit).toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { GeminiPrivacyNotice } from './GeminiPrivacyNotice.js';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
|
||||
@@ -23,20 +24,34 @@ describe('GeminiPrivacyNotice', () => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('renders correctly', () => {
|
||||
const { lastFrame } = render(<GeminiPrivacyNotice onExit={onExit} />);
|
||||
it('renders correctly', async () => {
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
<GeminiPrivacyNotice onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('Gemini API Key Notice');
|
||||
expect(lastFrame()).toContain('By using the Gemini API');
|
||||
expect(lastFrame()).toContain('Press Esc to exit');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('exits on Escape', () => {
|
||||
render(<GeminiPrivacyNotice onExit={onExit} />);
|
||||
it('exits on Escape', async () => {
|
||||
const { waitUntilReady, unmount } = render(
|
||||
<GeminiPrivacyNotice onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
|
||||
keypressHandler({ name: 'escape' });
|
||||
await act(async () => {
|
||||
keypressHandler({ name: 'escape' });
|
||||
});
|
||||
// Escape key has a 50ms timeout in KeypressContext, so we need to wrap waitUntilReady in act
|
||||
await act(async () => {
|
||||
await waitUntilReady();
|
||||
});
|
||||
|
||||
expect(onExit).toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -64,16 +64,18 @@ describe('PrivacyNotice', () => {
|
||||
},
|
||||
])(
|
||||
'renders $expectedComponent when authType is $authType',
|
||||
({ authType, expectedComponent }) => {
|
||||
async ({ authType, expectedComponent }) => {
|
||||
vi.mocked(mockConfig.getContentGeneratorConfig).mockReturnValue({
|
||||
authType,
|
||||
} as unknown as ContentGeneratorConfig);
|
||||
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, waitUntilReady, unmount } = render(
|
||||
<PrivacyNotice config={mockConfig} onExit={onExit} />,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain(expectedComponent);
|
||||
unmount();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user