-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrootLevelArraySchema.spec.ts
More file actions
59 lines (47 loc) · 2.53 KB
/
Copy pathrootLevelArraySchema.spec.ts
File metadata and controls
59 lines (47 loc) · 2.53 KB
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
import {test, expect} from '@playwright/test';
import {openApp} from '../../tests/shared/utils';
import {SessionMode} from '../src/store/sessionMode';
import {tpForceData, tpGetCurrentPath, tpGetData} from '../../tests/shared/utilsTestPanel';
import {addArrayItem, checkStringProperty, editStringProperty} from '../../tests/shared/utilsGuiEditor';
/**
* Regression test for the "schema with type array on root level does not work" bug:
* the GUI view stayed completely empty for a root-level array schema as long as the
* document data was still the initial empty object, and afterwards data writes for
* root-level items went to wrong locations.
*/
test('root level array schema can be filled and edited via the GUI editor', async ({page}) => {
await openApp(page, 'settings_testpanel.json', null, 'schema_rootarray.schema.json');
// a new document starts out with an empty object as data
expect(await tpGetData(page, SessionMode.DataEditor)).toEqual({});
// the GUI view must offer adding an item nonetheless
await addArrayItem(page, []);
await expect.poll(async () => tpGetData(page, SessionMode.DataEditor)).toEqual([{}]);
// the new item can be edited
await editStringProperty(page, [0, 'name'], 'Alex');
await expect
.poll(async () => tpGetData(page, SessionMode.DataEditor))
.toEqual([{name: 'Alex'}]);
// more items can be appended
await addArrayItem(page, []);
await expect
.poll(async () => tpGetData(page, SessionMode.DataEditor))
.toEqual([{name: 'Alex'}, {}]);
});
test('add item replaces leftover non-array data of a root level array', async ({page}) => {
await openApp(page, 'settings_testpanel.json', null, 'schema_rootarray.schema.json');
// simulate old data from a previous schema
await tpForceData(page, SessionMode.DataEditor, {legacy: 'value'});
// the GUI still offers adding an item; clicking it replaces the old data
await addArrayItem(page, []);
await expect.poll(async () => tpGetData(page, SessionMode.DataEditor)).toEqual([{}]);
});
test('zooming into an item of a root level array works', async ({page}) => {
await openApp(page, 'settings_testpanel.json', null, 'schema_rootarray.schema.json');
await addArrayItem(page, []);
await editStringProperty(page, [0, 'name'], 'Alex');
// zoom into the first item by clicking its label
await page.locator('[id="_label_[0]"]').click();
expect(await tpGetCurrentPath(page, SessionMode.DataEditor)).toEqual([0]);
// the item's properties are shown and editable at the zoomed level
await checkStringProperty(page, [0, 'name'], 'Alex');
});