feat(design-center): admin 入口按钮 +新建功能 / ⚡AI建功能
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
47
src/pages/DesignCenterPage.entrances.test.tsx
Normal file
47
src/pages/DesignCenterPage.entrances.test.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import { DesignCenterPage } from './DesignCenterPage';
|
||||
|
||||
// menu 走真实 http → mock 掉,避免网络
|
||||
vi.mock('../api/menu', () => ({
|
||||
fetchMenu: vi.fn().mockResolvedValue({ roots: [] }),
|
||||
collectLeaves: vi.fn().mockReturnValue([]),
|
||||
}));
|
||||
|
||||
// 受控 profile:默认 admin
|
||||
const profileMock = vi.fn();
|
||||
vi.mock('../auth/token', () => ({
|
||||
getProfile: () => profileMock(),
|
||||
}));
|
||||
|
||||
function renderPage() {
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<DesignCenterPage />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
describe('DesignCenterPage 入口按钮', () => {
|
||||
beforeEach(() => {
|
||||
profileMock.mockReset();
|
||||
});
|
||||
|
||||
it('admin 看到 [+ 新建功能] 与 [⚡ AI 建功能]', async () => {
|
||||
profileMock.mockReturnValue({ userId: 'ADMIN', account: 'admin', name: 'x', roles: [] });
|
||||
renderPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('dc-new-feature')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('dc-ai-feature')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('非 admin 不渲染入口(整页降级)', () => {
|
||||
profileMock.mockReturnValue({ userId: 'U1', account: 'zhangsan', name: 'z', roles: [] });
|
||||
renderPage();
|
||||
expect(screen.queryByTestId('dc-new-feature')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('dc-ai-feature')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user