|
| 1 | +import { readFileSync } from 'node:fs'; |
1 | 2 | import { expect, test } from 'vitest'; |
2 | 3 | import { buildUiHierarchySnapshot, parseUiHierarchyTree } from '../ui-hierarchy.ts'; |
3 | 4 |
|
@@ -75,3 +76,42 @@ test('ADB parses native field evidence and hint state before assigning values', |
75 | 76 | [undefined, undefined, undefined], |
76 | 77 | ]); |
77 | 78 | }); |
| 79 | + |
| 80 | +const fieldValues = JSON.parse( |
| 81 | + readFileSync( |
| 82 | + new URL('../../../../contracts/fixtures/android-field-values.json', import.meta.url), |
| 83 | + 'utf8', |
| 84 | + ), |
| 85 | +) as { |
| 86 | + cases: { |
| 87 | + name: string; |
| 88 | + input: { |
| 89 | + type: string; |
| 90 | + text?: string; |
| 91 | + editable?: boolean; |
| 92 | + password?: boolean; |
| 93 | + hintShowing?: boolean; |
| 94 | + }; |
| 95 | + value: string | null; |
| 96 | + }[]; |
| 97 | +}; |
| 98 | + |
| 99 | +test.each(fieldValues.cases)( |
| 100 | + 'ADB adapter applies the field value contract: $name', |
| 101 | + ({ input, value }) => { |
| 102 | + const attrs = [ |
| 103 | + `class="${input.type}"`, |
| 104 | + input.text === undefined ? '' : `text="${input.text}"`, |
| 105 | + input.editable === undefined ? '' : `editable="${input.editable}"`, |
| 106 | + input.password === undefined ? '' : `password="${input.password}"`, |
| 107 | + input.hintShowing === undefined ? '' : `hint-showing="${input.hintShowing}"`, |
| 108 | + ].join(' '); |
| 109 | + const tree = parseUiHierarchyTree( |
| 110 | + `<hierarchy><node ${attrs} resource-id="field" bounds="[0,0][200,100]" /></hierarchy>`, |
| 111 | + ); |
| 112 | + const { nodes } = buildUiHierarchySnapshot(tree, undefined, { raw: true }); |
| 113 | + const node = nodes.find((candidate) => candidate.identifier === 'field'); |
| 114 | + expect(node).toBeDefined(); |
| 115 | + expect(node?.value).toBe(value ?? undefined); |
| 116 | + }, |
| 117 | +); |
0 commit comments