Skip to content
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

#3181 - Autotests: Open and Save files (RXN) #3244

Merged
merged 12 commits into from
Oct 16, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,11 +1,277 @@
import { expect, test } from '@playwright/test';
import { expect, test, Page } from '@playwright/test';
import {
takeEditorScreenshot,
receiveFileComparisonData,
openFileAndAddToCanvas,
saveToFile,
drawBenzeneRing,
getCoordinatesTopAtomOfBenzeneRing,
clickOnAtom,
clickOnBond,
BondTool,
selectNestedTool,
ArrowTool,
selectAtomInToolbar,
AtomButton,
BondType,
clickOnTheCanvas,
selectTopPanelButton,
TopPanelButton,
RgroupTool,
pressButton,
selectLeftPanelButton,
LeftPanelButton,
selectAction,
dragMouseTo,
setAttachmentPoints,
moveMouseToTheMiddleOfTheScreen,
getCoordinatesOfTheMiddleOfTheScreen,
} from '@utils';
import { getRxn } from '@utils/formats';
import { drawReactionWithTwoBenzeneRings } from '@utils/canvas/drawStructures';

async function savedFileInfoStartsWithRxn(page: Page, wantedResult = false) {
await selectTopPanelButton(TopPanelButton.Save, page);
const textareaSelector = 'textarea[class^="Save-module_previewArea"]';
const textareaElement = await page.$(textareaSelector);
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
const textareaText = await textareaElement?.textContent();
const expectedSentence = '$RXN';
wantedResult
? expect(textareaText?.startsWith(expectedSentence)).toBeTruthy()
: expect(textareaText?.startsWith(expectedSentence)).toBeFalsy();
}

test('Open and Save file - Reaction with atom and bond properties', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-1897
* Description: Reaction with atom and bond properties
*/
const xOffsetFromCenter = 40;
await page.goto('');
await drawBenzeneRing(page);
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
await selectNestedTool(page, BondTool.SINGLE_AROMATIC);
await clickOnBond(page, BondType.DOUBLE, 1);
await selectNestedTool(page, BondTool.TRIPPLE);
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
await clickOnBond(page, BondType.DOUBLE, 1);
await selectAtomInToolbar(AtomButton.Nitrogen, page);
await clickOnAtom(page, 'C', 1);
await selectNestedTool(page, ArrowTool.ARROW_FILLED_BOW);
await clickOnTheCanvas(page, xOffsetFromCenter, 0);

const expectedFile = await getRxn(page);
await saveToFile(
'RXN/reaction-with-atom-and-bond-properties-saved.rxn',
expectedFile,
);

await selectAction(TopPanelButton.Clear, page);

await openFileAndAddToCanvas(
'RXN/reaction-with-atom-and-bond-properties-saved.rxn',
page,
);

await takeEditorScreenshot(page);
});

test('Open and Save file - Reaction from file that contains Rgroup', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-1901
* Description: Reaction from file that contains Rgroup
*/
const xOffsetFromCenter = 40;
await page.goto('');
await drawBenzeneRing(page);
await selectLeftPanelButton(LeftPanelButton.R_GroupLabelTool, page);
await clickOnAtom(page, 'C', 1);
await page.getByRole('button', { name: 'R7' }).click();
await page.getByRole('button', { name: 'Apply' }).click();
await selectNestedTool(page, ArrowTool.ARROW_FILLED_BOW);
await clickOnTheCanvas(page, xOffsetFromCenter, 0);
await selectTopPanelButton(TopPanelButton.Save, page);
const saveButtonOne = page.getByRole('button', { name: 'Save', exact: true });
await expect(saveButtonOne).not.toHaveAttribute('disabled', 'disabled');

await pressButton(page, 'Cancel');
await selectNestedTool(page, RgroupTool.ATTACHMENT_POINTS);
await setAttachmentPoints(
page,
{ label: 'C', index: 2 },
{ primary: true },
'Apply',
);
await selectTopPanelButton(TopPanelButton.Save, page);
const saveButtonTwo = page.getByRole('button', { name: 'Save', exact: true });
await expect(saveButtonTwo).not.toHaveAttribute('disabled', 'disabled');

await page.getByRole('button', { name: 'Cancel' }).click();
await selectNestedTool(page, RgroupTool.R_GROUP_FRAGMENT);
const { x, y } = await getCoordinatesTopAtomOfBenzeneRing(page);
await page.mouse.click(x, y);
await page.getByRole('button', { name: 'R22' }).click();
await page.getByRole('button', { name: 'Apply' }).click();
await selectTopPanelButton(TopPanelButton.Save, page);
const saveButtonThree = page.getByRole('button', {
name: 'Save',
exact: true,
});
await expect(saveButtonThree).not.toHaveAttribute('disabled', 'disabled');
});
vitaepam marked this conversation as resolved.
Show resolved Hide resolved

// EPMLSOPKET-1903 - TO DO
// TO DO: while saving file showed ERROR: array: invalid index -2 (size=0)
// Need to create new bug looks like it connected to #2389 issue
test.fixme(
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
'Open and Save file - Reaction from file that contains Sgroup',
async ({ page }) => {
/**
* Test case: EPMLSOPKET-1903
* Description: Reaction from file that contains Sgroup
*/
await page.goto('');
await openFileAndAddToCanvas(
'RXN/structure-with-s-groups-with-unsupported-s-group-type.rxn',
page,
);
const expectedFile = await getRxn(page);
await saveToFile(
'RXN/structure-with-s-groups-with-unsupported-s-group-type-saved.rxn',
expectedFile,
);
await openFileAndAddToCanvas(
'RXN/structure-with-s-groups-with-unsupported-s-group-type-saved.rxn',
page,
);
await takeEditorScreenshot(page);
},
);

test('Open and Save file - File without arrow or(and) plus-symbol', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-1905
* Description: File without arrow or(and) plus-symbol
*/
await page.goto('');
await selectLeftPanelButton(LeftPanelButton.Chain, page);
await moveMouseToTheMiddleOfTheScreen(page);
const { x, y } = await getCoordinatesOfTheMiddleOfTheScreen(page);
const xDelta = 300;
const xDeltaHalf = 150;
const yDelta50 = 50;
const yDelta20 = 20;
const xCoordinatesWithShift = x + xDelta;
const xCoordinatesWithShiftHalf = x + xDeltaHalf;
const yCoordinatesWithShift = y + yDelta50;
await dragMouseTo(xCoordinatesWithShift, y, page);
await savedFileInfoStartsWithRxn(page);

await pressButton(page, 'Cancel');
await selectLeftPanelButton(LeftPanelButton.ReactionPlusTool, page);
await page.mouse.click(xCoordinatesWithShiftHalf, yCoordinatesWithShift);
const ySecondChain = yCoordinatesWithShift + yDelta50;
await selectLeftPanelButton(LeftPanelButton.Chain, page);
await page.mouse.move(x, ySecondChain);
await dragMouseTo(xCoordinatesWithShift, ySecondChain, page);
await savedFileInfoStartsWithRxn(page);

await pressButton(page, 'Cancel');
await selectLeftPanelButton(LeftPanelButton.Erase, page);
await page.mouse.click(xCoordinatesWithShiftHalf, yCoordinatesWithShift);
await selectNestedTool(page, ArrowTool.ARROW_FILLED_BOW);
const yArrowStart = y + yDelta20;
const yArrowEnd = yArrowStart + yDelta20;
await page.mouse.move(xCoordinatesWithShiftHalf, yArrowStart);
await dragMouseTo(xCoordinatesWithShiftHalf, yArrowEnd, page);
await savedFileInfoStartsWithRxn(page, true);

await pressButton(page, 'Cancel');
await selectTopPanelButton(TopPanelButton.Clear, page);
await selectNestedTool(page, ArrowTool.ARROW_FILLED_BOW);
await page.mouse.move(xCoordinatesWithShiftHalf, yArrowStart);
await dragMouseTo(xCoordinatesWithShiftHalf, yArrowEnd, page);
await savedFileInfoStartsWithRxn(page, true);
});

// EPMLSOPKET-8904 - TO DO
// TO DO: looks like issue was not fixed
// Need to recheck issue #1837, added new screenshot there
test.fixme(
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
'Open and Save file - Structure is not missing when "Paste from clipboard" or "Open from file" if reaction consists of two or more reaction arrows and structures',
async ({ page }) => {
/**
* Test case: EPMLSOPKET-8904
* Description: Structure isn't missing when "Paste from clipboard" or "Open from file" if reaction consists of two or more reaction arrows and structures
*/
await page.goto('');
const RING_OFFSET = 150;
const ARROW_OFFSET = 20;
const ARROW_LENGTH = 100;
await drawReactionWithTwoBenzeneRings(
page,
RING_OFFSET,
ARROW_OFFSET,
ARROW_LENGTH,
);

const xOffsetFromCenter = 50;
await selectNestedTool(page, ArrowTool.ARROW_FILLED_BOW);
await moveMouseToTheMiddleOfTheScreen(page);
await clickOnTheCanvas(page, xOffsetFromCenter, 0);
const expectedFileV2000 = await getRxn(page);
await takeEditorScreenshot(page);
await saveToFile(
'RXN/structure-with-two-reaction-arrows-v2000-saved.rxn',
expectedFileV2000,
);
const expectedFileV3000 = await getRxn(page);
await saveToFile(
'RXN/structure-with-two-reaction-arrows-v3000-saved.rxn',
expectedFileV3000,
);
await selectAction(TopPanelButton.Clear, page);
await openFileAndAddToCanvas(
'RXN/structure-with-two-reaction-arrows-v3000-saved.rxn',
page,
);
await takeEditorScreenshot(page);
vitaepam marked this conversation as resolved.
Show resolved Hide resolved
},
);

test('Open and Save file - Import the structure from the saved RXN 2000/3000 file', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-12964
* Description: Import the structure from the saved RXN 2000/3000 file
*/
await page.goto('');
await openFileAndAddToCanvas(
'RXN/reaction-with-several-components.rxn',
page,
);
await takeEditorScreenshot(page);
});

test('Open and Save file - Open the RXN v2000/v3000 files with S-Group Properties Type = Multiple group', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-12967 for Open RXN v3000 file with 'S-Group Properties Type = Multiple group rxnV3000Multiple.zip
* Description: Open the RXN v2000/v3000 files with S-Group Properties Type = Multiple group
*/
await page.goto('');
await openFileAndAddToCanvas(
'RXN/structure-with-s-groups-with-unsupported-s-group-type-V3000.rxn',
page,
);
await takeEditorScreenshot(page);
});

test('Open and Save file - Reaction from file that contains abbreviation 1/2 - open', async ({
page,
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.
3 changes: 2 additions & 1 deletion ketcher-autotests/tests/Templates/S-Groups/s-groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ test.describe('S-Groups', () => {
page,
}) => {
/*
Test case: EPMLSOPKET-12967 for Open RXN v2000 file with 'S-Group Properties Type = Multiple group Multi.zip
Test case related to issue: https://github.com/epam/ketcher/issues/2389
Description: Open file with S-groups (with Unsupported S-group type GEN) and see that brackets in place for all S-Groups except DAT
*/
await openFileAndAddToCanvas(
'structure-with-s-groups-with-unsupported-s-group-type.rxn',
'RXN/structure-with-s-groups-with-unsupported-s-group-type-V2000.rxn',
page,
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$RXN

-INDIGO- 0904230127

1 0
$MOL

-INDIGO-09042301272D

6 6 0 0 0 0 0 0 0 0999 V2000
13.8348 -7.5001 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15.5652 -7.4996 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
14.7016 -7.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15.5652 -8.5005 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
13.8348 -8.5050 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
14.7038 -9.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3 1 2 0 0 0 0
4 2 3 0 0 0 0
1 5 1 0 0 0 0
2 3 1 0 0 0 0
5 6 6 0 0 0 0
6 4 1 0 0 0 0
M END
Loading
Loading