Skip to content

Commit

Permalink
#3531 – added tests for ketcher API for macro mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Nov 30, 2023
1 parent c89cfbe commit 8c6a274
Show file tree
Hide file tree
Showing 24 changed files with 698 additions and 21 deletions.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
Empty file modified .husky/pre-push
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
selectNestedTool,
openFileAndAddToCanvas,
takeEditorScreenshot,
pressButton,
selectTopPanelButton,
TopPanelButton,
clickOnTheCanvas,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Page, test } from '@playwright/test';
import {
readFileContents,
waitForPageInit,
turnOnMacromoleculesEditor,
takeEditorScreenshot,
waitForSpinnerFinishedWork,
addFragment,
selectRectangleArea,
openFileAndAddToCanvas,
dragMouseTo,
} from '@utils';

const fileName = 'KET/alanine-monomers-bonded.ket';

async function shiftStructure(page: Page) {
const startX = 100;
const startY = 100;
const endX = 800;
const endY = 750;
const toShiftToCoordinates = 400;

await selectRectangleArea(page, startX, startY, endX, endY);
const alanine = await page
.getByText('A', { exact: true })
.locator('..')
.first();
await alanine.hover();
await dragMouseTo(toShiftToCoordinates, toShiftToCoordinates, page);
}

test.describe('addFragment', () => {
test.beforeEach(async ({ page }) => {
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
await openFileAndAddToCanvas(fileName, page);
await shiftStructure(page);
});

test.afterEach(async ({ page }) => {
await page.mouse.move(0, 0);
await takeEditorScreenshot(page);
});

test('mol with two monomers bonded', async ({ page }) => {
const fileContents = await readFileContents(
'tests/test-data/Molfiles-V3000/alanine-monomers-bonded-expected.mol',
);
await waitForSpinnerFinishedWork(
page,
async () => await addFragment(page, fileContents),
);
});

test('ket with two monomers bonded', async ({ page }) => {
const fileContents = await readFileContents(`tests/test-data/${fileName}`);
await waitForSpinnerFinishedWork(
page,
async () => await addFragment(page, fileContents),
);
});
});
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.
26 changes: 26 additions & 0 deletions ketcher-autotests/tests/Macromolecule-editor/API/get-ket.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from '@playwright/test';
import {
openFileAndAddToCanvas,
readFileContents,
waitForPageInit,
turnOnMacromoleculesEditor,
getKet,
saveToFile,
} from '@utils';

test.describe('getKet', () => {
test.beforeEach(async ({ page }) => {
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
});

test('with two monomers bonded', async ({ page }) => {
await openFileAndAddToCanvas('KET/alanine-monomers-bonded.ket', page);
const ket = await getKet(page);
await saveToFile('KET/alanine-monomers-bonded-expected.ket', ket);
const fileContents = await readFileContents(
'tests/test-data/KET/alanine-monomers-bonded-expected.ket',
);
expect(ket).toBe(fileContents);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test, expect } from '@playwright/test';
import {
openFileAndAddToCanvas,
readFileContents,
waitForPageInit,
turnOnMacromoleculesEditor,
saveToFile,
getMolfile,
} from '@utils';

test.describe('getMolfile', () => {
test.beforeEach(async ({ page }) => {
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
});

test('with two monomers bonded', async ({ page }) => {
await openFileAndAddToCanvas('KET/alanine-monomers-bonded.ket', page);
const mol = await getMolfile(page);
await saveToFile(
'Molfiles-V3000/alanine-monomers-bonded-expected.mol',
mol,
);
const fileContents = await readFileContents(
'tests/test-data/Molfiles-V3000/alanine-monomers-bonded-expected.mol',
);
expect(mol).toBe(fileContents);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test';
import {
readFileContents,
waitForPageInit,
turnOnMacromoleculesEditor,
setMolecule,
takeEditorScreenshot,
waitForSpinnerFinishedWork,
} from '@utils';

test.describe('setMolecule', () => {
test.beforeEach(async ({ page }) => {
await waitForPageInit(page);
await turnOnMacromoleculesEditor(page);
});

test('mol with two monomers bonded', async ({ page }) => {
const fileContents = await readFileContents(
'tests/test-data/Molfiles-V3000/alanine-monomers-bonded-expected.mol',
);
await waitForSpinnerFinishedWork(
page,
async () => await setMolecule(page, fileContents),
);
await takeEditorScreenshot(page);
});

test('ket with two monomers bonded', async ({ page }) => {
const fileContents = await readFileContents(
'tests/test-data/KET/alanine-monomers-bonded.ket',
);
await waitForSpinnerFinishedWork(
page,
async () => await setMolecule(page, fileContents),
);
await takeEditorScreenshot(page);
});
});
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.
6 changes: 4 additions & 2 deletions ketcher-autotests/tests/Settings/Atoms/atoms-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
} from '@utils';
import { scrollSettingBar } from '@utils/scrollSettingBar';

const scrollBy = 150;

async function setHydrogenLabelsOn(page: Page) {
await selectTopPanelButton(TopPanelButton.Settings, page);
await page.getByText('Atoms', { exact: true }).click();
await scrollSettingBar(page, 150);
await scrollSettingBar(page, scrollBy);
await page.getByTestId('show-hydrogen-labels-input-span').click();
await page.getByTestId('On-option').click();
await pressButton(page, 'Apply');
Expand All @@ -31,7 +33,7 @@ async function selectExtendedTableElements(page: Page, element: string) {
async function atomDefaultSettings(page: Page) {
await selectTopPanelButton(TopPanelButton.Settings, page);
await page.getByText('Atoms', { exact: true }).click();
await scrollSettingBar(page,150);
await scrollSettingBar(page, scrollBy);
}

async function ringBondCountQuery(page: Page, menuItem: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"root": {
"nodes": [
{
"$ref": "monomer0"
},
{
"$ref": "monomer1"
}
],
"connections": [
{
"connectionType": "single",
"endpoint1": {
"monomerId": "monomer0",
"attachmentPointId": "R2"
},
"endpoint2": {
"monomerId": "monomer1",
"attachmentPointId": "R1"
}
}
],
"templates": [
{
"$ref": "monomerTemplate-A___Alanine"
}
]
},
"monomer0": {
"type": "monomer",
"id": "0",
"position": {
"x": 10.675,
"y": 6.75
},
"alias": "A",
"templateId": "A___Alanine"
},
"monomerTemplate-A___Alanine": {
"type": "monomerTemplate",
"atoms": [
{
"label": "N",
"location": [
-0.9805331061317909,
-0.30629450761308635,
0
]
},
{
"label": "C",
"location": [
-0.21253088283357013,
0.20573302003705518,
0
],
"stereoLabel": "abs"
},
{
"label": "C",
"location": [
-0.24245710640903242,
1.359025604825105,
0
]
},
{
"label": "C",
"location": [
0.8222288529623745,
-0.30629450761308635,
0
]
},
{
"label": "O",
"location": [
0.846138577281151,
-1.2284597573196285,
0
]
},
{
"type": "rg-label",
"location": [
1.5903092126145781,
0.20573302003705518,
0
],
"$refs": [
"rg-2"
]
},
{
"type": "rg-label",
"location": [
-1.8232336838376932,
0.07071340035455183,
0
],
"$refs": [
"rg-1"
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
1,
0
]
},
{
"type": 1,
"atoms": [
1,
2
],
"stereo": 1
},
{
"type": 1,
"atoms": [
1,
3
]
},
{
"type": 2,
"atoms": [
3,
4
]
},
{
"type": 1,
"atoms": [
3,
5
]
},
{
"type": 1,
"atoms": [
0,
6
]
}
],
"classHELM": "PEPTIDE",
"naturalAnalogShort": "A",
"id": "A___Alanine",
"alias": "A",
"attachmentPoints": [
{
"attachmentAtom": 6,
"leavingGroup": {
"atoms": []
},
"type": "left"
},
{
"attachmentAtom": 5,
"leavingGroup": {
"atoms": []
},
"type": "right"
}
]
},
"monomer1": {
"type": "monomer",
"id": "1",
"position": {
"x": 15.375,
"y": 10.4
},
"alias": "A",
"templateId": "A___Alanine"
}
}
Loading

0 comments on commit 8c6a274

Please sign in to comment.