diff --git a/packages/core/src/molecule/addMoleculeValidation.test.ts b/packages/core/src/molecule/addMoleculeValidation.test.ts index 10ef3ba5..46632b29 100644 --- a/packages/core/src/molecule/addMoleculeValidation.test.ts +++ b/packages/core/src/molecule/addMoleculeValidation.test.ts @@ -68,6 +68,75 @@ describe('parseMolecules()', () => { } ) }) + + it('should not error on null values in molecules array', () => { + // when null value passed in array + const mockGlobalParameters = { + molecules: [null] as any + } + const mockGlobalSchema: JSONSchema7 = { + type: 'object', + properties: { + molecules: { + title: 'Input Molecules', + description: 'The input molecules that will be used for docking.', + $comment: 'Molecules must be provided in PDB format. These PDB files can be single molecules or ensembles using the MODEL/ENDMDL statements.', + type: 'array', + minItems: 1, + maxItems: 20, + items: { + type: 'string', + format: 'uri-reference' + }, + format: 'moleculefilepaths' + } + }, + additionalProperties: false + } + const mockFiles = {} + + // return empty array + const actual1 = parseMolecules( + mockGlobalParameters, + mockGlobalSchema, + mockFiles + ) + expect(actual1).toEqual([[], 'molecules']) + }) + it('should not error on undefined values in molecules array', () => { + // when undefined value passed in array + const mockGlobalParameters = { + molecules: [undefined] as any + } + const mockGlobalSchema: JSONSchema7 = { + type: 'object', + properties: { + molecules: { + title: 'Input Molecules', + description: 'The input molecules that will be used for docking.', + $comment: 'Molecules must be provided in PDB format. These PDB files can be single molecules or ensembles using the MODEL/ENDMDL statements.', + type: 'array', + minItems: 1, + maxItems: 20, + items: { + type: 'string', + format: 'uri-reference' + }, + format: 'moleculefilepaths' + } + }, + additionalProperties: false + } + const mockFiles = {} + + // return empty array + const actual1 = parseMolecules( + mockGlobalParameters, + mockGlobalSchema, + mockFiles + ) + expect(actual1).toEqual([[], 'molecules']) + }) }) describe('addMoleculeValidation()', () => { diff --git a/packages/core/src/molecule/addMoleculeValidation.ts b/packages/core/src/molecule/addMoleculeValidation.ts index 78b107fd..446e92a2 100644 --- a/packages/core/src/molecule/addMoleculeValidation.ts +++ b/packages/core/src/molecule/addMoleculeValidation.ts @@ -20,6 +20,7 @@ export function parseMolecules ( if (globalSchema.properties === undefined) { return [[], undefined] } + // find prop which has format:moleculefilepaths const moleculesPropNameAndSchema = Object.entries( globalSchema.properties @@ -42,8 +43,13 @@ export function parseMolecules ( // find file of molecule path // TODO check whether files are actually PDB files using uiSchema.molecules..items.ui:options.accept: .pdb const moleculeFiles = moleculeFilePaths - // ignore undefined entries (invalid entries) - .filter(file => file !== undefined) + // ignore undefined/null entries (invalid entries) + .filter(file => { + // check on undefined value in array incl. string value + if (typeof file === 'undefined') return false + // check for null value + return file !== null + }) .map((p) => files[p]) // parse file