feat: unify plugin workspace navigation

This commit is contained in:
2026-09-03 13:39:55 +08:00
parent 959e2faf03
commit 1b1f206dd8
27 changed files with 3097 additions and 1100 deletions

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import {
parsePluginWorkspaceSearch,
serializePluginWorkspaceSearch,
} from '@/pages/Plugins/plugin-workspace-query';
describe('plugin workspace URL state', () => {
it('uses the hydrated project presence for a bare route default', () => {
expect(parsePluginWorkspaceSearch(new URLSearchParams(), true)).toEqual({
scope: 'project', source: 'all', state: 'all', search: '', selectedKey: null,
});
expect(parsePluginWorkspaceSearch(new URLSearchParams(), false)).toEqual({
scope: 'all', source: 'all', state: 'all', search: '', selectedKey: null,
});
});
it('normalizes unknown values and a project scope without a project', () => {
const params = new URLSearchParams('scope=unknown&source=remote&state=broken&q=%20notes%20&plugin=notes');
expect(parsePluginWorkspaceSearch(params, true)).toEqual({
scope: 'project', source: 'all', state: 'all', search: 'notes', selectedKey: null,
});
expect(parsePluginWorkspaceSearch(new URLSearchParams('scope=project'), false).scope).toBe('all');
});
it('round-trips canonical filters and source-qualified selection', () => {
const serialized = serializePluginWorkspaceSearch({
scope: 'all',
source: 'local',
state: 'enabled',
search: ' web search ',
selectedKey: 'local:makelore_web_search',
});
expect(serialized.toString()).toBe(
'scope=all&source=local&state=enabled&q=web+search&plugin=local%3Amakelore_web_search',
);
expect(parsePluginWorkspaceSearch(serialized, true)).toEqual({
scope: 'all',
source: 'local',
state: 'enabled',
search: 'web search',
selectedKey: 'local:makelore_web_search',
});
});
});