Skip to content

Commit

Permalink
Merge pull request #4597 from epam/3816-macro-rna-builder-allows-crea…
Browse files Browse the repository at this point in the history
…ting-an-invalid-preset-with-disconnected-sugar

#3816 - Added validations and monomer Item disablement
  • Loading branch information
ilya-asiyuk-epam authored May 31, 2024
2 parents a5a1fc3 + f57a887 commit f4704bc
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 88 deletions.
4 changes: 3 additions & 1 deletion ketcher-autotests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ selectNestedTool - select specific tool that has sub / nested levels.
- Rc: KETCHER_URL=link_to_rc
- Local frontend: KETCHER_URL=http://host.docker.internal:port (port where you run application)
- OPTIONAL: IGNORE_UNSTABLE_TESTS=true (if you want to ignore unstable tests)
- OPTIONAL: ENABLE_POLYMER_EDITOR=true (If you want to run tests for Macromolecule Editor)
- **OPTIONAL: Build frontend**:
if you want to run tests based on the localhost:4002, you can put KETCHER_URL=http://localhost:4002

### Run tests:

**OPTIONAL: Test Polymer Editor **:
If you want to run tests from Polymer Editor, add `ENABLE_POLYMER_EDITOR=true` in scripts:
If you want to run tests from Macromolecule Editor, add `ENABLE_POLYMER_EDITOR=true` in scripts:

- Root package.json: "build:example": "ENABLE_POLYMER_EDITOR=true npm run build -w example";

Expand Down Expand Up @@ -139,6 +140,7 @@ Run this command in the directory "ketcher-autotests"

- `npm run docker:test` run all tests
- `npm run docker:test file_name` run tests in a specific file
- `npm run docker:test file_name:N` run specific test in a file (N - line on which test starts)
- `npm run report` show report
- `npm run docker:update` update all snapshots
- `npm run docker:update:test -- "test_title"` update only 1 snapshot with test_title
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
addMonomerToCenterOfCanvas,
clickInTheMiddleOfTheScreen,
dragMouseTo,
moveMouseToTheMiddleOfTheScreen,
openFileAndAddToCanvasMacro,
pressButton,
receiveFileComparisonData,
Expand Down Expand Up @@ -300,11 +299,11 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click();
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
});
Expand All @@ -317,18 +316,18 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section and saved in local storage after reload.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click();
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
await page.reload();
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
await page.getByTestId('RNA-TAB').click();
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
});
Expand All @@ -339,19 +338,19 @@ test.describe('RNA Library', () => {
Description: System alert that you should rename preset.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
await page.reload();
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
await page.getByTestId('RNA-TAB').click();
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await page.getByTestId('add-to-presets-btn').click();
Expand All @@ -374,23 +373,23 @@ test.describe('RNA Library', () => {
await takeEditorScreenshot(page);
});

test('Add RNA to canvas when Sugar does not contain R3 attachment point(for example 3SS6(nC65C)oxy/ am6(daA)Rsp )', async ({
test('Add to RNA Sugar which does not contain R3 attachment point(for example 3SS6)', async ({
page,
}) => {
/*
Test case: #2507 - Add RNA monomers to canvas https://github.com/epam/ketcher/issues/3615
Description: RNA added to canvas when Sugar does not contain R3 attachment point.
The test is currently not functioning correctly as the bug has not been fixed
Description: Try to add to RNA Sugar which does not contain R3 attachment point(for example 3SS6).
Test was updated since logic for RNA Builder was changed in a scope of https://github.com/epam/ketcher/issues/3816
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.ThreeSS6);
await selectMonomer(page, Bases.NBebnzylAdenine);
await selectMonomer(page, Phosphates.Boranophosphate);
await pressAddToPresetsButton(page);
await page.getByTestId('3SS6(baA)bP_baA_3SS6_bP').click();
await clickInTheMiddleOfTheScreen(page);
await selectRectangleSelectionTool(page);
await takeEditorScreenshot(page);
await page.getByTestId('rna-builder-slot--sugar').click();
await page
.getByTestId("3SS6___3'-Thiol-Modifier 6 S-S from Glen Research")
.click();
await page.getByTestId('rna-builder-slot--sugar').click();
await takeRNABuilderScreenshot(page);
});

test('Add to presets (different combinations: Sugar+Base', async ({
Expand All @@ -401,10 +400,10 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR(A)_A_12ddR_.').click();
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R(A)_A_25R_.').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
});
Expand All @@ -417,10 +416,10 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Phosphates.Boranophosphate);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR()bP_._12ddR_bP').click();
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R()bP_._25R_bP').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
});
Expand All @@ -430,15 +429,13 @@ test.describe('RNA Library', () => {
}) => {
/*
Test case: #2759 - Edit RNA mode
Description: Custom presets added to Presets section.
Description: Custom preset Base+Phosphate could not be added to Presets.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Boranophosphate);
await pressAddToPresetsButton(page);
await page.getByTestId('(A)bP_A_._bP').click();
await expandCollapseRnaBuilder(page);
await takePresetsScreenshot(page);
await page.getByTestId('rna-builder-slot--base').click();
await takeRNABuilderScreenshot(page);
});

test('Add Custom preset to Presets section and Edit', async ({ page }) => {
Expand All @@ -447,18 +444,18 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section and can be edited.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click({
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click({
button: 'right',
});
await page.getByTestId('edit').locator('div').click();
await page.getByTestId('rna-builder-slot--base').click();
await page.getByTestId('baA___N-benzyl-adenine').click();
await page.getByTestId('save-btn').click();
await page.getByTestId('12ddR(baA)Test-6-Ph_baA_12ddR_Test-6-Ph').click();
await page.getByTestId('25R(baA)Test-6-Ph_baA_25R_Test-6-Ph').click();
// To avoid unstable test execution
// Allows see a right preset in a viewport
await expandCollapseRnaBuilder(page);
Expand All @@ -473,26 +470,26 @@ test.describe('RNA Library', () => {
Description: Custom presets added to Presets section then can be duplicated and edited.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Sugars.TwelveddR);
await selectMonomer(page, Sugars.TwentyFiveR);
await selectMonomer(page, Bases.Adenine);
await selectMonomer(page, Phosphates.Test6Ph);
await pressAddToPresetsButton(page);
await page.getByTestId('12ddR(A)Test-6-Ph_A_12ddR_Test-6-Ph').click({
await page.getByTestId('add-to-presets-btn').click();
await page.getByTestId('25R(A)Test-6-Ph_A_25R_Test-6-Ph').click({
button: 'right',
});
await page.getByTestId('duplicateandedit').locator('div').click();
await page.getByTestId('save-btn').click();
// To avoid unstable test execution
// Allows see a right preset in a veiwport
await expandCollapseRnaBuilder(page);
await page.getByTestId('12ddR(A)Test-6-Ph_Copy_A_12ddR_Test-6-Ph').click({
await page.getByTestId('25R(A)Test-6-Ph_Copy_A_25R_Test-6-Ph').click({
button: 'right',
});
await page.getByTestId('edit').click();
await page.getByTestId('rna-builder-slot--phosphate').click();
await page.getByTestId('P___Phosphate').click();
await page.getByTestId('save-btn').click();
await page.getByTestId('12ddR(A)P_A_12ddR_P').click();
await page.getByTestId('25R(A)P_A_25R_P').click();
await takePresetsScreenshot(page);
});

Expand Down Expand Up @@ -658,18 +655,18 @@ test.describe('RNA Library', () => {
await takeEditorScreenshot(page);
});

test('Can not Add Base-Phosphate Combination to Canvas', async ({ page }) => {
test('Can not Add Base-Phosphate Combination to Presets', async ({
page,
}) => {
/*
Test case: #2507 - Add RNA monomers to canvas
Description: Base-Phosphate Combination not added to Canvas.
Description: Base-Phosphate Combination not added to Presets.
*/
await expandCollapseRnaBuilder(page);
await selectMonomer(page, Bases.NBebnzylAdenine);
await selectMonomer(page, Phosphates.Boranophosphate);
await pressAddToPresetsButton(page);
await page.getByTestId('(baA)bP_baA_._bP').click();
await moveMouseToTheMiddleOfTheScreen(page);
await takeEditorScreenshot(page);
await page.getByTestId('rna-builder-slot--base').click();
await takeRNABuilderScreenshot(page);
});

test('Add Sugar and Base Combination to Canvas and connect with bond', async ({
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ const monomerData = [
describe('RNA ContextMenu', () => {
const editPreset = jest.fn();
const duplicatePreset = jest.fn();
const initialState = {
library: {
searchFilter: '',
favorites: {},
monomers: monomerData,
},
rnaBuilder: {
presetsDefault: mockedPresets,
presetsCustom: [],
groupItemValidations: {
Bases: [],
Sugars: [],
Phosphates: [],
},
},
};

it('should render contextMenu correctly', () => {
render(
Expand All @@ -78,17 +94,7 @@ describe('RNA ContextMenu', () => {
editPreset={editPreset}
/>
</div>,
{
library: {
searchFilter: '',
favorites: {},
monomers: monomerData,
},
rnaBuilder: {
presetsDefault: mockedPresets,
presetsCustom: [],
},
},
initialState,
),
);
const presetCard = screen.getByTestId('A_A_R_P');
Expand All @@ -106,17 +112,7 @@ describe('RNA ContextMenu', () => {
editPreset={editPreset}
/>
</div>,
{
library: {
searchFilter: '',
favorites: {},
monomers: monomerData,
},
rnaBuilder: {
presetsDefault: mockedPresets,
presetsCustom: [],
},
},
initialState,
),
);
const preset = screen.getByTestId('A_A_R_P');
Expand All @@ -136,17 +132,7 @@ describe('RNA ContextMenu', () => {
/>
<ModalContainer />
</div>,
{
library: {
searchFilter: '',
favorites: {},
monomers: monomerData,
},
rnaBuilder: {
presetsDefault: mockedPresets,
presetsCustom: [],
},
},
initialState,
),
);
const preset = screen.getByTestId('A_A_R_P');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,26 @@ import { RnaAccordion } from './RnaAccordion';
import { RnaEditor } from './RnaEditor';
import { RnaBuilderContainer } from './styles';
import { useAppDispatch, useAppSelector } from 'hooks';
import { selectUniqueNameError, setUniqueNameError } from 'state/rna-builder';
import {
selectUniqueNameError,
setUniqueNameError,
selectInvalidPresetError,
setInvalidPresetError,
} from 'state/rna-builder';
import { Modal } from 'components/shared/modal';
import { StyledButton } from 'components/monomerLibrary/RnaBuilder/RnaAccordion/styles';

export const RnaBuilder = ({ libraryName, duplicatePreset, editPreset }) => {
const dispatch = useAppDispatch();
const uniqueNameError = useAppSelector(selectUniqueNameError);
const invalidPresetError = useAppSelector(selectInvalidPresetError);
const closeErrorModal = () => {
dispatch(setUniqueNameError(''));
if (uniqueNameError.length > 0) {
dispatch(setUniqueNameError(''));
}
if (invalidPresetError.length > 0) {
dispatch(setInvalidPresetError(''));
}
};
return (
<RnaBuilderContainer>
Expand All @@ -37,14 +48,16 @@ export const RnaBuilder = ({ libraryName, duplicatePreset, editPreset }) => {
editPreset={editPreset}
/>
<Modal
isOpen={!!uniqueNameError}
isOpen={!!uniqueNameError || !!invalidPresetError}
title="Error Message"
onClose={closeErrorModal}
>
<Modal.Content>
<div style={{ padding: '12px' }}>
Preset with name "{uniqueNameError}" already exists. Please choose
another name.
{uniqueNameError &&
`Preset with name "${uniqueNameError}" already exists. Please choose another name.`}
{invalidPresetError &&
`Preset with name "${invalidPresetError}" can't be used. Because it is impossible to establish bonds between monomers. Edit it's structure or choose another one.`}
</div>
</Modal.Content>
<Modal.Footer>
Expand Down
Loading

0 comments on commit f4704bc

Please sign in to comment.