mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-11 22:00:41 -07:00
Fix tests to wrap all calls changing the UI with act. (#12268)
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { render } from 'ink-testing-library';
|
||||
import { act } from 'react';
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import type {
|
||||
Config,
|
||||
CodeAssistServer,
|
||||
@@ -13,6 +14,7 @@ import type {
|
||||
} from '@google/gemini-cli-core';
|
||||
import { UserTierId, getCodeAssistServer } from '@google/gemini-cli-core';
|
||||
import { usePrivacySettings } from './usePrivacySettings.js';
|
||||
import { waitFor } from '../../test-utils/async.js';
|
||||
|
||||
// Mock the dependencies
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
@@ -52,7 +54,7 @@ describe('usePrivacySettings', () => {
|
||||
|
||||
const { result } = renderPrivacySettingsHook();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(result.current.privacyState.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
@@ -71,7 +73,7 @@ describe('usePrivacySettings', () => {
|
||||
|
||||
const { result } = renderPrivacySettingsHook();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(result.current.privacyState.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
@@ -90,7 +92,7 @@ describe('usePrivacySettings', () => {
|
||||
|
||||
const { result } = renderPrivacySettingsHook();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(result.current.privacyState.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
@@ -118,15 +120,17 @@ describe('usePrivacySettings', () => {
|
||||
const { result } = renderPrivacySettingsHook();
|
||||
|
||||
// Wait for initial load
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(result.current.privacyState.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
// Update the setting
|
||||
await result.current.updateDataCollectionOptIn(false);
|
||||
await act(async () => {
|
||||
await result.current.updateDataCollectionOptIn(false);
|
||||
});
|
||||
|
||||
// Wait for update to complete
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(result.current.privacyState.dataCollectionOptIn).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user