test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions
@@ -119,18 +119,18 @@ describe('useFolderTrust', () => {
});
});
it('should not open dialog when folder is already trusted', () => {
it('should not open dialog when folder is already trusted', async () => {
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: true, source: 'file' });
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
expect(result.current.isFolderTrustDialogOpen).toBe(false);
expect(onTrustChange).toHaveBeenCalledWith(true);
});
it('should not open dialog when folder is already untrusted', () => {
it('should not open dialog when folder is already untrusted', async () => {
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: false, source: 'file' });
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
expect(result.current.isFolderTrustDialogOpen).toBe(false);
@@ -142,7 +142,7 @@ describe('useFolderTrust', () => {
isTrusted: undefined,
source: undefined,
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
await waitFor(() => {
@@ -151,9 +151,11 @@ describe('useFolderTrust', () => {
expect(onTrustChange).toHaveBeenCalledWith(undefined);
});
it('should send a message if the folder is untrusted', () => {
it('should send a message if the folder is untrusted', async () => {
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: false, source: 'file' });
renderHook(() => useFolderTrust(mockSettings, onTrustChange, addItem));
await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
expect(addItem).toHaveBeenCalledWith(
{
text: 'This folder is untrusted, project settings, hooks, MCPs, and GEMINI.md files will not be applied for this folder.\nUse the `/permissions` command to change the trust level.',
@@ -163,9 +165,11 @@ describe('useFolderTrust', () => {
);
});
it('should not send a message if the folder is trusted', () => {
it('should not send a message if the folder is trusted', async () => {
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: true, source: 'file' });
renderHook(() => useFolderTrust(mockSettings, onTrustChange, addItem));
await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
expect(addItem).not.toHaveBeenCalled();
});
@@ -182,7 +186,7 @@ describe('useFolderTrust', () => {
});
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -212,7 +216,7 @@ describe('useFolderTrust', () => {
isTrusted: undefined,
source: undefined,
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -238,7 +242,7 @@ describe('useFolderTrust', () => {
isTrusted: undefined,
source: undefined,
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -264,7 +268,7 @@ describe('useFolderTrust', () => {
isTrusted: undefined,
source: undefined,
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -292,7 +296,7 @@ describe('useFolderTrust', () => {
});
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -317,7 +321,7 @@ describe('useFolderTrust', () => {
isTrusted: true,
source: 'file',
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -342,7 +346,7 @@ describe('useFolderTrust', () => {
throw new Error('test error');
});
const emitFeedbackSpy = vi.spyOn(coreEvents, 'emitFeedback');
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);
@@ -362,14 +366,14 @@ describe('useFolderTrust', () => {
});
describe('headless mode', () => {
it('should force trust and hide dialog in headless mode', () => {
it('should force trust and hide dialog in headless mode', async () => {
vi.mocked(isHeadlessMode).mockReturnValue(true);
isWorkspaceTrustedSpy.mockReturnValue({
isTrusted: false,
source: 'file',
});
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useFolderTrust(mockSettings, onTrustChange, addItem),
);