feat(ui): 保时捷语法复刻收尾(ADR-0008/0009/0011/0012/0013) #65
No files matched your search
+4
-2
@@ -9,7 +9,7 @@ import { PerformanceTracker } from "@/components/analytics/PerformanceTracker";
|
||||
import { OutboundLinkTracker } from "@/components/analytics/OutboundLinkTracker";
|
||||
import { ScrollDepthTracker } from "@/components/analytics/ScrollDepthTracker";
|
||||
import { OrganizationSchema, WebsiteSchema, LocalBusinessSchema } from "@/components/seo/structured-data";
|
||||
import { MobileTabBar } from "@/components/layout/mobile-tab-bar";
|
||||
import { MobileTabBarGate } from "@/components/layout/mobile-tab-bar-gate";
|
||||
import { ErrorBoundary } from "@/components/ui/error-boundary";
|
||||
import { ScrollProgress } from "@/components/ui/scroll-progress";
|
||||
import { MotionProvider } from "@/components/ui/motion-provider";
|
||||
@@ -214,8 +214,10 @@ export default async function RootLayout({
|
||||
</ClientLayout>
|
||||
</SiteConfigProvider>
|
||||
</ErrorBoundary>
|
||||
{/* 公共移动 tab bar 留在根布局(main/PageTransition 之外,fixed 定位不受 transform 影响),
|
||||
只按 pathname 在 /admin 下关闭:/admin 是内部系统,露出公共导航会盖住后台内容(DEF-03)。 */}
|
||||
<Suspense fallback={null}>
|
||||
<MobileTabBar />
|
||||
<MobileTabBarGate />
|
||||
</Suspense>
|
||||
<CookieConsent />
|
||||
<BackToTop />
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, it, expect, jest } from '@jest/globals';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
let mockCurrentPath = '/';
|
||||
jest.mock('next/navigation', () => ({
|
||||
usePathname: () => mockCurrentPath,
|
||||
}));
|
||||
|
||||
jest.mock('./mobile-tab-bar', () => ({
|
||||
MobileTabBar: () => <div data-testid="mobile-tab-bar-mock" />,
|
||||
}));
|
||||
|
||||
import { MobileTabBarGate, shouldRenderMobileTabBar } from './mobile-tab-bar-gate';
|
||||
|
||||
describe('MobileTabBarGate', () => {
|
||||
it('不在 /admin 下渲染公共 tab bar', () => {
|
||||
expect(shouldRenderMobileTabBar('/admin')).toBe(false);
|
||||
expect(shouldRenderMobileTabBar('/admin/login')).toBe(false);
|
||||
expect(shouldRenderMobileTabBar('/admin/content/news')).toBe(false);
|
||||
});
|
||||
|
||||
it('营销路由继续渲染 tab bar', () => {
|
||||
expect(shouldRenderMobileTabBar('/')).toBe(true);
|
||||
expect(shouldRenderMobileTabBar('/products')).toBe(true);
|
||||
expect(shouldRenderMobileTabBar('/privacy')).toBe(true);
|
||||
});
|
||||
|
||||
it('按 pathname 实际 gate', () => {
|
||||
mockCurrentPath = '/admin';
|
||||
const admin = render(<MobileTabBarGate />);
|
||||
expect(screen.queryByTestId('mobile-tab-bar-mock')).not.toBeInTheDocument();
|
||||
admin.unmount();
|
||||
|
||||
mockCurrentPath = '/';
|
||||
render(<MobileTabBarGate />);
|
||||
expect(screen.getByTestId('mobile-tab-bar-mock')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { MobileTabBar } from './mobile-tab-bar';
|
||||
|
||||
/** /admin 是内部系统,不应出现公共移动导航;导出让单测钉住边界。 */
|
||||
export function shouldRenderMobileTabBar(pathname: string): boolean {
|
||||
return !pathname.startsWith('/admin');
|
||||
}
|
||||
|
||||
export function MobileTabBarGate() {
|
||||
const pathname = usePathname();
|
||||
if (!shouldRenderMobileTabBar(pathname)) {return null;}
|
||||
return <MobileTabBar />;
|
||||
}
|
||||
Reference in new issue
Block a user