-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtextEditorAnnotations.spec.ts
More file actions
65 lines (57 loc) · 2.36 KB
/
Copy pathtextEditorAnnotations.spec.ts
File metadata and controls
65 lines (57 loc) · 2.36 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
import {test, expect, type Page} from '@playwright/test';
import {openApp} from '../../tests/shared/utils';
import {SessionMode} from '../src/store/sessionMode';
import {checkCodeEditorForText, getCodeEditor} from '../../tests/shared/utilsCodeEditor';
/**
* Reads the validation annotations Ace has rendered on the editor for the given mode.
* Returns an array of {row (0-indexed), text} for each annotation marker.
*/
async function readAnnotations(
page: Page,
mode: SessionMode
): Promise<Array<{row: number; text: string}>> {
return await page.evaluate(modePrefix => {
const editor = document.querySelector(`[id^="code-editor-${modePrefix}"]`) as HTMLElement;
if (!editor) return [];
const ace = (window as any).ace;
const aceEditor = ace.edit(editor.id);
const annotations = aceEditor.getSession().getAnnotations() as Array<{
row: number;
text: string;
}>;
return annotations.map(a => ({row: a.row, text: a.text}));
}, mode);
}
test('Text editor shows annotations only at the leaf-error rows, including required-at-root', async ({
page,
}) => {
await openApp(
page,
'settings_testpanel.json',
'personInvalid.json',
'featureTesting.schema.json'
);
// wait for data to render
await checkCodeEditorForText(page, '"heightInMeter"', SessionMode.DataEditor);
await getCodeEditor(page, SessionMode.DataEditor).waitFor();
// give validation worker + 500ms annotation debounce time to run
await page.waitForTimeout(1500);
const annotations = await readAnnotations(page, SessionMode.DataEditor);
// Row map for personInvalid.json:
// 0: {
// 1: "heightInMeter": 9.24,
// 2: "telephoneNumber": 159,
// 3: "isMarried": true,
// 4: "address": {
// 5: "zipCode": 4
// 6: }
// 7: }
const rowsWithAnnotations = annotations.map(a => a.row).sort((a, b) => a - b);
// Expectation: required errors → row 0 (root opening brace), heightInMeter error → row 1,
// zipCode error → row 5. No annotation on the address row (4) or anywhere else.
expect(rowsWithAnnotations).toContain(0); // required at root
expect(rowsWithAnnotations).toContain(1); // heightInMeter
expect(rowsWithAnnotations).toContain(5); // address/zipCode
// No annotation on the address line (it would be a parent-level summary that we now filter out)
expect(rowsWithAnnotations).not.toContain(4);
});