Skip to content

Commit

Permalink
#3385 - Simplified bond check and e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gayane Chilingaryan committed Oct 18, 2023
1 parent 2507b05 commit 9e5ef8e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
29 changes: 15 additions & 14 deletions packages/ketcher-core/src/application/editor/tools/Bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/ketcher-polymer-editor-react/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ function Editor({ theme }: EditorProps) {
autoHideDuration={6000}
>
<StyledToast id="error-tooltip">
<StyledToastContent>{errorTooltipText}</StyledToastContent>
<StyledToastContent data-testid="error-tooltip">
{errorTooltipText}
</StyledToastContent>
<StyledIconButton
iconName="close"
onClick={handleCloseErrorTooltip}
Expand Down

0 comments on commit 9e5ef8e

Please sign in to comment.