mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 06:25:16 -07:00
feat(ui): Introduce useUI Hook and UIContext (#5488)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ vi.mock('process', () => ({
|
||||
|
||||
describe('useFolderTrust', () => {
|
||||
let mockSettings: LoadedSettings;
|
||||
let mockConfig: unknown;
|
||||
let mockTrustedFolders: LoadedTrustedFolders;
|
||||
let loadTrustedFoldersSpy: vi.SpyInstance;
|
||||
let isWorkspaceTrustedSpy: vi.SpyInstance;
|
||||
@@ -36,6 +37,8 @@ describe('useFolderTrust', () => {
|
||||
setValue: vi.fn(),
|
||||
} as unknown as LoadedSettings;
|
||||
|
||||
mockConfig = {} as unknown;
|
||||
|
||||
mockTrustedFolders = {
|
||||
setValue: vi.fn(),
|
||||
} as unknown as LoadedTrustedFolders;
|
||||
@@ -55,7 +58,7 @@ describe('useFolderTrust', () => {
|
||||
it('should not open dialog when folder is already trusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(true);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(true);
|
||||
@@ -64,7 +67,7 @@ describe('useFolderTrust', () => {
|
||||
it('should not open dialog when folder is already untrusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(false);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(false);
|
||||
@@ -73,7 +76,7 @@ describe('useFolderTrust', () => {
|
||||
it('should open dialog when folder trust is undefined', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(undefined);
|
||||
@@ -84,7 +87,7 @@ describe('useFolderTrust', () => {
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
isWorkspaceTrustedSpy.mockReturnValue(true);
|
||||
@@ -106,7 +109,7 @@ describe('useFolderTrust', () => {
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -126,7 +129,7 @@ describe('useFolderTrust', () => {
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(false);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -138,14 +141,14 @@ describe('useFolderTrust', () => {
|
||||
TrustLevel.DO_NOT_TRUST,
|
||||
);
|
||||
expect(onTrustChange).toHaveBeenLastCalledWith(false);
|
||||
expect(result.current.isRestarting).toBe(true);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||
expect(result.current.isRestarting).toBe(false);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
});
|
||||
|
||||
it('should do nothing for default choice', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -163,15 +166,15 @@ describe('useFolderTrust', () => {
|
||||
it('should set isRestarting to true when trust status changes from false to true', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValueOnce(false).mockReturnValueOnce(true); // Initially untrusted, then trusted
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
|
||||
});
|
||||
|
||||
expect(result.current.isRestarting).toBe(true);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true); // Dialog should stay open
|
||||
expect(result.current.isRestarting).toBe(false);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close after selection
|
||||
});
|
||||
|
||||
it('should not set isRestarting to true when trust status does not change', () => {
|
||||
@@ -179,7 +182,7 @@ describe('useFolderTrust', () => {
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true); // Initially undefined, then trust
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, mockConfig, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
|
||||
Reference in New Issue
Block a user