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

@@ -108,7 +108,7 @@ const BaseImplementation = {
);
if (!existingStudy) {
const newStudy = new StudyMetadata(StudyInstanceUID);
const newStudy = createStudyMetadata(StudyInstanceUID);
newStudy.PatientID = study.PatientID;
newStudy.PatientName = study.PatientName;
@@ -130,13 +130,11 @@ class MeasurementService {
*/
createSource(name, version) {
if (!name) {
log.warn('Source name not provided. Exiting early.');
return;
throw new Error('Source name not provided.');
}
if (!version) {
log.warn('Source version not provided. Exiting early.');
return;
throw new Error('Source version not provided.');
}
const id = guid();
@@ -205,23 +203,23 @@ class MeasurementService {
toMeasurementSchema
) {
if (!this._isValidSource(source)) {
log.warn('Invalid source. Exiting early.');
return;
throw new Error('Invalid source.');
}
if (!matchingCriteria) {
log.warn('Matching criteria not provided. Exiting early.');
return;
throw new Error('Matching criteria not provided.');
}
if (!definition) {
log.warn('Definition not provided. Exiting early.');
return;
throw new Error('Definition not provided.');
}
if (!toSourceSchema) {
throw new Error('Mapping function to source schema not provided.');
}
if (!toMeasurementSchema) {
log.warn('Measurement mapping function not provided. Exiting early.');
return;
throw new Error('Measurement mapping function not provided.');
}
const mapping = {
@@ -297,7 +295,7 @@ class MeasurementService {
this.measurements[id] = updatedMeasurement;
this._broadcastChange(
this._broadcastEvent(
// Add an internal flag to say the measurement has not yet been updated at source.
this.EVENTS.MEASUREMENT_UPDATED,
{
@@ -380,14 +378,14 @@ class MeasurementService {
newMeasurement
);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(this.EVENTS.MEASUREMENT_UPDATED, {
this._broadcastEvent(this.EVENTS.MEASUREMENT_UPDATED, {
source,
measurement: newMeasurement,
});
} else {
log.info(`Measurement added.`, newMeasurement);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(this.EVENTS.MEASUREMENT_ADDED, {
this._broadcastEvent(this.EVENTS.MEASUREMENT_ADDED, {
source,
measurement: newMeasurement,
});
@@ -406,22 +404,19 @@ class MeasurementService {
*/
addOrUpdate(source, definition, sourceMeasurement) {
if (!this._isValidSource(source)) {
log.warn('Invalid source. Exiting early.');
return;
throw new Error('Invalid source.');
}
if (!definition) {
throw new Error('No source definition provided.');
}
const sourceInfo = this._getSourceInfo(source);
if (!definition) {
log.warn('No source definition provided. Exiting early.');
return;
}
if (!this._sourceHasMappings(source)) {
log.warn(
throw new Error(
`No measurement mappings found for '${sourceInfo}' source. Exiting early.`
);
return;
}
let measurement = {};
@@ -437,24 +432,22 @@ class MeasurementService {
/* Assign measurement source instance */
measurement.source = source;
} catch (error) {
log.warn(
throw new Error(
`Failed to map '${sourceInfo}' measurement for definition ${definition}:`,
error.message
);
return;
}
if (!this._isValidMeasurement(measurement)) {
log.warn(
throw new Error(
`Attempting to add or update a invalid measurement provided by '${sourceInfo}'. Exiting early.`
);
return;
}
let internalId = sourceMeasurement.id;
if (!internalId) {
internalId = guid();
log.warn(`Measurement ID not found. Generating UID: ${internalId}`);
log.info(`Measurement ID not found. Generating UID: ${internalId}`);
}
const newMeasurement = {
@@ -469,15 +462,15 @@ class MeasurementService {
newMeasurement
);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(this.EVENTS.MEASUREMENT_UPDATED, {
this._broadcastEvent(this.EVENTS.MEASUREMENT_UPDATED, {
source,
measurement: newMeasurement,
notYetUpdatedAtSource: false,
});
} else {
log.info(`Measurement added.`, newMeasurement);
log.info('Measurement added.', newMeasurement);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(this.EVENTS.MEASUREMENT_ADDED, {
this._broadcastEvent(this.EVENTS.MEASUREMENT_ADDED, {
source,
measurement: newMeasurement,
});
@@ -500,7 +493,7 @@ class MeasurementService {
}
delete this.measurements[id];
this._broadcastChange(this.EVENTS.MEASUREMENT_REMOVED, {
this._broadcastEvent(this.EVENTS.MEASUREMENT_REMOVED, {
source,
measurement: id, // This is weird :shrug:
});
@@ -508,7 +501,7 @@ class MeasurementService {
clearMeasurements() {
this.measurements = {};
this._broadcastChange(this.EVENTS.MEASUREMENTS_CLEARED);
this._broadcastEvent(this.EVENTS.MEASUREMENTS_CLEARED);
}
jumpToMeasurement(viewportIndex, id) {
@@ -559,7 +552,7 @@ class MeasurementService {
*/
clear() {
this.measurements = {};
this._broadcastChange(this.EVENTS.MEASUREMENTS_CLEARED);
this._broadcastEvent(this.EVENTS.MEASUREMENTS_CLEARED);
}
/**
@@ -618,27 +611,6 @@ class MeasurementService {
);
}
/**
* Broadcasts measurement changes.
*
* @param {string} eventName The event name.add
* @param {object} eventData.source The measurement source.
* @param {object} eventData.measurement The measurement.
* @param {boolean} eventData.notYetUpdatedAtSource True if the measurement was edited
* within the measurement service and the source needs to update.
* @return void
*/
_broadcastChange(eventName, eventData) {
const hasListeners = Object.keys(this.listeners).length > 0;
const hasCallbacks = Array.isArray(this.listeners[eventName]);
if (hasListeners && hasCallbacks) {
this.listeners[eventName].forEach(listener => {
listener.callback(eventData);
});
}
}
/**
* Check if a given measurement data is valid.
*
@@ -13,7 +13,7 @@ describe('MeasurementService.js', () => {
let source;
let definition;
let matchingCriteria;
let toAnnotation;
let toSourceSchema;
let toMeasurement;
let annotation;
@@ -40,8 +40,14 @@ describe('MeasurementService.js', () => {
],
source: source,
};
toAnnotation = () => annotation;
toMeasurement = () => measurement;
toSourceSchema = () => annotation;
toMeasurement = () => {
if (Object.keys(measurement).includes('invalidProperty')) {
throw new Error('Measurement does not match schema');
}
return measurement;
}
matchingCriteria = {
valueType: measurementService.VALUE_TYPES.POLYLINE,
points: 2,
@@ -55,16 +61,16 @@ describe('MeasurementService.js', () => {
measurementService.createSource('Testing', '1');
});
it('logs warning and return early if no name provided', () => {
measurementService.createSource(null, '1');
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no name provided', () => {
expect(() => {
measurementService.createSource(null, '1')
}).toThrow(new Error('Source name not provided.'));
});
it('logs warning and return early if no version provided', () => {
measurementService.createSource('Testing', null);
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no version provided', () => {
expect(() => {
measurementService.createSource('Testing', null)
}).toThrow(new Error('Source version not provided.'));
});
});
@@ -74,83 +80,84 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
});
it('logs warning and return early if no matching criteria provided', () => {
measurementService.addMapping(
source,
definition,
null,
toAnnotation,
toMeasurement
);
it('throws Error if invalid source provided', () => {
expect(() => {
const invalidSource = {};
expect(log.warn.mock.calls.length).toBe(1);
measurementService.addMapping(
invalidSource,
definition,
matchingCriteria,
toSourceSchema,
toMeasurement
);
}).toThrow(new Error('Invalid source.'));
});
it('logs warning and return early if invalid source provided', () => {
const invalidSoure = {};
measurementService.addMapping(
invalidSoure,
definition,
matchingCriteria,
toAnnotation,
toMeasurement
);
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no matching criteria provided', () => {
expect(() => {
measurementService.addMapping(
source,
definition,
null,
toSourceSchema,
toMeasurement
);
}).toThrow(new Error('Matching criteria not provided.'));
});
it('logs warning and return early if no source provided', () => {
measurementService.addMapping(
null /* source */,
definition,
matchingCriteria,
toAnnotation,
toMeasurement
);
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no source provided', () => {
expect(() => {
measurementService.addMapping(
null /* source */,
definition,
matchingCriteria,
toSourceSchema,
toMeasurement
);
}).toThrow(new Error('Invalid source.'));
});
it('logs warning and return early if no definition provided', () => {
measurementService.addMapping(
source,
null /* definition */,
matchingCriteria,
toAnnotation,
toMeasurement
);
expect(log.warn.mock.calls.length).toBe(1);
expect(() => {
measurementService.addMapping(
source,
null /* definition */,
matchingCriteria,
toSourceSchema,
toMeasurement
);
}).toThrow(new Error('Definition not provided.'));
});
it('logs warning and return early if no measurement mapping function provided', () => {
measurementService.addMapping(
source,
definition,
matchingCriteria,
null /* toAnnotation */,
toMeasurement
);
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no measurement mapping function provided', () => {
expect(() => {
measurementService.addMapping(
source,
definition,
matchingCriteria,
null /* toSourceSchema */,
toMeasurement
);
}).toThrow(new Error('Mapping function to source schema not provided.'));
});
it('logs warning and return early if no annotation mapping function provided', () => {
measurementService.addMapping(
source,
definition,
matchingCriteria,
toAnnotation,
null /* toMeasurement */
);
expect(log.warn.mock.calls.length).toBe(1);
it('throws Error if no annotation mapping function provided', () => {
expect(() => {
measurementService.addMapping(
source,
definition,
matchingCriteria,
toSourceSchema,
null /* toMeasurement */
);
}).toThrow(new Error('Measurement mapping function not provided.'));
});
});
@@ -160,7 +167,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
const measurementId = source.addOrUpdate(definition, annotation);
@@ -174,7 +181,7 @@ describe('MeasurementService.js', () => {
source,
definition,
{},
toAnnotation,
toSourceSchema,
toMeasurement
);
const measurementId = source.addOrUpdate(definition, annotation);
@@ -196,7 +203,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -215,7 +222,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -235,7 +242,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -248,9 +255,9 @@ describe('MeasurementService.js', () => {
});
it('fails to add new measurements when no mapping', () => {
source.addOrUpdate(definition, measurement);
expect(log.warn.mock.calls.length).toBe(1);
expect(() => {
source.addOrUpdate(definition, measurement);
}).toThrow()
});
it('fails to add new measurements when invalid mapping function', () => {
@@ -258,13 +265,13 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
1 /* Invalid */
);
source.addOrUpdate(definition, measurement);
expect(log.warn.mock.calls.length).toBe(1);
expect(() => {
source.addOrUpdate(definition, measurement);
}).toThrow()
});
it('adds new measurement with custom id', () => {
@@ -274,7 +281,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -291,28 +298,28 @@ describe('MeasurementService.js', () => {
expect(newMeasurement).toEqual(savedMeasurement);
});
it('logs warning and return if adding invalid measurement', () => {
it('throws Error if adding invalid measurement', () => {
measurement.invalidProperty = {};
measurementService.addMapping(
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
source.addOrUpdate(definition, measurement);
expect(log.warn.mock.calls.length).toBe(2);
expect(() => {
source.addOrUpdate(definition, measurement);
}).toThrow()
});
it('updates existent measurement', () => {
it('updates existing measurement', () => {
measurementService.addMapping(
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -333,7 +340,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -357,7 +364,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -384,7 +391,7 @@ describe('MeasurementService.js', () => {
source,
definition,
matchingCriteria,
toAnnotation,
toSourceSchema,
toMeasurement
);
@@ -65,6 +65,8 @@ export default class ToolBarService {
: !this.state.toggles[itemId];
break;
}
default:
throw new Error(`Invalid interaction type: ${interactionType}`);
}
// Run command if there's one associated
@@ -83,7 +85,7 @@ export default class ToolBarService {
this.state.groups[groupId] = itemId;
}
this._broadcastChange(this.EVENTS.TOOL_BAR_STATE_MODIFIED, {});
this._broadcastEvent(this.EVENTS.TOOL_BAR_STATE_MODIFIED, {});
}
getButtons() {
@@ -97,7 +99,7 @@ export default class ToolBarService {
setButton(id, button) {
if (this.buttons[id]) {
this.buttons[id] = merge(this.buttons[id], button);
this._broadcastChange(this.EVENTS.TOOL_BAR_MODIFIED, {
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, {
buttons: this.buttons,
button: this.buttons[id],
buttonSections: this.buttonSections,
@@ -107,7 +109,7 @@ export default class ToolBarService {
setButtons(buttons) {
this.buttons = buttons;
this._broadcastChange(this.EVENTS.TOOL_BAR_MODIFIED, {
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, {
buttons: this.buttons,
buttonSections: this.buttonSections,
});
@@ -138,7 +140,7 @@ export default class ToolBarService {
// Props check important for validation here...
this.buttonSections[key] = buttons;
this._broadcastChange(this.EVENTS.TOOL_BAR_MODIFIED, {});
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, {});
}
/**
@@ -178,26 +180,9 @@ export default class ToolBarService {
}
});
this._broadcastChange(this.EVENTS.TOOL_BAR_MODIFIED, {});
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, {});
}
/**
* Broadcasts toolbarService changes.
*
* @param {string} eventName The event name
* @return void
*/
_broadcastChange = (eventName, callbackProps) => {
const hasListeners = Object.keys(this.listeners).length > 0;
const hasCallbacks = Array.isArray(this.listeners[eventName]);
if (hasListeners && hasCallbacks) {
this.listeners[eventName].forEach(listener => {
listener.callback(callbackProps);
});
}
};
/**
*
* @param {*} btn
@@ -28,6 +28,7 @@ const serviceImplementation = {
*/
function _show({
viewportIndex,
id,
type,
message,
actions,
@@ -36,6 +37,7 @@ function _show({
}) {
return serviceImplementation._show({
viewportIndex,
id,
type,
message,
actions,