-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathket-files-properties.spec.ts
61 lines (47 loc) · 1.96 KB
/
ket-files-properties.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable no-magic-numbers */
import { expect, test } from '@playwright/test';
import {
openFileAndAddToCanvas,
receiveFileComparisonData,
saveToFile,
waitForPageInit,
} from '@utils';
import { getKet } from '@utils/formats';
test('Open KET file with properties and check properties are saved in struct', async ({
page,
}) => {
await waitForPageInit(page);
await openFileAndAddToCanvas('KET/ket-with-properties.ket', page);
const fragments = await page.evaluate(() => {
// eslint-disable-next-line no-unsafe-optional-chaining
return [...window.ketcher?.editor?.struct()?.frags?.values()];
});
const [firstFragment, secondFragment] = fragments;
if (!firstFragment?.properties || !secondFragment?.properties) {
test.fail();
return;
}
const [firstFragmentProperties] = firstFragment.properties! as any;
const [secondFragmentProperties] = secondFragment.properties! as any;
const [firstFragmentPropKey] = Object.keys(firstFragmentProperties);
const [secondFragmentPropKey] = Object.keys(secondFragmentProperties);
const firstFragmentPropValue = firstFragmentProperties[firstFragmentPropKey];
const secondFragmentPropValue =
secondFragmentProperties[secondFragmentPropKey];
expect(firstFragmentPropKey).toEqual('mol0_key');
expect(firstFragmentPropValue).toEqual('mol0_value');
expect(secondFragmentPropKey).toEqual('mol1_key');
expect(secondFragmentPropValue).toEqual('mol1_value');
});
test('Save a structure with properties to KET format', async ({ page }) => {
await waitForPageInit(page);
await openFileAndAddToCanvas('KET/ket-with-properties.ket', page);
const expectedFile = await getKet(page);
await saveToFile('KET/ket-with-properties-expected.ket', expectedFile);
const { fileExpected: ketFileExpected, file: ketFile } =
await receiveFileComparisonData({
page,
expectedFileName: 'tests/test-data/KET/ket-with-properties-expected.ket',
});
expect(ketFile).toEqual(ketFileExpected);
});