阶段七:完成 React Feature 化与前置重构收口

This commit is contained in:
Christ committed 2026-08-17 20:29:34 +08:00
1 parent 375e84d663
commit 1a228dc35c
305 files changed
+14179 -5431

No files matched your search

@@ -0,0 +1,29 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import { readSidebarCollapsed, writeSidebarCollapsed } from './sidebarState';
afterEach(/* 当前回调处理用户交互或异步状态变化。 */ () => vi.unstubAllGlobals());
describe('sidebar persistence', /* 当前回调处理用户交互或异步状态变化。 */ () => {
test('defaults to expanded and persists both states', /* 当前回调处理用户交互或异步状态变化。 */ () => {
// values 值列表。
const values = new Map<string, string>();
vi.stubGlobal('window', { localStorage: {
getItem: /* 当前回调处理用户交互或异步状态变化。 */ (key: string) => values.get(key) ?? null,
setItem: /* 当前回调处理用户交互或异步状态变化。 */ (key: string, value: string) => values.set(key, value),
}});
expect(readSidebarCollapsed()).toBe(false);
writeSidebarCollapsed(true);
expect(readSidebarCollapsed()).toBe(true);
writeSidebarCollapsed(false);
expect(readSidebarCollapsed()).toBe(false);
});
test('storage failures safely fall back to expanded', /* 当前回调处理用户交互或异步状态变化。 */ () => {
vi.stubGlobal('window', { localStorage: {
getItem: /* 当前回调处理用户交互或异步状态变化。 */ () => { throw new Error('blocked'); },
setItem: /* 当前回调处理用户交互或异步状态变化。 */ () => { throw new Error('blocked'); },
}});
expect(readSidebarCollapsed()).toBe(false);
expect(/* 当前回调处理用户交互或异步状态变化。 */ () => writeSidebarCollapsed(true)).not.toThrow();
});
});
+21
View File
@@ -0,0 +1,21 @@
// storageKey 侧边栏折叠状态存储键。
const storageKey = 'ydisks.sidebar.v1';
// readSidebarCollapsed 读取侧边栏折叠状态。
export const readSidebarCollapsed = (): boolean => {
try {
return window.localStorage.getItem(storageKey) === 'collapsed';
} catch {
return false;
}
};
// writeSidebarCollapsed 写入侧边栏折叠状态。
export const writeSidebarCollapsed = (collapsed: boolean): void => {
try {
window.localStorage.setItem(storageKey, collapsed ? 'collapsed' : 'expanded');
} catch {
// Storage can be unavailable in hardened browsers; the in-memory state
// remains fully functional.
}
};