diff --git a/ketcher-autotests/tests/Macromolecule-editor/Polymer-Bond-Tool/polymer-bond-tool.spec.ts b/ketcher-autotests/tests/Macromolecule-editor/Polymer-Bond-Tool/polymer-bond-tool.spec.ts index ba59b7c576..e1bd7f5060 100644 --- a/ketcher-autotests/tests/Macromolecule-editor/Polymer-Bond-Tool/polymer-bond-tool.spec.ts +++ b/ketcher-autotests/tests/Macromolecule-editor/Polymer-Bond-Tool/polymer-bond-tool.spec.ts @@ -1,10 +1,12 @@ -import { test } from '@playwright/test'; +import { test, expect } from '@playwright/test'; import { selectSingleBondTool, waitForPageInit, takePageScreenshot, + addMonomerToCanvas, } from '@utils'; import { turnOnMacromoleculesEditor } from '@utils/macromolecules'; +import { bondTwoMonomers } from '@utils/macromolecules/polymerBond'; /* eslint-disable no-magic-numbers */ test.describe('Polymer Bond Tool', () => { @@ -90,4 +92,28 @@ test.describe('Polymer Bond Tool', () => { await takePageScreenshot(page); }); + + test('Select monomers and pass a bond', async ({ page }) => { + /* + Test case: Macro: #3385 - Overlapping of bonds between 2 monomers + https://github.com/epam/ketcher/issues/3385 + Description: The system shall unable user to create more + than 1 bond between the first and the second monomer + */ + const MONOMER_NAME = 'Tza___3-thiazolylalanine'; + const MONOMER_ALIAS = 'Tza'; + await addMonomerToCanvas(page, MONOMER_NAME, 300, 300); + await addMonomerToCanvas(page, MONOMER_NAME, 500, 500); + const peptides = await page.getByText(MONOMER_ALIAS).locator('..'); + const peptide1 = peptides.nth(0); + const peptide2 = peptides.nth(1); + await selectSingleBondTool(page); + await bondTwoMonomers(page, peptide1, peptide2); + await bondTwoMonomers(page, peptide2, peptide1); + await page.waitForSelector('#error-tooltip'); + const errorTooltip = await page.getByTestId('error-tooltip').innerText(); + const errorMessage = + "There can't be more than 1 bond between the first and the second monomer"; + expect(errorTooltip).toEqual(errorMessage); + }); }); diff --git a/packages/ketcher-core/src/application/editor/tools/Bond.ts b/packages/ketcher-core/src/application/editor/tools/Bond.ts index e4df12c002..af998f05f4 100644 --- a/packages/ketcher-core/src/application/editor/tools/Bond.ts +++ b/packages/ketcher-core/src/application/editor/tools/Bond.ts @@ -168,20 +168,21 @@ class PolymerBond implements BaseTool { const firstMonomer = this.bondRenderer?.polymerBond?.firstMonomer; const secondMonomer = renderer.monomer; - for (const key in secondMonomer.attachmentPointsToBonds) { - const bond = secondMonomer.attachmentPointsToBonds[key]; - if (bond !== null) { - if ( - (bond.firstMonomer === firstMonomer && - bond.secondMonomer === secondMonomer) || - (bond.firstMonomer === secondMonomer && - bond.secondMonomer === firstMonomer) - ) { - this.editor.events.error.dispatch( - "There can't be more than 1 bond between the first and the second monomer", - ); - return; - } + for (const attachmentPoint in secondMonomer.attachmentPointsToBonds) { + const bond = secondMonomer.attachmentPointsToBonds[attachmentPoint]; + if (!bond) { + continue; + } + const alreadyHasBond = + (bond.firstMonomer === firstMonomer && + bond.secondMonomer === secondMonomer) || + (bond.firstMonomer === secondMonomer && + bond.secondMonomer === firstMonomer); + if (alreadyHasBond) { + this.editor.events.error.dispatch( + "There can't be more than 1 bond between the first and the second monomer", + ); + return; } } diff --git a/packages/ketcher-polymer-editor-react/src/Editor.tsx b/packages/ketcher-polymer-editor-react/src/Editor.tsx index 65a368967c..4d77e45907 100644 --- a/packages/ketcher-polymer-editor-react/src/Editor.tsx +++ b/packages/ketcher-polymer-editor-react/src/Editor.tsx @@ -202,7 +202,9 @@ function Editor({ theme }: EditorProps) { autoHideDuration={6000} > - {errorTooltipText} + + {errorTooltipText} +