From a227e96f94f09fbaa00ad0d3f605b0a402f66011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Sun, 19 May 2024 09:57:45 +0200 Subject: [PATCH] Add new tests --- packages/application/src/plugins.ts | 2 +- packages/application/tests/src/index.spec.ts | 90 ++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/packages/application/src/plugins.ts b/packages/application/src/plugins.ts index 2f447ef5c..34f8982fa 100644 --- a/packages/application/src/plugins.ts +++ b/packages/application/src/plugins.ts @@ -117,7 +117,7 @@ export interface IPlugin { } /** - * Abstract plugin registry. + * Plugin registry. */ export class PluginRegistry { constructor(options: PluginRegistry.IOptions = {}) { diff --git a/packages/application/tests/src/index.spec.ts b/packages/application/tests/src/index.spec.ts index ba7a46c63..e688ad915 100644 --- a/packages/application/tests/src/index.spec.ts +++ b/packages/application/tests/src/index.spec.ts @@ -28,6 +28,35 @@ describe('@lumino/application', () => { expect(app.contextMenu).to.be.instanceOf(ContextMenu); expect(app.shell).to.equal(shell); }); + + it('should accept an external plugin registry', async () => { + const shell = new Widget(); + const pluginRegistry = new PluginRegistry(); + const id1 = 'plugin1'; + pluginRegistry.registerPlugin({ + id: id1, + activate: () => { + // no-op + } + }); + const id2 = 'plugin2'; + pluginRegistry.registerPlugin({ + id: id2, + activate: () => { + // no-op + } + }); + + const app = new Application({ + shell, + pluginRegistry + }); + + await pluginRegistry.activatePlugin(id2); + + expect(app.hasPlugin(id1)).to.be.true; + expect(app.isPluginActivated(id2)).to.be.true; + }); }); describe('#getPluginDescription', () => { @@ -869,6 +898,67 @@ describe('@lumino/application', () => { expect(plugins.hasPlugin(id)).to.be.true; }); + + it('should refuse to register not allowed plugins', async () => { + const plugins = new PluginRegistry({ + allowedPlugins: new Set(['id1']) + }); + expect(function () { + plugins.registerPlugin({ + id: 'id', + activate: () => { + /* no-op */ + } + }); + }).to.throw(); + plugins.registerPlugin({ + id: 'id1', + activate: () => { + /* no-op */ + } + }); + }); + + it('should refuse to register blocked plugins', async () => { + const plugins = new PluginRegistry({ + blockedPlugins: new Set(['id1']) + }); + expect(function () { + plugins.registerPlugin({ + id: 'id1', + activate: () => { + /* no-op */ + } + }); + }).to.throw(); + plugins.registerPlugin({ + id: 'id2', + activate: () => { + /* no-op */ + } + }); + }); + + it('should use allowed list over blocked list of plugins', async () => { + const plugins = new PluginRegistry({ + allowedPlugins: new Set(['id1', 'id2']), + blockedPlugins: new Set(['id2']) + }); + expect(function () { + plugins.registerPlugin({ + id: 'id', + activate: () => { + /* no-op */ + } + }); + }).to.throw(); + plugins.registerPlugin({ + id: 'id2', + activate: () => { + /* no-op */ + } + }); + }); }); describe('#deregisterPlugin', () => {