Skip to content

Commit

Permalink
#3208 - Structure disappears after pressing 'Layout' and the app cras…
Browse files Browse the repository at this point in the history
…hes (#3264)

* #3208 - structure disappearance by pressing layout

* #3208 - Remove unused 'openFile' variable declaration

* #3208 - simplify 'Stereo flag' test by using a loop and refactor 'Center molecule after layout' test

* #3208 - Refactor code to ensure 'label' object is properly initialized

* #3208 – fix tests

---------

Co-authored-by: Gayane Chilingaryan <[email protected]>
Co-authored-by: Nikita_Vozisov <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent 74390f5 commit c147c6a
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 25 deletions.
21 changes: 17 additions & 4 deletions ketcher-autotests/tests/Indigo-Tools/Layout/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
waitForLoad,
getCoordinatesOfTheMiddleOfTheScreen,
waitForPageInit,
openFileAndAddToCanvas,
} from '@utils';

async function openFileWithShift(filename: string, page: Page) {
Expand All @@ -28,8 +29,7 @@ test.describe('Indigo Tools - Layout', () => {

test('Center molecule after layout', async ({ page }) => {
// Related Github issue: https://github.com/epam/ketcher/issues/2078
const anyStructure = 'benzene-rings.mol';
await openFileWithShift(anyStructure, page);
await openFileAndAddToCanvas('Molfiles-V2000/benzene-rings.mol', page);
await selectTopPanelButton(TopPanelButton.Layout, page);
await takeEditorScreenshot(page);
});
Expand All @@ -39,9 +39,22 @@ test.describe('Indigo Tools - Layout', () => {
}) => {
// Related Github issue: https://github.com/epam/ketcher/issues/3025
const structureWithStereoFlags = 'KET/structure-with-stereo-flags.ket';
const numberOfIterations = 3;
await openFileWithShift(structureWithStereoFlags, page);
await selectTopPanelButton(TopPanelButton.Layout, page);
await selectTopPanelButton(TopPanelButton.Layout, page);
for (let i = 0; i < numberOfIterations; i++) {
await selectTopPanelButton(TopPanelButton.Layout, page);
}
await takeEditorScreenshot(page);
});

test('After applying Layout, the structure does not disappear and can be interacted with', async ({
page,
}) => {
// Related Github issue: https://github.com/epam/ketcher/issues/3208
await openFileAndAddToCanvas(
'Molfiles-V2000/chloro-ethylamino-dimethyl-propoxy-propan-ol.mol',
page,
);
await selectTopPanelButton(TopPanelButton.Layout, page);
await takeEditorScreenshot(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.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
BondTypeName,
selectBond,
waitForPageInit,
waitForRender,
} from '@utils';
import { getAtomByIndex } from '@utils/canvas/atoms';
import { getRxn, getSmiles } from '@utils/formats';
Expand Down Expand Up @@ -66,7 +67,9 @@ test.describe('R-Group Label Tool', () => {
const { x, y } = await getCoordinatesTopAtomOfBenzeneRing(page);
await page.mouse.click(x, y);
await pressButton(page, 'R5');
await pressButton(page, 'Apply');
await waitForRender(page, async () => {
await pressButton(page, 'Apply');
});
});

test('Multiple R-Group label', async ({ page }) => {
Expand All @@ -83,7 +86,9 @@ test.describe('R-Group Label Tool', () => {
await pressButton(page, 'R4');
await pressButton(page, 'R5');
await pressButton(page, 'R6');
await pressButton(page, 'Apply');
await waitForRender(page, async () => {
await pressButton(page, 'Apply');
});
});

test('Delete R-Group label using Erase tool', async ({ page }) => {
Expand All @@ -101,7 +106,9 @@ test.describe('R-Group Label Tool', () => {
await pressButton(page, 'Apply');

await selectLeftPanelButton(LeftPanelButton.Erase, page);
await page.getByText('R5').click();
await waitForRender(page, async () => {
await page.getByText('R5').click();
});
});

test('Edit R-Group label', async ({ page }) => {
Expand All @@ -121,7 +128,9 @@ test.describe('R-Group Label Tool', () => {
await page.getByText('R5').click();
await pressButton(page, 'R5');
await pressButton(page, 'R8');
await pressButton(page, 'Apply');
await waitForRender(page, async () => {
await pressButton(page, 'Apply');
});
});

test('Create S-Group with R-Group', async ({ page }) => {
Expand All @@ -148,7 +157,9 @@ test.describe('R-Group Label Tool', () => {
point = await getAtomByIndex(page, { label: 'C' }, 2);
await page.mouse.click(point.x, point.y);
await pressButton(page, 'R5');
await pressButton(page, 'Apply');
await waitForRender(page, async () => {
await pressButton(page, 'Apply');
});
});

test('Rotate R-group', async ({ page }) => {
Expand All @@ -166,7 +177,9 @@ test.describe('R-Group Label Tool', () => {
await pressButton(page, 'Apply');

await page.keyboard.press('Control+a');
await pressButton(page, 'Vertical Flip (Alt+V)');
await waitForRender(page, async () => {
await pressButton(page, 'Vertical Flip (Alt+V)');
});
});

test('Undo-Redo with R-group label', async ({ page }) => {
Expand All @@ -188,9 +201,13 @@ test.describe('R-Group Label Tool', () => {
await pressButton(page, 'R7');
await pressButton(page, 'R8');
await pressButton(page, 'Apply');
await selectTopPanelButton(TopPanelButton.Undo, page);
await waitForRender(page, async () => {
await selectTopPanelButton(TopPanelButton.Undo, page);
});
await takeEditorScreenshot(page);
await selectTopPanelButton(TopPanelButton.Redo, page);
await waitForRender(page, async () => {
await selectTopPanelButton(TopPanelButton.Redo, page);
});
});

test('Create the same R-Group label as existing', async ({ page }) => {
Expand All @@ -213,7 +230,10 @@ test.describe('R-Group Label Tool', () => {
point = await getAtomByIndex(page, { label: 'C' }, 2);
await page.mouse.click(point.x, point.y);
await pressButton(page, 'R5');
await pressButton(page, 'Apply');

await waitForRender(page, async () => {
await pressButton(page, 'Apply');
});
});

test('Zoom In/Zoom Out', async ({ page }) => {
Expand All @@ -232,13 +252,17 @@ test.describe('R-Group Label Tool', () => {

// eslint-disable-next-line no-magic-numbers
for (let i = 0; i < 5; i++) {
await page.keyboard.press('Control+_');
await waitForRender(page, async () => {
await page.keyboard.press('Control+_');
});
}
await takeEditorScreenshot(page);

// eslint-disable-next-line no-magic-numbers
for (let i = 0; i < 5; i++) {
await page.keyboard.press('Control+=');
await waitForRender(page, async () => {
await page.keyboard.press('Control+=');
});
}
});

Expand All @@ -258,7 +282,9 @@ test.describe('R-Group Label Tool', () => {

await selectLeftPanelButton(LeftPanelButton.RectangleSelection, page);
await page.getByText('R5').click();
await page.keyboard.press('Delete');
await waitForRender(page, async () => {
await page.keyboard.press('Delete');
});
});

test('Move Structure with R-Group label', async ({ page }) => {
Expand Down Expand Up @@ -365,7 +391,9 @@ test.describe('R-Group Label Tool', () => {
await selectLeftPanelButton(LeftPanelButton.ChargePlus, page);
await page.getByText('R8').click();
await selectLeftPanelButton(LeftPanelButton.ChargeMinus, page);
await page.getByText('R13').click();
await waitForRender(page, async () => {
await page.getByText('R13').click();
});
});

test('Add Bond to the R-Group Label', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

Ketcher 7102316352D 1 1.00000 0.00000 0

36 40 0 0 0 0 0 0 0 0999 V2000
3.3523 1.9354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.3523 1.1104 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.6378 0.6979 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.9233 1.1104 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1387 0.8555 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
0.6538 1.5229 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1387 2.1904 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8838 2.9750 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0768 3.1465 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.1781 3.9312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.3739 4.5442 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
0.1190 5.3289 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.6710 5.9420 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.4161 6.7266 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.9681 7.3397 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7751 7.1682 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0300 6.3835 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.4780 5.7704 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.3271 7.7812 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
2.0722 8.5659 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2652 8.7374 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
2.6242 9.1790 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.3693 9.9636 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.9213 10.5767 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.6663 11.3613 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.2184 11.9744 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.0253 11.8029 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.5774 12.4160 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
4.2803 11.0182 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.0873 10.8467 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
3.7283 10.4052 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1809 4.3727 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.4358 3.5881 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.9233 1.9354 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.6378 2.3479 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.0668 2.3479 0.0000 R 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0
2 3 1 0 0 0
3 4 2 0 0 0
4 5 1 0 0 0
5 6 1 0 0 0
6 7 2 0 0 0
7 8 1 0 0 0
8 9 1 0 0 0
9 10 1 0 0 0
10 11 1 0 0 0
11 12 1 0 0 0
12 13 1 0 0 0
13 14 1 0 0 0
14 15 1 0 0 0
15 16 1 0 0 0
16 17 1 0 0 0
17 18 1 0 0 0
13 18 1 0 0 0
16 19 1 0 0 0
19 20 1 0 0 0
20 21 2 0 0 0
20 22 1 0 0 0
22 23 2 0 0 0
23 24 1 0 0 0
24 25 2 0 0 0
25 26 1 0 0 0
26 27 2 0 0 0
27 28 1 0 0 0
27 29 1 0 0 0
29 30 1 0 0 0
29 31 2 0 0 0
24 31 1 0 0 0
11 32 1 0 0 0
32 33 1 0 0 0
8 33 1 0 0 0
7 34 1 0 0 0
4 34 1 0 0 0
34 35 2 0 0 0
1 35 1 0 0 0
36 1 1 0 0 0
M END
4 changes: 3 additions & 1 deletion ketcher-autotests/tests/utils/canvas/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ELEMENT_TITLE } from './types';
import { DELAY_IN_SECONDS, TopPanelButton, waitForRender } from '..';
import { selectTopPanelButton } from './tools';
import { getLeftTopBarSize } from './common/getLeftTopBarSize';
import { emptyFunction } from '@utils/common/helpers';

export async function drawBenzeneRing(page: Page) {
await page.getByRole('button', { name: 'Benzene (T)' }).click();
Expand Down Expand Up @@ -80,8 +81,9 @@ export async function takeEditorScreenshot(
page: Page,
options?: { masks?: Locator[] },
) {
const maxTimeout = 3000;
const editor = page.getByTestId('ketcher-canvas').first();
await waitForRender(page);
await waitForRender(page, emptyFunction, maxTimeout);
await expect(editor).toHaveScreenshot({ mask: options?.masks });
}

Expand Down
2 changes: 2 additions & 0 deletions ketcher-autotests/tests/utils/common/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export async function emptyFunction() {}
6 changes: 2 additions & 4 deletions ketcher-autotests/tests/utils/common/loaders/waitForRender.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Page } from '@playwright/test';

type AnyFunction = (...args: any) => Promise<any>;
// eslint-disable-next-line @typescript-eslint/no-empty-function
const emptyFunction: AnyFunction = async () => {};

export const waitForRender = async (
page: Page,
callback = emptyFunction,
timeout = 3000,
callback: AnyFunction,
timeout?: number,
) => {
await Promise.all([
waitForCustomEvent(page, 'renderComplete', timeout),
Expand Down
5 changes: 4 additions & 1 deletion ketcher-autotests/tests/utils/files/readFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
waitForLoad,
delay,
takeEditorScreenshot,
waitForRender,
} from '@utils';
import { MolfileFormat } from 'ketcher-core';
import { getSmiles, getInchi } from '@utils/formats';
Expand Down Expand Up @@ -40,7 +41,9 @@ export async function openFileAndAddToCanvas(filename: string, page: Page) {
await waitForLoad(page, async () => {
await pressButton(page, 'Add to Canvas');
});
await clickInTheMiddleOfTheScreen(page);
await waitForRender(page, async () => {
await clickInTheMiddleOfTheScreen(page);
});
}

export async function pasteFromClipboardAndAddToCanvas(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,12 @@ function buildLabel(
options: any,
): ElemAttr {
// eslint-disable-line max-statements
let label: any = {};
const label: any = {};
label.text = getLabelText(atom.a);

if (label.text === '') label = 'R#'; // for structures that missed 'M RGP' tag in molfile
if (!label.text) {
label.text = 'R#';
}

if (label.text === atom.a.label) {
const element = Elements.get(label.text);
Expand Down

0 comments on commit c147c6a

Please sign in to comment.