chore: Clean up unused files, imports, and work on getting end-to-end tests and unit tests running (#2272)

This commit is contained in:
Erik Ziegler authored and GitHub committed 2021-03-01 16:52:54 +01:00
1 parent 414ebc6850
commit 0db81b30f3
374 files changed
+14138 -21288

No files matched your search

@@ -2,7 +2,7 @@ import MODULE_TYPES from './MODULE_TYPES.js';
import log from './../log.js';
export default class ExtensionManager {
constructor({ commandsManager, servicesManager, hotkeysManager, api, appConfig = {} }) {
constructor({ commandsManager, servicesManager, hotkeysManager, appConfig = {} }) {
this.modules = {};
this.registeredExtensionIds = [];
this.moduleTypeNames = Object.values(MODULE_TYPES);
@@ -11,7 +11,6 @@ export default class ExtensionManager {
this._servicesManager = servicesManager;
this._hotkeysManager = hotkeysManager;
this._appConfig = appConfig;
this._api = api;
this.modulesMap = {};
this.moduleTypeNames.forEach(moduleType => {
@@ -95,15 +94,15 @@ export default class ExtensionManager {
*
* @param {Object[]} extensions - Array of extensions
*/
registerExtensions = (extensions, dataSources) => {
registerExtensions = (extensions, dataSources = []) => {
extensions.forEach(extension => {
const hasConfiguration = Array.isArray(extension);
if (hasConfiguration) {
const [ohifExtension, configuration] = extension;
this.registerExtension(ohifExtension, dataSources, configuration);
this.registerExtension(ohifExtension, configuration, dataSources);
} else {
this.registerExtension(extension, dataSources);
this.registerExtension(extension, {}, dataSources);
}
});
};
@@ -114,12 +113,11 @@ export default class ExtensionManager {
* @param {Object} extension
* @param {Object} configuration
*/
registerExtension = (extension, dataSources, configuration = {}) => {
registerExtension = (extension, configuration = {}, dataSources = []) => {
if (!extension) {
log.warn(
'Attempting to register a null/undefined extension. Exiting early.'
throw new Error(
'Attempting to register a null/undefined extension.'
);
return;
}
let extensionId = extension.id;
@@ -193,6 +191,8 @@ export default class ExtensionManager {
] = element;
});
break;
default:
throw new Error(`Module type invalid: ${moduleType}`);
}
this.modules[moduleType].push({
@@ -241,13 +241,11 @@ export default class ExtensionManager {
try {
const extensionModule = getModuleFn({
appConfig: this._appConfig,
getDataSources: this.getDataSources, // Why pass this in if we're passing in `extensionManager`?
commandsManager: this._commandsManager,
servicesManager: this._servicesManager,
hotkeysManager: this._hotkeysManager,
extensionManager: this,
configuration,
api: this._api,
});
if (!extensionModule) {
@@ -258,14 +256,13 @@ export default class ExtensionManager {
return extensionModule;
} catch (ex) {
log.error(
throw new Error(
`Exception thrown while trying to call ${getModuleFnName} for the ${extensionId} extension`
);
log.error(ex);
}
};
_initDataSourcesModule(extensionModule, extensionId, dataSources) {
_initDataSourcesModule(extensionModule, extensionId, dataSources = []) {
extensionModule.forEach(element => {
const namespace = `${extensionId}.${MODULE_TYPES.DATA_SOURCE}.${element.name}`;
@@ -1,4 +1,3 @@
import { Exception } from 'handlebars';
import ExtensionManager from './ExtensionManager.js';
import MODULE_TYPES from './MODULE_TYPES.js';
import log from './../log.js';
@@ -70,7 +69,7 @@ describe('ExtensionManager.js', () => {
describe('registerExtension()', () => {
it('calls preRegistration() for extension', () => {
// SUT
const fakeExtension = { one: '1', preRegistration: jest.fn() };
const fakeExtension = { id: '1', preRegistration: jest.fn() };
extensionManager.registerExtension(fakeExtension);
// Assert
@@ -81,7 +80,7 @@ describe('ExtensionManager.js', () => {
const extensionConfiguration = { config: 'Some configuration' };
// SUT
const extension = { one: '1', preRegistration: jest.fn() };
const extension = { id: '1', preRegistration: jest.fn() };
extensionManager.registerExtension(extension, extensionConfiguration);
// Assert
@@ -97,18 +96,22 @@ describe('ExtensionManager.js', () => {
const undefinedExtension = undefined;
const nullExtension = null;
extensionManager.registerExtension(undefinedExtension);
extensionManager.registerExtension(nullExtension);
expect(() => {
extensionManager.registerExtension(undefinedExtension);
}).toThrow('Attempting to register a null/undefined extension.');
expect(log.warn.mock.calls.length).toBe(2);
expect(() => {
extensionManager.registerExtension(nullExtension);
}).toThrow('Attempting to register a null/undefined extension.');
});
it('logs a warning if the extension does not have an id', () => {
const extensionWithoutId = {};
extensionManager.registerExtension(extensionWithoutId);
expect(log.warn.mock.calls.length).toBe(1);
expect(() => {
extensionManager.registerExtension(extensionWithoutId);
}).toThrow(new Error('Extension ID not set'));
});
it('tracks which extensions have been registered', () => {
@@ -151,16 +154,13 @@ describe('ExtensionManager.js', () => {
const extensionWithBadModule = {
id: 'hello-world',
getViewportModule: () => {
throw new Exception('Hello World');
throw new Error('Hello World');
},
};
extensionManager.registerExtension(extensionWithBadModule);
expect(log.error.mock.calls.length).toBe(1);
expect(log.error.mock.calls[0][0]).toContain(
'Exception thrown while trying to call'
);
expect(() => {
extensionManager.registerExtension(extensionWithBadModule);
}).toThrow();
});
it('successfully passes dependencies to each module along with extension configuration', () => {
@@ -182,8 +182,10 @@ describe('ExtensionManager.js', () => {
expect(extension[module].mock.calls[0][0]).toEqual({
servicesManager,
commandsManager,
hotkeysManager: undefined,
appConfig,
configuration: extensionConfiguration,
extensionManager
});
}
});
@@ -193,20 +195,29 @@ describe('ExtensionManager.js', () => {
const extension = {
id: 'hello-world',
getViewportModule: () => {
return {};
return [{}];
},
getSopClassHandlerModule: () => {
return {};
return [{}];
},
getPanelModule: () => {
return {};
return [{}];
},
getToolbarModule: () => {
return {};
return [{}];
},
getCommandsModule: () => {
return {};
return [{}];
},
getLayoutTemplateModule: () => {
return [{}];
},
getDataSourcesModule: () => {
return [{}];
},
getContextModule: () => {
return [{}];
}
};
extensionManager.registerExtension(extension);