Pass services to each module, improve tests
This commit is contained in:
parent
b6119f8e29
commit
e3e039ad47
@ -110,7 +110,9 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const extensionModule = getModuleFn();
|
const extensionModule = getModuleFn({
|
||||||
|
servicesManager: this._servicesManager,
|
||||||
|
});
|
||||||
|
|
||||||
if (!extensionModule) {
|
if (!extensionModule) {
|
||||||
log.warn(
|
log.warn(
|
||||||
|
|||||||
@ -40,6 +40,30 @@ describe('ExtensionManager.js', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('registerExtension()', () => {
|
describe('registerExtension()', () => {
|
||||||
|
it('calls preRegistration() for extension', () => {
|
||||||
|
// SUT
|
||||||
|
const fakeExtension = { one: '1', preRegistration: jest.fn() };
|
||||||
|
extensionManager.registerExtension(fakeExtension);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(fakeExtension.preRegistration.mock.calls.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls preRegistration() passing configuration and servicesManager instance for extension', () => {
|
||||||
|
const configuration = { config: 'Some configuration' };
|
||||||
|
extensionManager._servicesManager = { services: { TestService: {} } };
|
||||||
|
|
||||||
|
// SUT
|
||||||
|
const fakeExtension = { one: '1', preRegistration: jest.fn() };
|
||||||
|
extensionManager.registerExtension(fakeExtension, configuration);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(fakeExtension.preRegistration.mock.calls[0][0]).toEqual({
|
||||||
|
servicesManager: extensionManager._servicesManager,
|
||||||
|
configuration,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('logs a warning if the extension is null or undefined', () => {
|
it('logs a warning if the extension is null or undefined', () => {
|
||||||
const undefinedExtension = undefined;
|
const undefinedExtension = undefined;
|
||||||
const nullExtension = null;
|
const nullExtension = null;
|
||||||
@ -110,6 +134,25 @@ describe('ExtensionManager.js', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('successfully passes a servicesManager instance to each module', () => {
|
||||||
|
extensionManager._servicesManager = { services: { TestService: {} } };
|
||||||
|
|
||||||
|
const extension = {
|
||||||
|
id: 'hello-world',
|
||||||
|
getViewportModule: jest.fn(),
|
||||||
|
getSopClassHandlerModule: jest.fn(),
|
||||||
|
getPanelModule: jest.fn(),
|
||||||
|
getToolbarModule: jest.fn(),
|
||||||
|
getCommandsModule: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
extensionManager.registerExtension(extension);
|
||||||
|
|
||||||
|
expect(extension.getViewportModule.mock.calls[0][0]).toEqual({
|
||||||
|
servicesManager: extensionManager._servicesManager,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('successfully registers a module for each module type', () => {
|
it('successfully registers a module for each module type', () => {
|
||||||
const extension = {
|
const extension = {
|
||||||
id: 'hello-world',
|
id: 'hello-world',
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default {
|
|||||||
preRegistration({ servicesManager, configuration = {} }) {
|
preRegistration({ servicesManager, configuration = {} }) {
|
||||||
init({ servicesManager, configuration });
|
init({ servicesManager, configuration });
|
||||||
},
|
},
|
||||||
getPanelModule() {
|
getPanelModule({ servicesManager }) {
|
||||||
return {
|
return {
|
||||||
menuOptions: [
|
menuOptions: [
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user