Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/ketcher-core/__tests__/application/editor/Editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,38 @@ describe('CoreEditor', () => {
);
expect(editor.monomersLibrary.length).toBe(initialLibrarySize + 1);
});

it('should reject monomer group template without name', () => {
const unnamedPreset = {
root: {
templates: [
{
$ref: 'monomerGroupTemplate-',
},
],
},
'monomerGroupTemplate-': {
type: 'monomerGroupTemplate',
id: '',
name: ' ',
class: 'RNA',
templates: [],
connections: [],
},
};

const initialTemplatesCount =
editor.monomersLibraryParsedJson?.root.templates.length ?? 0;
editor.updateMonomersLibrary(JSON.stringify(unnamedPreset));

expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Monomer group template name cannot be empty or whitespace for template monomerGroupTemplate-',
),
);
expect(editor.monomersLibraryParsedJson?.root.templates.length).toBe(
initialTemplatesCount,
);
});
});
});
7 changes: 7 additions & 0 deletions packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ export class CoreEditor {
return;
}

if (!templateDefinition.name?.trim()) {
KetcherLogger.error(
`Editor::updateMonomersLibrary: Monomer group template name cannot be empty or whitespace for template ${templateRef.$ref}. The template was not added to the library.`,
);
return;
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this._monomersLibraryParsedJson![templateRef.$ref] = templateDefinition;
if (
Expand Down
Loading