feat: expose plugin settings UI API
This commit is contained in:
@@ -14,6 +14,7 @@ describe('VerstakPluginAPI contract', () => {
|
||||
expect(typeof api.settings.write).toBe('function');
|
||||
expect(typeof api.storage.data.read).toBe('function');
|
||||
expect(typeof api.storage.data.write).toBe('function');
|
||||
expect(typeof api.ui.openSettings).toBe('function');
|
||||
expect(typeof api.capabilities.list).toBe('function');
|
||||
expect(typeof api.commands.register).toBe('function');
|
||||
expect(typeof api.commands.execute).toBe('function');
|
||||
@@ -211,6 +212,20 @@ describe('VerstakPluginAPI contract', () => {
|
||||
await expect(api.storage.data.read('missing')).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('ui openSettings publishes the requested settings target in the mock API namespace', async () => {
|
||||
const api = createMockPluginAPI('ui.plugin');
|
||||
const received: unknown[] = [];
|
||||
|
||||
const unsubscribe = await api.events.subscribe('ui.openSettings', (event) => {
|
||||
received.push(event.payload);
|
||||
});
|
||||
|
||||
await api.ui.openSettings('ui.plugin.settings');
|
||||
|
||||
expect(received).toEqual([{ pluginId: 'ui.plugin', panelId: 'ui.plugin.settings' }]);
|
||||
unsubscribe();
|
||||
});
|
||||
|
||||
test('commands register, execute, and unregister', async () => {
|
||||
const api = createMockPluginAPI('cmd.plugin');
|
||||
|
||||
|
||||
@@ -104,6 +104,10 @@ export interface VerstakPluginAPI {
|
||||
};
|
||||
};
|
||||
|
||||
ui: {
|
||||
openSettings(panelId?: string): Promise<void>;
|
||||
};
|
||||
|
||||
capabilities: {
|
||||
has(capability: string): Promise<boolean>;
|
||||
get(capability: string): Promise<{ available: boolean; name?: string; pluginId?: string; status?: string }>;
|
||||
|
||||
@@ -138,6 +138,17 @@ export function createMockPluginAPI(pluginId = 'test.plugin', options: MockPlugi
|
||||
}),
|
||||
},
|
||||
},
|
||||
ui: {
|
||||
openSettings: vi.fn(async (panelId?: string) => {
|
||||
const event = {
|
||||
name: 'ui.openSettings',
|
||||
pluginId,
|
||||
payload: { pluginId, panelId: panelId || '' },
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
(eventHandlers.get('ui.openSettings') || []).slice().forEach((handler) => handler(event));
|
||||
}),
|
||||
},
|
||||
capabilities: {
|
||||
has: vi.fn(async () => false),
|
||||
get: vi.fn(async (name: string) => ({ available: false, name })),
|
||||
|
||||
Reference in New Issue
Block a user