feat: move plugin center into project configuration

This commit is contained in:
inman
2026-08-31 16:57:26 +08:00
parent b3f4166f21
commit e237941399
13 changed files with 260 additions and 103 deletions

View File

@@ -0,0 +1,47 @@
import { useState } from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';
import { PluginServices } from '@/components/plugins/PluginServices';
import { getPluginServiceTab, type PluginServiceTab } from '@/lib/plugin-services';
vi.mock('@/pages/PluginMarketplace', () => ({
PluginMarketplaceCatalog: () => <div>发现插件内容</div>,
}));
vi.mock('@/pages/MyPlugins', () => ({
MyPlugins: () => <div>我的插件内容</div>,
}));
vi.mock('@/pages/ProjectPlugins', () => ({
ProjectPlugins: () => <div>项目启用内容</div>,
}));
function Harness() {
const [value, setValue] = useState<PluginServiceTab>('project');
return <PluginServices
value={value}
onValueChange={setValue}
onProjectPluginsChanged={vi.fn()}
onManageAgents={vi.fn()}
onResolveIdentity={vi.fn()}
/>;
}
describe('PluginServices', () => {
it('keeps discovery, account/device management, and project enablement in one surface', () => {
render(<MemoryRouter><Harness /></MemoryRouter>);
expect(screen.getByRole('tab', { name: '项目启用' })).toHaveAttribute('aria-selected', 'true');
expect(screen.getByText('项目启用内容')).toBeVisible();
fireEvent.mouseDown(screen.getByRole('tab', { name: '发现插件' }), { button: 0, ctrlKey: false });
expect(screen.getByText('发现插件内容')).toBeVisible();
fireEvent.mouseDown(screen.getByRole('tab', { name: '我的插件' }), { button: 0, ctrlKey: false });
expect(screen.getByText('我的插件内容')).toBeVisible();
});
it('defaults invalid and missing deep-link values to project enablement', () => {
expect(getPluginServiceTab(null)).toBe('project');
expect(getPluginServiceTab('unknown')).toBe('project');
expect(getPluginServiceTab('discover')).toBe('discover');
expect(getPluginServiceTab('mine')).toBe('mine');
});
});