75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
parsePluginWorkspaceSearch,
|
|
resolvePluginWorkspaceSearch,
|
|
serializePluginWorkspaceSearch,
|
|
} from '@/pages/Plugins/plugin-workspace-query';
|
|
|
|
describe('plugin workspace URL state', () => {
|
|
it('opens the cloud-backed available tab for a bare route', () => {
|
|
expect(parsePluginWorkspaceSearch(new URLSearchParams(), true)).toEqual({
|
|
scope: 'all', source: 'all', state: 'available', search: '', selectedKey: null,
|
|
});
|
|
expect(parsePluginWorkspaceSearch(new URLSearchParams(), false)).toEqual({
|
|
scope: 'all', source: 'all', state: 'available', 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: 'all', source: 'all', state: 'available', 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: 'available', search: '', selectedKey: null,
|
|
},
|
|
canonicalSearch: 'scope=all&source=all&state=available',
|
|
scopeFallback: true,
|
|
});
|
|
|
|
const afterProjectAppears = resolvePluginWorkspaceSearch(new URLSearchParams(), true);
|
|
expect(afterProjectAppears).toEqual({
|
|
filters: {
|
|
scope: 'all', source: 'all', state: 'available', search: '', selectedKey: null,
|
|
},
|
|
canonicalSearch: 'scope=all&source=all&state=available',
|
|
scopeFallback: false,
|
|
});
|
|
});
|
|
|
|
it('round-trips the installed tab and source-qualified selection', () => {
|
|
const serialized = serializePluginWorkspaceSearch({
|
|
scope: 'all',
|
|
source: 'local',
|
|
state: 'mine',
|
|
search: ' web search ',
|
|
selectedKey: 'local:makelore_web_search',
|
|
});
|
|
expect(serialized.toString()).toBe(
|
|
'scope=all&source=local&state=mine&q=web+search&plugin=local%3Amakelore_web_search',
|
|
);
|
|
expect(parsePluginWorkspaceSearch(serialized, true)).toEqual({
|
|
scope: 'all',
|
|
source: 'local',
|
|
state: 'mine',
|
|
search: 'web search',
|
|
selectedKey: 'local:makelore_web_search',
|
|
});
|
|
});
|
|
|
|
it('maps historical hidden filters onto one of the two visible tabs', () => {
|
|
expect(parsePluginWorkspaceSearch(new URLSearchParams('state=enabled'), true).state).toBe('mine');
|
|
expect(parsePluginWorkspaceSearch(new URLSearchParams('state=all'), true).state).toBe('available');
|
|
});
|
|
});
|