Files
makelore/tests/unit/plugin-workspace-query.test.ts

70 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
parsePluginWorkspaceSearch,
resolvePluginWorkspaceSearch,
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('reports a project-scope fallback while returning the exact canonical URL state', () => {
const fallback = resolvePluginWorkspaceSearch(
new URLSearchParams('scope=project&source=remote&state=broken'),
false,
);
expect(fallback).toEqual({
filters: {
scope: 'all', source: 'all', state: 'all', search: '', selectedKey: null,
},
canonicalSearch: 'scope=all&source=all&state=all',
scopeFallback: true,
});
const afterProjectAppears = resolvePluginWorkspaceSearch(new URLSearchParams(), true);
expect(afterProjectAppears).toEqual({
filters: {
scope: 'project', source: 'all', state: 'all', search: '', selectedKey: null,
},
canonicalSearch: 'scope=project&source=all&state=all',
scopeFallback: false,
});
});
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',
});
});
});