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
@@ -138,9 +138,9 @@ describe('useApprovalModeIndicator', () => {
mockConfigInstance = new (Config as any)() as MockConfigInstanceShape;
});
it('should initialize with ApprovalMode.AUTO_EDIT if config.getApprovalMode returns ApprovalMode.AUTO_EDIT', () => {
it('should initialize with ApprovalMode.AUTO_EDIT if config.getApprovalMode returns ApprovalMode.AUTO_EDIT', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.AUTO_EDIT);
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -150,9 +150,9 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode).toHaveBeenCalledTimes(1);
});
it('should initialize with ApprovalMode.DEFAULT if config.getApprovalMode returns ApprovalMode.DEFAULT', () => {
it('should initialize with ApprovalMode.DEFAULT if config.getApprovalMode returns ApprovalMode.DEFAULT', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -162,9 +162,9 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode).toHaveBeenCalledTimes(1);
});
it('should initialize with ApprovalMode.YOLO if config.getApprovalMode returns ApprovalMode.YOLO', () => {
it('should initialize with ApprovalMode.YOLO if config.getApprovalMode returns ApprovalMode.YOLO', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.YOLO);
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -174,9 +174,9 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode).toHaveBeenCalledTimes(1);
});
it('should cycle the indicator and update config when Shift+Tab or Ctrl+Y is pressed', () => {
it('should cycle the indicator and update config when Shift+Tab or Ctrl+Y is pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -238,9 +238,9 @@ describe('useApprovalModeIndicator', () => {
expect(result.current).toBe(ApprovalMode.AUTO_EDIT);
});
it('should not toggle if only one key or other keys combinations are pressed', () => {
it('should not toggle if only one key or other keys combinations are pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -297,9 +297,9 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.setApprovalMode).not.toHaveBeenCalled();
});
it('should update indicator when config value changes externally (useEffect dependency)', () => {
it('should update indicator when config value changes externally (useEffect dependency)', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const { result, rerender } = renderHook(
const { result, rerender } = await renderHook(
(props: { config: ActualConfigType; addItem: () => void }) =>
useApprovalModeIndicator(props),
{
@@ -326,7 +326,7 @@ describe('useApprovalModeIndicator', () => {
mockConfigInstance.isTrustedFolder.mockReturnValue(false);
});
it('should not enable YOLO mode when Ctrl+Y is pressed', () => {
it('should not enable YOLO mode when Ctrl+Y is pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
mockConfigInstance.setApprovalMode.mockImplementation(() => {
throw new Error(
@@ -334,7 +334,7 @@ describe('useApprovalModeIndicator', () => {
);
});
const mockAddItem = vi.fn();
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -356,7 +356,7 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode()).toBe(ApprovalMode.DEFAULT);
});
it('should not enable AUTO_EDIT mode when Shift+Tab is pressed', () => {
it('should not enable AUTO_EDIT mode when Shift+Tab is pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
mockConfigInstance.setApprovalMode.mockImplementation(() => {
throw new Error(
@@ -364,7 +364,7 @@ describe('useApprovalModeIndicator', () => {
);
});
const mockAddItem = vi.fn();
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -389,10 +389,10 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode()).toBe(ApprovalMode.DEFAULT);
});
it('should disable YOLO mode when Ctrl+Y is pressed', () => {
it('should disable YOLO mode when Ctrl+Y is pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.YOLO);
const mockAddItem = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -409,12 +409,12 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode()).toBe(ApprovalMode.DEFAULT);
});
it('should disable AUTO_EDIT mode when Shift+Tab is pressed', () => {
it('should disable AUTO_EDIT mode when Shift+Tab is pressed', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(
ApprovalMode.AUTO_EDIT,
);
const mockAddItem = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -434,7 +434,7 @@ describe('useApprovalModeIndicator', () => {
expect(mockConfigInstance.getApprovalMode()).toBe(ApprovalMode.DEFAULT);
});
it('should show a warning when trying to enable privileged modes', () => {
it('should show a warning when trying to enable privileged modes', async () => {
// Mock the error thrown by setApprovalMode
const errorMessage =
'Cannot enable privileged approval modes in an untrusted folder.';
@@ -443,7 +443,7 @@ describe('useApprovalModeIndicator', () => {
});
const mockAddItem = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -491,13 +491,13 @@ describe('useApprovalModeIndicator', () => {
}
});
it('should not enable YOLO mode when Ctrl+Y is pressed and add an info message', () => {
it('should not enable YOLO mode when Ctrl+Y is pressed and add an info message', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
mockConfigInstance.getRemoteAdminSettings.mockReturnValue({
strictModeDisabled: true,
});
const mockAddItem = vi.fn();
const { result } = renderHook(() =>
const { result } = await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -524,14 +524,14 @@ describe('useApprovalModeIndicator', () => {
expect(result.current).toBe(ApprovalMode.DEFAULT);
});
it('should show admin error message when YOLO mode is disabled by admin', () => {
it('should show admin error message when YOLO mode is disabled by admin', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
mockConfigInstance.getRemoteAdminSettings.mockReturnValue({
mcpEnabled: true,
});
const mockAddItem = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -551,12 +551,12 @@ describe('useApprovalModeIndicator', () => {
);
});
it('should show default error message when admin settings are empty', () => {
it('should show default error message when admin settings are empty', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
mockConfigInstance.getRemoteAdminSettings.mockReturnValue({});
const mockAddItem = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: mockAddItem,
@@ -577,12 +577,12 @@ describe('useApprovalModeIndicator', () => {
});
});
it('should call onApprovalModeChange when switching to YOLO mode', () => {
it('should call onApprovalModeChange when switching to YOLO mode', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const mockOnApprovalModeChange = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
onApprovalModeChange: mockOnApprovalModeChange,
@@ -599,12 +599,12 @@ describe('useApprovalModeIndicator', () => {
expect(mockOnApprovalModeChange).toHaveBeenCalledWith(ApprovalMode.YOLO);
});
it('should call onApprovalModeChange when switching to AUTO_EDIT mode', () => {
it('should call onApprovalModeChange when switching to AUTO_EDIT mode', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const mockOnApprovalModeChange = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
onApprovalModeChange: mockOnApprovalModeChange,
@@ -623,12 +623,12 @@ describe('useApprovalModeIndicator', () => {
);
});
it('should call onApprovalModeChange when switching to DEFAULT mode', () => {
it('should call onApprovalModeChange when switching to DEFAULT mode', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.YOLO);
const mockOnApprovalModeChange = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
onApprovalModeChange: mockOnApprovalModeChange,
@@ -645,10 +645,10 @@ describe('useApprovalModeIndicator', () => {
expect(mockOnApprovalModeChange).toHaveBeenCalledWith(ApprovalMode.DEFAULT);
});
it('should not call onApprovalModeChange when callback is not provided', () => {
it('should not call onApprovalModeChange when callback is not provided', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
}),
@@ -664,12 +664,12 @@ describe('useApprovalModeIndicator', () => {
// Should not throw an error when callback is not provided
});
it('should handle multiple mode changes correctly', () => {
it('should handle multiple mode changes correctly', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
const mockOnApprovalModeChange = vi.fn();
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
onApprovalModeChange: mockOnApprovalModeChange,
@@ -697,10 +697,10 @@ describe('useApprovalModeIndicator', () => {
);
});
it('should cycle to PLAN when allowPlanMode is true', () => {
it('should cycle to PLAN when allowPlanMode is true', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.AUTO_EDIT);
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),
@@ -717,10 +717,10 @@ describe('useApprovalModeIndicator', () => {
);
});
it('should cycle to DEFAULT when allowPlanMode is false', () => {
it('should cycle to DEFAULT when allowPlanMode is false', async () => {
mockConfigInstance.getApprovalMode.mockReturnValue(ApprovalMode.AUTO_EDIT);
renderHook(() =>
await renderHook(() =>
useApprovalModeIndicator({
config: mockConfigInstance as unknown as ActualConfigType,
addItem: vi.fn(),