Skip to content

Commit

Permalink
#3208 – fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Sep 8, 2023
1 parent a1ce25e commit eb9b7a0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
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
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

0 comments on commit eb9b7a0

Please sign in to comment.