-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathselectors-public.test.ts
More file actions
70 lines (63 loc) · 1.99 KB
/
selectors-public.test.ts
File metadata and controls
70 lines (63 loc) · 1.99 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
import assert from 'node:assert/strict';
import { test } from 'vitest';
import {
findSelectorChainMatch,
formatSelectorFailure,
isNodeEditable,
isNodeVisible,
isSelectorToken,
parseSelectorChain,
resolveSelectorChain,
tryParseSelectorChain,
type Selector,
type SelectorChain,
type SelectorDiagnostics,
type SelectorResolution,
} from '../selectors.ts';
import type { SnapshotNode } from '../utils/snapshot.ts';
const nodes: SnapshotNode[] = [
{
ref: 'e1',
index: 0,
type: 'android.widget.Button',
label: 'Continue',
rect: { x: 0, y: 0, width: 120, height: 48 },
enabled: true,
},
{
ref: 'e2',
index: 1,
type: 'android.widget.EditText',
label: 'Email',
rect: { x: 0, y: 64, width: 200, height: 48 },
enabled: true,
},
];
test('public selector subpath exposes platform-aware matching helpers', () => {
const chain: SelectorChain = parseSelectorChain('role=button label="Continue" visible=true');
const firstSelector: Selector = chain.selectors[0]!;
assert.equal(firstSelector.raw, 'role=button label="Continue" visible=true');
assert.equal(tryParseSelectorChain(chain.raw)?.raw, chain.raw);
assert.equal(isSelectorToken('visible=true'), true);
const match = findSelectorChainMatch(nodes, chain, {
platform: 'android',
requireRect: true,
});
assert.ok(match);
assert.equal(match.matches, 1);
const resolved: SelectorResolution | null = resolveSelectorChain(nodes, chain, {
platform: 'android',
requireRect: true,
});
assert.equal(resolved?.node.ref, 'e1');
assert.equal(isNodeVisible(nodes[0]!), true);
assert.equal(isNodeEditable(nodes[1]!, 'android'), true);
});
test('public selector diagnostics format failures', () => {
const chain = parseSelectorChain('label=Missing');
const diagnostics: SelectorDiagnostics[] = [{ selector: 'label=Missing', matches: 0 }];
assert.equal(
formatSelectorFailure(chain, diagnostics, { unique: false }),
'Selector did not match (label=Missing -> 0)',
);
});