-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro: #3041 – RNA Builder. Delete presets. #3414
Merged
+3,954
−977
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ec7aefc
#3041 Delete RNA presets.
StarlaStarla 63d20e7
#3041 fix right click preset
StarlaStarla e243fdb
#3041 fix auto tests
StarlaStarla 0421b02
#3041 remove skip for tests
StarlaStarla b18423c
#3041 fix screenshots
StarlaStarla 2711c70
#3041 – updated screenshots
Nitvex 132a6ab
#3041 update implementation
StarlaStarla 00e6692
Merge branch 'master' of github.com:epam/ketcher into 3041-rna-builde…
StarlaStarla 5959683
#3041 update screenshots
StarlaStarla 318d946
#3041 add dots menu and change delete dialog style
StarlaStarla 181bca2
#3041 update screenshot
StarlaStarla 2580368
#3041 align modal style
StarlaStarla fc3c898
Merge branch 'master' of github.com:epam/ketcher into 3041-rna-builde…
StarlaStarla d857fdd
#3041 update screenshots
StarlaStarla 3d3bae5
Merge branch 'master' of github.com:epam/ketcher into 3041-rna-builde…
StarlaStarla 2dbc7ea
#3041 update screenshots
StarlaStarla fe2dd42
#3041 fix ci babel audit issue
StarlaStarla c077861
#3041 update ui design
StarlaStarla da3dba4
#3041 update screenshots
StarlaStarla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ketcher-autotests/tests/Macromolecule-editor/RNAEditor/delete-preset.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Page, test } from '@playwright/test'; | ||
import { POLYMER_TOGGLER, RNA_TAB } from '../../../constants/testIdConstants'; | ||
import { waitForPageInit } from '@utils/common'; | ||
import { takePageScreenshot } from '@utils'; | ||
|
||
async function gotoRNA(page: Page) { | ||
await page.getByTestId(POLYMER_TOGGLER).click(); | ||
await page.getByTestId(RNA_TAB).click(); | ||
} | ||
|
||
test.describe('Macromolecules delete RNA presets', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await waitForPageInit(page); | ||
await gotoRNA(page); | ||
}); | ||
|
||
test.afterEach(async ({ page }) => { | ||
await takePageScreenshot(page); | ||
}); | ||
|
||
test('Should not delete default RNA preset', async ({ page }) => { | ||
await page.getByTestId('cancel-btn').click(); | ||
|
||
await page.getByTestId('A_A_R_P').click({ button: 'right' }); | ||
}); | ||
|
||
test('Delete copy RNA preset', async ({ page }) => { | ||
await page.getByTestId('cancel-btn').click(); | ||
|
||
await page.getByTestId('A_A_R_P').click({ button: 'right' }); | ||
|
||
await page.getByTestId('duplicateandedit').click(); | ||
|
||
await page.getByTestId('A_Copy_A_R_P').click(); | ||
await page.getByTestId('A_Copy_A_R_P').click({ button: 'right' }); | ||
|
||
await page.getByTestId('deletepreset').click(); | ||
|
||
await takePageScreenshot(page); | ||
|
||
await page.getByTitle('Delete').click(); | ||
}); | ||
}); |
Binary file added
BIN
+61.2 KB
...s/Macromolecules-delete-RNA-presets-Delete-copy-RNA-preset-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.3 KB
...s/Macromolecules-delete-RNA-presets-Delete-copy-RNA-preset-2-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.5 KB
...es-delete-RNA-presets-Should-not-delete-default-RNA-preset-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/**************************************************************************** | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
***************************************************************************/ | ||
|
||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { ModalContainer } from 'components/modal/modalContainer'; | ||
import { RnaBuilder } from 'components/monomerLibrary/RnaBuilder'; | ||
import { MONOMER_TYPES } from 'src/constants'; | ||
|
||
jest.mock('../../../src/helpers/dom.ts', () => { | ||
return { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
scrollToElement: () => {}, | ||
}; | ||
}); | ||
const monomerData = [ | ||
{ | ||
struct: {}, | ||
props: { | ||
Name: 'Ribose', | ||
MonomerType: 'RNA', | ||
MonomerName: 'R', | ||
MonomerCode: 'R', | ||
MonomerNaturalAnalogCode: 'R', | ||
BranchMonomer: 'false', | ||
MonomerCaps: '[R1]H', | ||
}, | ||
}, | ||
{ | ||
struct: {}, | ||
props: { | ||
Name: 'Phosphate', | ||
MonomerType: 'RNA', | ||
MonomerName: 'P', | ||
MonomerCode: 'P', | ||
MonomerNaturalAnalogCode: 'P', | ||
BranchMonomer: 'false', | ||
MonomerCaps: '[R1]O', | ||
}, | ||
}, | ||
{ | ||
props: { | ||
Name: 'Adenine', | ||
MonomerType: 'RNA', | ||
MonomerName: 'A', | ||
MonomerCode: 'A', | ||
MonomerNaturalAnalogCode: 'A', | ||
BranchMonomer: 'true', | ||
MonomerCaps: '[R1]H', | ||
}, | ||
}, | ||
]; | ||
describe('RNA ContextMenu', () => { | ||
it('should render contextMenu correctly', () => { | ||
render( | ||
withThemeAndStoreProvider( | ||
<RnaBuilder libraryName={MONOMER_TYPES.RNA} />, | ||
{ | ||
library: { | ||
searchFilter: '', | ||
favorites: {}, | ||
monomers: monomerData, | ||
}, | ||
}, | ||
), | ||
); | ||
const cancelButton = screen.getByTestId('cancel-btn'); | ||
fireEvent.click(cancelButton); | ||
const presetCard = screen.getByTestId('A_A_R_P'); | ||
fireEvent.contextMenu(presetCard); | ||
expect(screen.getByTestId('deletepreset')).toBeInTheDocument(); | ||
}); | ||
|
||
it("should disable 'Delete Preset' menu when trying to delete default preset", () => { | ||
render( | ||
withThemeAndStoreProvider( | ||
<RnaBuilder libraryName={MONOMER_TYPES.RNA} />, | ||
{ | ||
library: { | ||
searchFilter: '', | ||
favorites: {}, | ||
monomers: monomerData, | ||
}, | ||
}, | ||
), | ||
); | ||
const cancelButton = screen.getByTestId('cancel-btn'); | ||
fireEvent.click(cancelButton); | ||
const preset = screen.getByTestId('A_A_R_P'); | ||
fireEvent.contextMenu(preset); | ||
const deleteMenu = screen.getByTestId('deletepreset'); | ||
expect(deleteMenu.className).toContain('disabled'); | ||
}); | ||
|
||
it("should delete preset correctly when click menu 'Delete Preset'", () => { | ||
render( | ||
withThemeAndStoreProvider( | ||
<div> | ||
<RnaBuilder libraryName={MONOMER_TYPES.RNA} /> | ||
<ModalContainer /> | ||
</div>, | ||
{ | ||
library: { | ||
searchFilter: '', | ||
favorites: {}, | ||
monomers: monomerData, | ||
}, | ||
}, | ||
), | ||
); | ||
const cancelButton = screen.getByTestId('cancel-btn'); | ||
fireEvent.click(cancelButton); | ||
const preset = screen.getByTestId('A_A_R_P'); | ||
fireEvent.contextMenu(preset); | ||
const duplicateMenu = screen.getByTestId('duplicateandedit'); | ||
fireEvent.click(duplicateMenu); | ||
const presetCopyCard = screen.getByTestId('A_Copy_A_R_P'); | ||
fireEvent.contextMenu(presetCopyCard); | ||
const deleteMenu = screen.getByTestId('deletepreset'); | ||
fireEvent.click(deleteMenu); | ||
const deleteBtn = screen.getByTitle('Delete'); | ||
fireEvent.click(deleteBtn); | ||
expect(presetCopyCard).not.toBeInTheDocument(); | ||
}); | ||
}); |
65 changes: 65 additions & 0 deletions
65
packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Item, ItemParams, Menu, Separator } from 'react-contexify'; | ||
import { openModal } from 'state/modal'; | ||
import { useAppDispatch, useAppSelector } from 'hooks'; | ||
import { ReactElement } from 'react'; | ||
import { CONTEXT_MENU_ID } from './types'; | ||
import { selectActivePreset } from 'state/rna-builder'; | ||
|
||
export const RNAContextMenu = () => { | ||
const dispatch = useAppDispatch(); | ||
const activePreset = useAppSelector(selectActivePreset); | ||
const RNAMenus = [ | ||
{ name: 'duplicateandedit', title: 'Duplicate and Edit...' }, | ||
{ name: 'edit', title: 'Edit...', seperator: true }, | ||
{ name: 'deletepreset', title: 'Delete Preset' }, | ||
]; | ||
|
||
const isItemDisabled = (name: string) => { | ||
if (name === 'deletepreset' && activePreset?.default) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
const handleMenuChange = ({ id, props }: ItemParams) => { | ||
switch (id) { | ||
case 'duplicateandedit': | ||
props.duplicatePreset(); | ||
break; | ||
case 'edit': | ||
props.activateEditMode(); | ||
break; | ||
case 'deletepreset': | ||
dispatch(openModal('delete')); | ||
break; | ||
} | ||
}; | ||
|
||
const assembleMenuItems = () => { | ||
const items: ReactElement[] = []; | ||
RNAMenus.forEach(({ name, title, seperator }, index) => { | ||
const item = ( | ||
<Item | ||
id={name} | ||
onClick={handleMenuChange} | ||
key={name} | ||
disabled={isItemDisabled(name)} | ||
data-testid={name} | ||
> | ||
<span>{title}</span> | ||
</Item> | ||
); | ||
items.push(item); | ||
if (seperator) { | ||
items.push(<Separator key={index} />); | ||
} | ||
}); | ||
return items; | ||
}; | ||
|
||
return ( | ||
<Menu style={{ minWidth: '160px' }} id={CONTEXT_MENU_ID.FOR_RNA}> | ||
{assembleMenuItems()} | ||
</Menu> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/ketcher-polymer-editor-react/src/components/contextMenu/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum CONTEXT_MENU_ID { | ||
FOR_RNA = 'context-menu-for-RNA', | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/ketcher-polymer-editor-react/src/components/modal/Delete/Delete.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/**************************************************************************** | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
***************************************************************************/ | ||
|
||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import { Delete } from './Delete'; | ||
|
||
const mockProps = { | ||
isModalOpen: true, | ||
onClose: jest.fn(), | ||
}; | ||
|
||
describe('Delete component', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const preset: any = { | ||
base: { | ||
label: 'A', | ||
}, | ||
phosphate: { | ||
label: 'P', | ||
}, | ||
sugar: { | ||
label: 'R', | ||
}, | ||
name: 'A', | ||
}; | ||
it('should render correctly', () => { | ||
expect( | ||
render( | ||
withThemeAndStoreProvider(<Delete {...mockProps} />, { | ||
rnaBuilder: { | ||
activePreset: { presetInList: preset, name: 'name' }, | ||
presets: [preset], | ||
}, | ||
}), | ||
), | ||
).toMatchSnapshot(); | ||
}); | ||
it('should cancel delete', () => { | ||
render( | ||
withThemeAndStoreProvider(<Delete {...mockProps} />, { | ||
rnaBuilder: { | ||
activePreset: { presetInList: preset, name: 'name' }, | ||
presets: [preset], | ||
}, | ||
}), | ||
); | ||
const cancelButton = screen.getByTitle('Cancel'); | ||
fireEvent.click(cancelButton); | ||
expect(mockProps.onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should execute delete', () => { | ||
render( | ||
withThemeAndStoreProvider(<Delete {...mockProps} />, { | ||
rnaBuilder: { | ||
activePreset: { presetInList: preset, name: 'name' }, | ||
presets: [preset], | ||
}, | ||
}), | ||
); | ||
const deleteButton = screen.getByTitle('Delete'); | ||
fireEvent.click(deleteButton); | ||
expect(mockProps.onClose).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add here test.afterEach:
await test.afterEach(async ({ page }) => {
await takePageScreenshot(page);
});