Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(desktop): 补齐 worker 列表默认布局回退的回归测试

Shinku3fbc722fc5cf
diff --git a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
index 153966074f..4e14e9d5a4 100644
--- a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
@@ -167,7 +167,8 @@ function ensureChildHorizontallyVisible(container: HTMLElement, child: HTMLEleme
type WorkerListLayout = 'tabs' | 'dropdown';
type DropdownOpenMode = 'transient' | 'pinned' | null;
-function readStoredWorkerListLayout(): WorkerListLayout {
+// Exported for direct unit testing of the default-layout fallback matrix.
+export function readStoredWorkerListLayout(): WorkerListLayout {
if (typeof window === 'undefined') return 'tabs';
try {
const stored = window.localStorage.getItem(WORKER_LIST_LAYOUT_KEY);
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/workerListLayoutPersistence.test.ts b/apps/desktop/src/renderer/features/cc-agent/__tests__/workerListLayoutPersistence.test.ts
new file mode 100644
index 0000000000..6ffc22f72e
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/workerListLayoutPersistence.test.ts
@@ -0,0 +1,40 @@
+// @vitest-environment jsdom
+
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { readStoredWorkerListLayout } from '../RolePillDropdown';
+
+const KEY = 'orca-worker-list-layout-v1';
+
+describe('readStoredWorkerListLayout default-layout fallback', () => {
+ afterEach(() => {
+ window.localStorage.clear();
+ vi.restoreAllMocks();
+ });
+
+ it('returns tabs when no key is stored', () => {
+ expect(readStoredWorkerListLayout()).toBe('tabs');
+ });
+
+ it('keeps tabs when a stored tabs preference exists', () => {
+ window.localStorage.setItem(KEY, 'tabs');
+ expect(readStoredWorkerListLayout()).toBe('tabs');
+ });
+
+ it('keeps dropdown when a stored dropdown preference exists', () => {
+ window.localStorage.setItem(KEY, 'dropdown');
+ expect(readStoredWorkerListLayout()).toBe('dropdown');
+ });
+
+ it('falls back to tabs when reading localStorage throws', () => {
+ vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
+ throw new Error('storage read failed');
+ });
+ expect(readStoredWorkerListLayout()).toBe('tabs');
+ });
+
+ it('falls back to tabs on an invalid stored value', () => {
+ window.localStorage.setItem(KEY, 'bogus');
+ expect(readStoredWorkerListLayout()).toBe('tabs');
+ });
+});