Skip to content

Commit

Permalink
Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed May 19, 2024
1 parent a10d181 commit a227e96
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/application/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface IPlugin<T, U> {
}

/**
* Abstract plugin registry.
* Plugin registry.
*/
export class PluginRegistry<T = any> {
constructor(options: PluginRegistry.IOptions = {}) {
Expand Down
90 changes: 90 additions & 0 deletions packages/application/tests/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit a227e96

Please sign in to comment.