chore: Clean up unused files, imports, and work on getting end-to-end tests and unit tests running (#2272)
This commit is contained in:
1 parent
414ebc6850
commit
0db81b30f3
374 files changed
+14138
-21288
No files matched your search
@@ -18,16 +18,15 @@ import log from '../log.js';
|
||||
* to extend this class, please check it's source before adding new methods.
|
||||
*/
|
||||
export class CommandsManager {
|
||||
constructor({ getAppState, getActiveContexts } = {}) {
|
||||
constructor({ getActiveContexts } = {}) {
|
||||
this.contexts = {};
|
||||
|
||||
if (!getAppState || !getActiveContexts) {
|
||||
log.warn(
|
||||
'CommandsManager was instantiated without getAppState() or getActiveContexts()'
|
||||
if (!getActiveContexts) {
|
||||
throw new Error(
|
||||
'CommandsManager was instantiated without getActiveContexts()'
|
||||
);
|
||||
}
|
||||
|
||||
this._getAppState = getAppState;
|
||||
this._getActiveContexts = getActiveContexts;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,6 @@ describe('CommandsManager', () => {
|
||||
options: { passMeToCommandFn: ':wave:' },
|
||||
},
|
||||
commandsManagerConfig = {
|
||||
getAppState: () => {
|
||||
return {
|
||||
viewers: 'Test',
|
||||
};
|
||||
},
|
||||
getActiveContexts: () => ['VIEWER', 'ACTIVE_VIEWER::CORNERSTONE'],
|
||||
};
|
||||
|
||||
@@ -34,10 +29,10 @@ describe('CommandsManager', () => {
|
||||
expect(localCommandsManager.contexts).toEqual({});
|
||||
});
|
||||
|
||||
it('logs a warning if instantiated without getAppState or getActiveContexts', () => {
|
||||
new CommandsManager();
|
||||
|
||||
expect(log.warn.mock.calls.length).toBe(1);
|
||||
it('throws Error if instantiated without getActiveContexts', () => {
|
||||
expect(() => {
|
||||
new CommandsManager();
|
||||
}).toThrow(new Error('CommandsManager was instantiated without getActiveContexts()'));
|
||||
});
|
||||
|
||||
describe('createContext()', () => {
|
||||
@@ -180,16 +175,6 @@ describe('CommandsManager', () => {
|
||||
expect(command.commandFn.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('Calls commandFn w/ properties from appState', () => {
|
||||
commandsManager.registerCommand('VIEWER', 'TestCommand', command);
|
||||
commandsManager.runCommand('TestCommand', {}, 'VIEWER');
|
||||
|
||||
expect(command.commandFn.mock.calls.length).toBe(1);
|
||||
expect(command.commandFn.mock.calls[0][0].viewers).toEqual(
|
||||
commandsManagerConfig.getAppState().viewers
|
||||
);
|
||||
});
|
||||
|
||||
it('Calls commandFn w/ command definition options', () => {
|
||||
commandsManager.registerCommand('VIEWER', 'TestCommand', command);
|
||||
commandsManager.runCommand('TestCommand', {}, 'VIEWER');
|
||||
|
||||
@@ -19,8 +19,8 @@ export class HotkeysManager {
|
||||
this.isEnabled = true;
|
||||
|
||||
if (!commandsManager) {
|
||||
log.warn(
|
||||
'[hotkeys] HotkeysManager instantiated without a commandsManager. Hotkeys will be unable to find and run commands.'
|
||||
throw new Error(
|
||||
'HotkeysManager instantiated without a commandsManager. Hotkeys will be unable to find and run commands.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export class HotkeysManager {
|
||||
const { UINotificationService } = this._servicesManager.services;
|
||||
UINotificationService.show({
|
||||
title: 'Hotkeys Manager',
|
||||
message: 'Erro while setting hotkeys',
|
||||
message: 'Error while setting hotkeys',
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
@@ -165,8 +165,7 @@ export class HotkeysManager {
|
||||
*/
|
||||
registerHotkeys({ commandName, commandOptions = {}, keys, label, isEditable } = {}, extension) {
|
||||
if (!commandName) {
|
||||
log.warn(`[hotkeys] No command was defined for hotkey "${keys}"`);
|
||||
return;
|
||||
throw new Error(`No command was defined for hotkey "${keys}"`);
|
||||
}
|
||||
|
||||
const commandHash = objectHash({ commandName, commandOptions });
|
||||
|
||||
@@ -2,6 +2,7 @@ import CommandsManager from './CommandsManager.js';
|
||||
import HotkeysManager from './HotkeysManager.js';
|
||||
import hotkeys from './../utils/hotkeys';
|
||||
import log from './../log.js';
|
||||
import objectHash from "object-hash";
|
||||
|
||||
jest.mock('./CommandsManager.js');
|
||||
jest.mock('./../utils/hotkeys');
|
||||
@@ -34,11 +35,10 @@ describe('HotkeysManager', () => {
|
||||
expect(containsAllExpectedProperties).toBe(true);
|
||||
});
|
||||
|
||||
it('logs a warning if instantiated without a commandsManager', () => {
|
||||
new HotkeysManager();
|
||||
|
||||
expect(log.warn.mock.calls.length).toBe(1);
|
||||
expect(log.warn.mock.calls[0][0]).toEqual(
|
||||
it('throws Error if instantiated without a commandsManager', () => {
|
||||
expect(() => {
|
||||
new HotkeysManager();
|
||||
}).toThrow(
|
||||
'HotkeysManager instantiated without a commandsManager. Hotkeys will be unable to find and run commands.'
|
||||
);
|
||||
});
|
||||
@@ -97,6 +97,7 @@ describe('HotkeysManager', () => {
|
||||
expect(firstCallArgs).toEqual(hotkeyDefinitions[0]);
|
||||
expect(secondCallArgs).toEqual(hotkeyDefinitions[1]);
|
||||
});
|
||||
|
||||
it('does not set this.hotkeyDefaults when calling setHotKeys', () => {
|
||||
const hotkeyDefinitions = [{ commandName: 'dance', keys: '+' }];
|
||||
|
||||
@@ -117,30 +118,32 @@ describe('HotkeysManager', () => {
|
||||
});
|
||||
|
||||
describe('registerHotkeys()', () => {
|
||||
it('logs a warning and returns undefined if a commandName is not provided', () => {
|
||||
it('throws an Error if a commandName is not provided', () => {
|
||||
const definition = { commandName: undefined, keys: '+' };
|
||||
|
||||
const result = hotkeysManager.registerHotkeys(definition);
|
||||
|
||||
expect(result).toBe(undefined);
|
||||
expect(log.warn.mock.calls.length).toBe(1);
|
||||
expect(() => {
|
||||
hotkeysManager.registerHotkeys(definition)
|
||||
}).toThrow();
|
||||
});
|
||||
it('updates hotkeyDefinitions property with registered keys', () => {
|
||||
const definition = { commandName: 'dance', label: 'hello', keys: '+' };
|
||||
const expectedHotkeyDefinition = { label: 'hello', keys: '+' };
|
||||
const definition = { commandName: 'dance', commandOptions: {}, label: 'hello', keys: '+', };
|
||||
|
||||
hotkeysManager.registerHotkeys(definition);
|
||||
|
||||
const numOfHotkeyDefinitions = Object.keys(
|
||||
hotkeysManager.hotkeyDefinitions
|
||||
).length;
|
||||
|
||||
const commandHash = objectHash({
|
||||
commandName: definition.commandName,
|
||||
commandOptions: definition.commandOptions
|
||||
});
|
||||
const hotkeyDefinitionForRegisteredCommand =
|
||||
hotkeysManager.hotkeyDefinitions[definition.commandName];
|
||||
hotkeysManager.hotkeyDefinitions[commandHash];
|
||||
|
||||
expect(numOfHotkeyDefinitions).toBe(1);
|
||||
expect(hotkeyDefinitionForRegisteredCommand).toEqual(
|
||||
expectedHotkeyDefinition
|
||||
);
|
||||
expect(Object.keys(hotkeysManager.hotkeyDefinitions)[0]).toEqual(commandHash);
|
||||
expect(hotkeyDefinitionForRegisteredCommand).toEqual(definition);
|
||||
});
|
||||
it('calls hotkeys.bind for the group of keys', () => {
|
||||
const definition = { commandName: 'dance', keys: ['shift', 'e'] };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import guid from '../utils/guid.js';
|
||||
import OHIFError from './OHIFError';
|
||||
import { Vector3 } from 'cornerstone-math';
|
||||
|
||||
const OBJECT = 'object';
|
||||
@@ -13,7 +12,7 @@ const OBJECT = 'object';
|
||||
class ImageSet {
|
||||
constructor(images) {
|
||||
if (Array.isArray(images) !== true) {
|
||||
throw new OHIFError('ImageSet expects an array of images');
|
||||
throw new Error('ImageSet expects an array of images');
|
||||
}
|
||||
|
||||
// @property "images"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import dcmjs from 'dcmjs';
|
||||
import queryString from 'query-string';
|
||||
import dicomParser from 'dicom-parser';
|
||||
import getPixelSpacingInformation from '../utils/metadataProvider/getPixelSpacingInformation';
|
||||
@@ -6,8 +5,6 @@ import fetchPaletteColorLookupTableData from '../utils/metadataProvider/fetchPal
|
||||
import fetchOverlayData from '../utils/metadataProvider/fetchOverlayData';
|
||||
import DicomMetadataStore from '../services/DicomMetadataStore';
|
||||
|
||||
window.dcmjs = dcmjs;
|
||||
|
||||
class MetadataProvider {
|
||||
constructor() {
|
||||
// Define the main "metadataLookup" private property as an immutable property.
|
||||
@@ -426,6 +423,8 @@ class MetadataProvider {
|
||||
};
|
||||
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
@@ -441,8 +440,7 @@ class MetadataProvider {
|
||||
SeriesInstanceUID: splitImageId[2], // Note: splitImageId[3] === 'instances'
|
||||
SOPInstanceUID: splitImageId[4],
|
||||
};
|
||||
}
|
||||
if (imageId.includes('wado?requestType=WADO')) {
|
||||
} else if (imageId.includes('?requestType=WADO')) {
|
||||
const qs = queryString.parse(imageId);
|
||||
|
||||
return {
|
||||
@@ -450,10 +448,10 @@ class MetadataProvider {
|
||||
SeriesInstanceUID: qs.seriesUID,
|
||||
SOPInstanceUID: qs.objectUID,
|
||||
};
|
||||
} else {
|
||||
// Maybe its a non-standard imageId
|
||||
return this.imageIdToUIDs.get(imageId);
|
||||
}
|
||||
|
||||
// Maybe its a non-standard imageId
|
||||
return this.imageIdToUIDs.get(imageId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// @TODO: improve this object
|
||||
/**
|
||||
* Objects to be used to throw errors
|
||||
*/
|
||||
class OHIFError extends Error {
|
||||
constructor(message) {
|
||||
super();
|
||||
this.message = message;
|
||||
this.stack = new Error().stack;
|
||||
this.name = this.constructor.name;
|
||||
}
|
||||
}
|
||||
|
||||
export default OHIFError;
|
||||
@@ -2,14 +2,12 @@ import CommandsManager from './CommandsManager.js';
|
||||
import HotkeysManager from './HotkeysManager.js';
|
||||
import ImageSet from './ImageSet';
|
||||
import MetadataProvider from './MetadataProvider';
|
||||
import OHIFError from './OHIFError.js';
|
||||
|
||||
export {
|
||||
MetadataProvider,
|
||||
CommandsManager,
|
||||
HotkeysManager,
|
||||
ImageSet,
|
||||
OHIFError,
|
||||
};
|
||||
|
||||
const classes = {
|
||||
@@ -17,7 +15,6 @@ const classes = {
|
||||
CommandsManager,
|
||||
HotkeysManager,
|
||||
ImageSet,
|
||||
OHIFError,
|
||||
};
|
||||
|
||||
export default classes;
|
||||
Reference in new issue
Block a user