diff options
| author | shrutip90 <[email protected]> | 2025-08-21 00:38:12 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-21 07:38:12 +0000 |
| commit | ba5309c4050efde8b0be0d9dd726e5c5f1a4c4c6 (patch) | |
| tree | d34cc814b2968bc8a09add14128544afe0f4f529 /packages/cli/src/ui/hooks/useFolderTrust.test.ts | |
| parent | 0242ecd83a5b0673a6ef97a406a743b286ef12e2 (diff) | |
Force restart on trust level change to reload settings (#6713)
Diffstat (limited to 'packages/cli/src/ui/hooks/useFolderTrust.test.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useFolderTrust.test.ts | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/packages/cli/src/ui/hooks/useFolderTrust.test.ts b/packages/cli/src/ui/hooks/useFolderTrust.test.ts index 3103cab4..54e7fe86 100644 --- a/packages/cli/src/ui/hooks/useFolderTrust.test.ts +++ b/packages/cli/src/ui/hooks/useFolderTrust.test.ts @@ -82,7 +82,9 @@ describe('useFolderTrust', () => { }); it('should handle TRUST_FOLDER choice', () => { - isWorkspaceTrustedSpy.mockReturnValue(undefined); + isWorkspaceTrustedSpy + .mockReturnValueOnce(undefined) + .mockReturnValueOnce(true); const { result } = renderHook(() => useFolderTrust(mockSettings, onTrustChange), ); @@ -102,12 +104,13 @@ describe('useFolderTrust', () => { }); it('should handle TRUST_PARENT choice', () => { - isWorkspaceTrustedSpy.mockReturnValue(undefined); + isWorkspaceTrustedSpy + .mockReturnValueOnce(undefined) + .mockReturnValueOnce(true); const { result } = renderHook(() => useFolderTrust(mockSettings, onTrustChange), ); - isWorkspaceTrustedSpy.mockReturnValue(true); act(() => { result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_PARENT); }); @@ -120,13 +123,14 @@ describe('useFolderTrust', () => { expect(onTrustChange).toHaveBeenLastCalledWith(true); }); - it('should handle DO_NOT_TRUST choice', () => { - isWorkspaceTrustedSpy.mockReturnValue(undefined); + it('should handle DO_NOT_TRUST choice and trigger restart', () => { + isWorkspaceTrustedSpy + .mockReturnValueOnce(undefined) + .mockReturnValueOnce(false); const { result } = renderHook(() => useFolderTrust(mockSettings, onTrustChange), ); - isWorkspaceTrustedSpy.mockReturnValue(false); act(() => { result.current.handleFolderTrustSelect(FolderTrustChoice.DO_NOT_TRUST); }); @@ -135,8 +139,9 @@ describe('useFolderTrust', () => { '/test/path', TrustLevel.DO_NOT_TRUST, ); - expect(result.current.isFolderTrustDialogOpen).toBe(false); expect(onTrustChange).toHaveBeenLastCalledWith(false); + expect(result.current.isRestarting).toBe(true); + expect(result.current.isFolderTrustDialogOpen).toBe(true); }); it('should do nothing for default choice', () => { @@ -156,4 +161,34 @@ describe('useFolderTrust', () => { expect(result.current.isFolderTrustDialogOpen).toBe(true); expect(onTrustChange).toHaveBeenCalledWith(undefined); }); + + 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), + ); + + act(() => { + result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER); + }); + + expect(result.current.isRestarting).toBe(true); + expect(result.current.isFolderTrustDialogOpen).toBe(true); // Dialog should stay open + }); + + it('should not set isRestarting to true when trust status does not change', () => { + isWorkspaceTrustedSpy + .mockReturnValueOnce(undefined) + .mockReturnValueOnce(true); // Initially undefined, then trust + const { result } = renderHook(() => + useFolderTrust(mockSettings, onTrustChange), + ); + + act(() => { + result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER); + }); + + expect(result.current.isRestarting).toBe(false); + expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close + }); }); |
