45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
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',
|
|
});
|
|
});
|
|
});
|