fix(RouterProvider): 将 goBack 重命名为 goHome,修复跨窗同步 merge 不一致

API 命名与实际行为(返回 dashboard)对齐;storage.onChanged 同步 visiblePages/pageOrder 时应用 mergeWithDefaults,与初始化逻辑保持一致。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
雨霖铃
2026-06-19 00:38:01 +08:00
parent aa63723b80
commit 8f9ff27034
6 changed files with 68 additions and 15 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ const SEARCH_HISTORY_LIMIT = 10;
const SEARCH_HISTORY_DISPLAY = 5;
export default function TopBar() {
const { currentPage, goBack, navigateTo } = useRouter();
const { currentPage, goHome, navigateTo } = useRouter();
const { mode, setMode } = useThemeMode();
const [searchQuery, setSearchQuery] = useState('');
@@ -138,8 +138,8 @@ export default function TopBar() {
{!isDashboard && (
<button
type="button"
onClick={goBack}
aria-label={'返回'}
onClick={goHome}
aria-label={'返回首页'}
className="flex h-8 w-8 items-center justify-center rounded-md border border-input bg-background text-muted-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
>
<ArrowLeft className="h-4 w-4" />
@@ -12,7 +12,7 @@ const mockRouterValue = {
isLoaded: true,
navigateTo: vi.fn(),
syncNavigation: vi.fn(),
goBack: vi.fn(),
goHome: vi.fn(),
setVisiblePages: vi.fn(),
setPageOrder: vi.fn(),
};
+5 -5
View File
@@ -27,7 +27,7 @@ const mockRouterValue = {
isLoaded: true,
navigateTo: vi.fn(),
syncNavigation: vi.fn(),
goBack: vi.fn(),
goHome: vi.fn(),
setVisiblePages: vi.fn(),
setPageOrder: vi.fn(),
};
@@ -54,7 +54,7 @@ describe('TopBar 组件', () => {
it('不在 dashboard 时应渲染返回按钮', () => {
mockRouterValue.currentPage = 'timestamp';
renderWithProvider(<TopBar />);
expect(screen.getByLabelText('返回')).toBeInTheDocument();
expect(screen.getByLabelText('返回首页')).toBeInTheDocument();
});
it('在 dashboard 上不应渲染返回按钮', () => {
@@ -65,12 +65,12 @@ describe('TopBar 组件', () => {
});
describe('交互测试', () => {
it('点击返回按钮时应调用 goBack', () => {
it('点击返回按钮时应调用 goHome', () => {
mockRouterValue.currentPage = 'timestamp';
renderWithProvider(<TopBar />);
fireEvent.click(screen.getByLabelText('返回'));
expect(mockRouterValue.goBack).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByLabelText('返回首页'));
expect(mockRouterValue.goHome).toHaveBeenCalledTimes(1);
});
});
});