-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpanelTextEditor.spec.ts
More file actions
102 lines (78 loc) · 4.64 KB
/
Copy pathpanelTextEditor.spec.ts
File metadata and controls
102 lines (78 loc) · 4.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { test, expect } from '@playwright/test';
import {
forceDataFormat,
getCurrentDataFormat,
openApp,
redo,
selectInitialSchemaFromExamples,
undo
} from "../../tests/shared/utils";
import {SessionMode} from "../src/store/sessionMode";
import {checkCodeEditorForText, forceCodeEditorText, getCodeEditor} from "../../tests/shared/utilsCodeEditor";
import {tpForceData, tpGetData} from "../../tests/shared/utilsTestPanel";
test('Select an example schema, enter some value and change the data format. Then check the code editor content for the data in the new format.', async ({ page }) => {
// Go to the app
await openApp(page)
// Select the "Autonomous Vehicle Schema" from the example schema options
await selectInitialSchemaFromExamples(page, 'Autonomous Vehicle Schema');
// Enter some values in the textboxes
await page.getByRole('textbox', { name: 'SimulationName' }).click();
await page.getByRole('textbox', { name: 'SimulationName' }).fill('TestName');
await page.getByRole('textbox', { name: 'SimulationName' }).press('Enter');
// Check that the code editor shows the correct JSON data
await checkCodeEditorForText(page, '{ "SimulationName": "TestName"}', SessionMode.DataEditor);
// Expect the data format to be in JSON
expect(await getCurrentDataFormat(page)).toBe('json');
// Change the data format to YAML and check that the code editor shows the correct YAML data
await forceDataFormat(page, 'yaml');
expect(await getCurrentDataFormat(page)).toBe('yaml');
await checkCodeEditorForText(page, 'SimulationName: TestName', SessionMode.DataEditor);
// Change the data format to JSON
await forceDataFormat(page, 'json');
expect(await getCurrentDataFormat(page)).toBe('json');
// Edit the simulation name in the code editor to an invalid value
await page.getByRole('textbox', { name: 'SimulationName' }).fill('Sim1');
await page.getByRole('textbox', { name: 'SimulationName' }).press('Enter');
// TODO: check that there is an error highlighting in the GUI due to invalid SimulationName
// Edit the simulation name in the code editor to a valid value
await page.getByRole('textbox', { name: 'SimulationName' }).fill('Sim_2');
await page.getByRole('textbox', { name: 'SimulationName' }).press('Enter');
// Check that the code editor shows the correct JSON data
await checkCodeEditorForText(page, '{ "SimulationName": "Sim_2"}', SessionMode.DataEditor);
});
test('Change the internal data and check if the code editor is updated properly', async ({ page }) => {
// Go to the app, pre-loading the schema
await openApp(page, 'settings_testpanel.json', null, 'schema_medium.schema.json');
// Confirm that the initial data is an empty object
await checkCodeEditorForText(page, '{}', SessionMode.DataEditor);
// Update the data to {"properties": {"address": {"city": "Berlin"}}}
const dataBerlin = {"address": {"city": "Berlin"}};
await tpForceData(page, SessionMode.DataEditor, dataBerlin);
// Validate that the data is set correctly
await checkCodeEditorForText(page, '{ "address": { "city": "Berlin" }}', SessionMode.DataEditor);
});
test('Change the code editor content and check if the internal data is updated properly', async ({ page }) => {
// Go to the app, pre-loading the schema
await openApp(page, 'settings_testpanel.json', null, 'schema_medium.schema.json');
// Confirm that the initial data is an empty object
await checkCodeEditorForText(page, '{}', SessionMode.DataEditor);
// Change the code editor content
await forceCodeEditorText(page, '{ "name": "Alex" }', SessionMode.DataEditor);
// Validate that the internal data is updated correctly
const dataAfterNameEnter = await tpGetData(page, SessionMode.DataEditor);
expect(dataAfterNameEnter).toEqual({ name: 'Alex' });
});
test('Undo and redo in the code editor use the global history', async ({ page }) => {
await openApp(page, 'settings_testpanel.json', null, 'schema_medium.schema.json');
await forceCodeEditorText(page, '{ "name": "Alex" }', SessionMode.DataEditor);
expect(await tpGetData(page, SessionMode.DataEditor)).toEqual({ name: 'Alex' });
await getCodeEditor(page, SessionMode.DataEditor).click();
await undo(page);
await page.waitForTimeout(300);
expect(await tpGetData(page, SessionMode.DataEditor)).toEqual({});
await checkCodeEditorForText(page, '{}', SessionMode.DataEditor);
await redo(page);
await page.waitForTimeout(300);
expect(await tpGetData(page, SessionMode.DataEditor)).toEqual({ name: 'Alex' });
await checkCodeEditorForText(page, '"name": "Alex"', SessionMode.DataEditor);
});