summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useFolderTrust.test.ts
diff options
context:
space:
mode:
authorshrutip90 <[email protected]>2025-08-08 11:02:27 -0700
committerGitHub <[email protected]>2025-08-08 18:02:27 +0000
commit34b5dc7f289dc9af0a87d3a795e681d2415da3c9 (patch)
tree9f4b52a13c26a27ccd0eed28715362ee2ded0b65 /packages/cli/src/ui/hooks/useFolderTrust.test.ts
parent3af4913ef3f00de71744de551a568aa713a3beec (diff)
Add FolderTrustDialog that shows on launch and enables folderTrust setting (#5815)
Diffstat (limited to 'packages/cli/src/ui/hooks/useFolderTrust.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/useFolderTrust.test.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/useFolderTrust.test.ts b/packages/cli/src/ui/hooks/useFolderTrust.test.ts
new file mode 100644
index 00000000..61552af0
--- /dev/null
+++ b/packages/cli/src/ui/hooks/useFolderTrust.test.ts
@@ -0,0 +1,78 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { renderHook, act } from '@testing-library/react';
+import { vi } from 'vitest';
+import { useFolderTrust } from './useFolderTrust.js';
+import { LoadedSettings, SettingScope } from '../../config/settings.js';
+import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
+
+describe('useFolderTrust', () => {
+ it('should set isFolderTrustDialogOpen to true when folderTrustFeature is true and folderTrust is undefined', () => {
+ const settings = {
+ merged: {
+ folderTrustFeature: true,
+ folderTrust: undefined,
+ },
+ setValue: vi.fn(),
+ } as unknown as LoadedSettings;
+
+ const { result } = renderHook(() => useFolderTrust(settings));
+
+ expect(result.current.isFolderTrustDialogOpen).toBe(true);
+ });
+
+ it('should set isFolderTrustDialogOpen to false when folderTrustFeature is false', () => {
+ const settings = {
+ merged: {
+ folderTrustFeature: false,
+ folderTrust: undefined,
+ },
+ setValue: vi.fn(),
+ } as unknown as LoadedSettings;
+
+ const { result } = renderHook(() => useFolderTrust(settings));
+
+ expect(result.current.isFolderTrustDialogOpen).toBe(false);
+ });
+
+ it('should set isFolderTrustDialogOpen to false when folderTrust is defined', () => {
+ const settings = {
+ merged: {
+ folderTrustFeature: true,
+ folderTrust: true,
+ },
+ setValue: vi.fn(),
+ } as unknown as LoadedSettings;
+
+ const { result } = renderHook(() => useFolderTrust(settings));
+
+ expect(result.current.isFolderTrustDialogOpen).toBe(false);
+ });
+
+ it('should call setValue and set isFolderTrustDialogOpen to false on handleFolderTrustSelect', () => {
+ const settings = {
+ merged: {
+ folderTrustFeature: true,
+ folderTrust: undefined,
+ },
+ setValue: vi.fn(),
+ } as unknown as LoadedSettings;
+
+ const { result } = renderHook(() => useFolderTrust(settings));
+
+ act(() => {
+ result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
+ });
+
+ expect(settings.setValue).toHaveBeenCalledWith(
+ SettingScope.User,
+ 'folderTrust',
+ true,
+ );
+ expect(result.current.isFolderTrustDialogOpen).toBe(false);
+ });
+});