Skip to content

Commit

Permalink
Replacement of methods
Browse files Browse the repository at this point in the history
  • Loading branch information
knadonenkoepam committed Nov 25, 2024
1 parent 3045fee commit 9fe789d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.describe('Rectangle selection tool', () => {

const selectionCoords = { x: 300, y: 200 };
async function clickCanvas(page: Page) {
await page.mouse.click(selectionCoords.x, selectionCoords.y);
await clickOnCanvas(page, selectionCoords.x, selectionCoords.y);
}

test('Structure selection with rectangle selection tool', async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function drawStructureWithArrowOpenAngle(page: Page) {
await resetCurrentTool(page);

await page.mouse.move(x, y + shiftForCoordinatesToResetArrowOpenAngleTool);
await page.mouse.click;
await clickOnCanvas;

await selectAtomInToolbar(AtomButton.Oxygen, page);
await clickOnCanvas(page, x + shiftForOxygen, y, {
Expand Down
22 changes: 11 additions & 11 deletions ketcher-autotests/tests/utils/canvas/bonds/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {};
// import { test } from '@playwright/test';
// import { drawElementByTitle, waitForPageInit } from '@utils';
// import { drawElementByTitle, waitForPageInit, clickOnCanvas, } from '@utils';
// import {
// getRightBondByAttributes,
// getBottomBondByAttributes,
Expand Down Expand Up @@ -32,54 +32,54 @@ export {};
// { type: BondType.HYDROGEN },
// searchedIndex,
// );
// await page.mouse.click(bondByIndex.x, bondByIndex.y);
// await clickOnCanvas(page, bondByIndex.x, bondByIndex.y);

// const leftBond = await getLeftBondByAttributes(page, {
// topology: 1,
// type: BondType.DOUBLE,
// sb: 2,
// reactingCenterStatus: 2,
// });
// await page.mouse.click(leftBond.x, leftBond.y);
// await clickOnCanvas(page, leftBond.x, leftBond.y);

// const rBond = await getRightBondByAttributes(page, {
// stereo: 2,
// type: BondType.DATIVE,
// });
// await page.mouse.click(rBond.x, rBond.y);
// await clickOnCanvas(page, rBond.x, rBond.y);

// const bottomBond = await getBottomBondByAttributes(page, { sa: 1 });
// await page.mouse.click(bottomBond.x, bottomBond.y);
// await clickOnCanvas(page, bottomBond.x, bottomBond.y);

// const topBond = await getTopBondByAttributes(page, { type: BondType.DOUBLE });
// await page.mouse.click(topBond.x, topBond.y);
// await clickOnCanvas(page, topBond.x, topBond.y);
// });

// test(`ATOM`, async ({ page }) => {
// await waitForPageInit(page);
// await drawElementByTitle(page, ELEMENT_TITLE.BENZENE, OFFSET_X, OFFSET_Y);

// const firstAtom = await getAtomByIndex(page, { label: 'C', valence: 1 }, 0);
// await page.mouse.click(firstAtom.x, firstAtom.y);
// await clickOnCanvas(page, firstAtom.x, firstAtom.y);

// const leftAtom = await getLeftAtomByAttributes(page, {
// stereoParity: 1,
// });
// await page.mouse.click(leftAtom.x, leftAtom.y);
// await clickOnCanvas(page, leftAtom.x, leftAtom.y);

// const rightAtom = await getRightAtomByAttributes(page, {
// exactChangeFlag: 2,
// hCount: 1,
// charge: 2,
// });
// await page.mouse.click(rightAtom.x, rightAtom.y);
// await clickOnCanvas(page, rightAtom.x, rightAtom.y);

// const bottomAtom = await getBottomAtomByAttributes(page, { charge: 1 });
// await page.mouse.click(bottomAtom.x, bottomAtom.y);
// await clickOnCanvas(page, bottomAtom.x, bottomAtom.y);

// const topAtom = await getTopAtomByAttributes(page, {
// substitutionCount: 1,
// valence: 3,
// });
// await page.mouse.click(topAtom.x, topAtom.y);
// await clickOnCanvas(page, topAtom.x, topAtom.y);
// });
2 changes: 1 addition & 1 deletion ketcher-autotests/tests/utils/canvas/tools/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export async function selectClearCanvasTool(page: Page, maxAttempts = 10) {
return;
} catch (error) {
attempts++;
await page.mouse.click(0, 0);
await clickOnCanvas(page, 0, 0);
await page.keyboard.press('Escape');
if (await closeWindowXButton.isVisible()) {
await closeWindowXButton.click();
Expand Down
31 changes: 10 additions & 21 deletions ketcher-autotests/tests/utils/clicks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function clickOnCanvas(
},
) {
await waitForRender(page, async () => {
await page.mouse.click(x, y, options);
await clickOnCanvas(page, x, y, options);
});
}

Expand Down Expand Up @@ -143,7 +143,8 @@ export async function clickOnTheCanvas(
page,
);
await waitForRender(page, async () => {
await page.mouse.click(
await clickOnCanvas(
page,
secondStructureCoordinates.x + xOffsetFromCenter,
secondStructureCoordinates.y + yOffsetFromCenter,
);
Expand All @@ -152,9 +153,7 @@ export async function clickOnTheCanvas(

export async function clickOnMiddleOfCanvas(page: Page) {
const middleOfCanvas = await getCoordinatesOfTheMiddleOfTheCanvas(page);
await waitForRender(page, async () => {
await page.mouse.click(middleOfCanvas.x, middleOfCanvas.y);
});
await clickOnCanvas(page, middleOfCanvas.x, middleOfCanvas.y);
}

export async function clickByLink(page: Page, url: string) {
Expand All @@ -168,9 +167,7 @@ export async function clickOnBond(
buttonSelect?: 'left' | 'right' | 'middle',
) {
const point = await getBondByIndex(page, { type: bondType }, bondNumber);
await waitForRender(page, async () => {
await page.mouse.click(point.x, point.y, { button: buttonSelect });
});
await clickOnCanvas(page, point.x, point.y, { button: buttonSelect });
}

export async function clickOnBondById(
Expand All @@ -179,9 +176,7 @@ export async function clickOnBondById(
buttonSelect?: 'left' | 'right' | 'middle',
) {
const point = await getBondById(page, bondId);
await waitForRender(page, async () => {
await page.mouse.click(point.x, point.y, { button: buttonSelect });
});
await clickOnCanvas(page, point.x, point.y, { button: buttonSelect });
}

export async function clickOnAtom(
Expand All @@ -191,9 +186,7 @@ export async function clickOnAtom(
buttonSelect?: 'left' | 'right' | 'middle',
) {
const point = await getAtomByIndex(page, { label: atomLabel }, atomNumber);
await waitForRender(page, async () => {
await page.mouse.click(point.x, point.y, { button: buttonSelect });
});
await clickOnCanvas(page, point.x, point.y, { button: buttonSelect });
}

export async function clickOnAtomById(
Expand All @@ -202,9 +195,7 @@ export async function clickOnAtomById(
buttonSelect?: 'left' | 'right' | 'middle',
) {
const point = await getAtomById(page, atomId);
await waitForRender(page, async () => {
await page.mouse.click(point.x, point.y, { button: buttonSelect });
});
await clickOnCanvas(page, point.x, point.y, { button: buttonSelect });
}

export async function doubleClickOnAtom(
Expand All @@ -213,9 +204,7 @@ export async function doubleClickOnAtom(
atomNumber: number,
) {
const point = await getAtomByIndex(page, { label: atomLabel }, atomNumber);
await waitForRender(page, async () => {
await page.mouse.dblclick(point.x, point.y);
});
await clickOnCanvas(page, point.x, point.y);
}

export async function doubleClickOnBond(
Expand All @@ -235,7 +224,7 @@ export async function rightClickOnBond(
bondNumber: number,
) {
const point = await getBondByIndex(page, { type: bondType }, bondNumber);
await page.mouse.click(point.x, point.y, { button: 'right' });
await clickOnCanvas(page, point.x, point.y, { button: 'right' });
}

export async function moveOnAtom(
Expand Down
5 changes: 3 additions & 2 deletions ketcher-autotests/tests/utils/macromolecules/polymerBond.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-magic-numbers */
import { Locator, Page } from '@playwright/test';
import { hideMonomerPreview } from '@utils/macromolecules/index';
import { moveMouseAway, selectMacroBond } from '..';
import { clickOnCanvas, moveMouseAway, selectMacroBond } from '..';
import { DropdownToolIds } from '@utils/clicks/types';
import { MacroBondTool } from '@utils/canvas/tools/selectNestedTool/types';

Expand Down Expand Up @@ -279,7 +279,8 @@ export async function clickOnMicroBondByIndex(page: Page, bondIndex: number) {
// Simple click on element doesn't work always because only black pixels of bond are clickable (what? YES!)
// So, bonds with empty space in the center (for example - double bond) are not clickable
if (boundingBox) {
await page.mouse.click(
await clickOnCanvas(
page,
boundingBox.x + boundingBox.width / 2 + 2,
boundingBox.y + boundingBox.height / 2 + 2,
);
Expand Down
13 changes: 7 additions & 6 deletions ketcher-autotests/tests/utils/selectors/templateModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
takeEditorScreenshot,
STRUCTURE_LIBRARY_BUTTON_NAME,
pressButton,
clickOnCanvas,
} from '@utils';
import { ElementLabel } from 'ketcher-core';

Expand Down Expand Up @@ -333,12 +334,12 @@ const COORDS_CLICK = {
Function for attaching structures on top of bonds attached on Benzene ring
*/
export async function attachOnTopOfBenzeneBonds(page: Page) {
await page.mouse.click(COORDS_CLICK.x1, COORDS_CLICK.y1);
await page.mouse.click(COORDS_CLICK.x2, COORDS_CLICK.y2);
await page.mouse.click(COORDS_CLICK.x3, COORDS_CLICK.y3);
await page.mouse.click(COORDS_CLICK.x4, COORDS_CLICK.y4);
await page.mouse.click(COORDS_CLICK.x5, COORDS_CLICK.y5);
await page.mouse.click(COORDS_CLICK.x6, COORDS_CLICK.y6);
await clickOnCanvas(page, COORDS_CLICK.x2, COORDS_CLICK.y2);
await clickOnCanvas(page, COORDS_CLICK.x3, COORDS_CLICK.y3);
await clickOnCanvas(page, COORDS_CLICK.x1, COORDS_CLICK.y1);
await clickOnCanvas(page, COORDS_CLICK.x4, COORDS_CLICK.y4);
await clickOnCanvas(page, COORDS_CLICK.x5, COORDS_CLICK.y5);
await clickOnCanvas(page, COORDS_CLICK.x6, COORDS_CLICK.y6);
}

export async function fillFieldByLabel(
Expand Down

0 comments on commit 9fe789d

Please sign in to comment.