Skip to content

Commit

Permalink
#5255 – Fix adding new monomers to canvas in sequence mode while edit…
Browse files Browse the repository at this point in the history
…ing RNA in builder (#5261)

* #5255 – Fix adding new monomers to canvas in sequence mode while editing RNA in builder

* #5261 – Add hook mock to unit test
  • Loading branch information
svvald authored Aug 9, 2024
1 parent c27e667 commit 74ddccd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ export const RnaAccordion = ({ libraryName, duplicatePreset, editPreset }) => {
];

const selectItem = (monomer, groupName) => {
if (!isSequenceEditInRNABuilderMode) {
if (!isSequenceEditInRNABuilderMode && !isEditMode) {
editor.events.selectMonomer.dispatch(monomer);
}
if (!isEditMode) return;

if (!isEditMode) {
return;
}

const monomerClass = monomer.props.MonomerClass.toLowerCase();
const currentPreset = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { fireEvent, render, screen } from '@testing-library/react';
import { RnaEditorExpanded } from 'components/monomerLibrary/RnaBuilder/RnaEditor/RnaEditorExpanded/RnaEditorExpanded';
import { EmptyFunction } from 'helpers';

jest.mock('hooks', () => ({
...jest.requireActual('hooks'),
useLayoutMode: () => 'sequence-layout-mode',
}));

describe('Test Rna Editor Expanded component', () => {
it('should render correctly in edit mode', async () => {
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
***************************************************************************/

import { Entities } from 'ketcher-core';
import { Entities, ModeTypes } from 'ketcher-core';
import { MonomerGroups } from 'src/constants';
import { GroupBlock } from './GroupBlock';
import {
Expand Down Expand Up @@ -53,7 +53,7 @@ import {
setSequenceSelectionName,
selectIsActivePresetNewAndEmpty,
} from 'state/rna-builder';
import { useAppSelector } from 'hooks';
import { useAppSelector, useLayoutMode } from 'hooks';
import {
scrollToSelectedMonomer,
scrollToSelectedPreset,
Expand Down Expand Up @@ -126,6 +126,8 @@ export const RnaEditorExpanded = ({
generateSequenceSelectionGroupNames(sequenceSelection),
);

const isSequenceMode = useLayoutMode() === ModeTypes.sequence;

const updatePresetMonomerGroup = () => {
if (activePresetMonomerGroup) {
const groupName =
Expand Down Expand Up @@ -216,7 +218,7 @@ export const RnaEditorExpanded = ({
selectedGroup,
);

if (selectedRNAPartMonomer) {
if (selectedRNAPartMonomer && !isSequenceMode) {
editor.events.selectMonomer.dispatch(selectedRNAPartMonomer);
}
scrollToActiveItemInLibrary(selectedGroup);
Expand Down

0 comments on commit 74ddccd

Please sign in to comment.