feat(routes): 接线 /new-feature 与 /ai-feature(admin-gated 页内守护)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-20 09:56:52 +08:00
parent 4e0e974473
commit a6bd4b0432
2 changed files with 52 additions and 0 deletions

47
src/App.routes.test.tsx Normal file
View File

@@ -0,0 +1,47 @@
import '@testing-library/jest-dom';
import { render, screen, waitFor } from '@testing-library/react';
import { MemoryRouter, Routes, Route } from 'react-router-dom';
import { vi, describe, it, expect } from 'vitest';
import { NewFeatureShell } from './pages/NewFeatureShell';
import { AiFeatureForm } from './pages/AiFeatureForm';
vi.mock('./auth/token', () => ({
getProfile: () => ({ userId: 'ADMIN', account: 'admin', name: 'x', roles: [] }),
}));
vi.mock('./api/meta', () => ({ listEntities: vi.fn().mockResolvedValue([]), createEntity: vi.fn() }));
vi.mock('./api/recipe', () => ({
listRecipes: () => [{ id: 'maintenance-crud-v1', label: '维护型 CRUD' }],
compileRecipe: vi.fn(),
}));
vi.mock('./api/publish', () => ({ publishFeature: vi.fn() }));
vi.mock('./api/menu', () => ({ fetchMenu: vi.fn().mockResolvedValue({ roots: [] }), collectLeaves: vi.fn() }));
vi.mock('./api/ai', async (io) => {
const actual = await io<typeof import('./api/ai')>();
return { ...actual, autoDevelop: vi.fn() };
});
describe('新路由可达', () => {
it('/new-feature 渲染 NewFeatureShell', async () => {
render(
<MemoryRouter initialEntries={['/new-feature']}>
<Routes>
<Route path="/new-feature" element={<NewFeatureShell />} />
<Route path="/ai-feature" element={<AiFeatureForm />} />
</Routes>
</MemoryRouter>,
);
await waitFor(() => expect(screen.getByTestId('new-feature-shell')).toBeInTheDocument());
});
it('/ai-feature 渲染 AiFeatureForm', () => {
render(
<MemoryRouter initialEntries={['/ai-feature']}>
<Routes>
<Route path="/new-feature" element={<NewFeatureShell />} />
<Route path="/ai-feature" element={<AiFeatureForm />} />
</Routes>
</MemoryRouter>,
);
expect(screen.getByTestId('ai-feature-form')).toBeInTheDocument();
});
});

View File

@@ -8,6 +8,8 @@ import { PageRenderPage } from './pages/PageRenderPage';
import { TodoPage } from './pages/TodoPage';
import { WorkbenchPage } from './pages/WorkbenchPage';
import { DesignCenterPage } from './pages/DesignCenterPage';
import { NewFeatureShell } from './pages/NewFeatureShell';
import { AiFeatureForm } from './pages/AiFeatureForm';
import { ModelerPage } from './pages/ModelerPage';
// 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate)
@@ -41,6 +43,9 @@ export default function App() {
<Route path="/page/:templateId" element={<PageRenderPage />} />
{/* 设计中心(管理员集中式低代码设计入口,替代每页设计按钮)*/}
<Route path="/design-center" element={<DesignCenterPage />} />
{/* 人走五环编排壳 + AI ①面入口(admin-gated,页内早返回守护)*/}
<Route path="/new-feature" element={<NewFeatureShell />} />
<Route path="/ai-feature" element={<AiFeatureForm />} />
{/* 建模器(五环第①环·元数据→表,仅管理员)*/}
<Route path="/modeler" element={<ModelerPage />} />
{/* 根路径默认跳工作台 */}