-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathcommand-codecs.test.ts
More file actions
124 lines (117 loc) · 3.74 KB
/
command-codecs.test.ts
File metadata and controls
124 lines (117 loc) · 3.74 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { test } from 'vitest';
import assert from 'node:assert/strict';
import {
fillCommandCodec,
findCommandCodec,
interactionTargetCodec,
isCommandCodec,
longPressCommandCodec,
settingsCommandCodec,
waitCommandCodec,
} from '../command-codecs.ts';
import type { CliFlags } from '../utils/command-schema.ts';
const BASE_FLAGS: CliFlags = {
json: false,
help: false,
version: false,
};
test('wait codec preserves CLI bare text and client selector forms', () => {
const options = waitCommandCodec.decode(['Continue', '1500'], BASE_FLAGS);
assert.equal(options.text, 'Continue');
assert.equal(options.timeoutMs, 1500);
assert.deepEqual(
waitCommandCodec.encode({
selector: 'id=submit',
timeoutMs: 2000,
}),
['id=submit', '2000'],
);
});
test('interaction and fill codecs share ref, selector, and point grammar', () => {
assert.deepEqual(interactionTargetCodec.decode(['@e3', 'Email']), {
ref: '@e3',
label: 'Email',
});
assert.deepEqual(interactionTargetCodec.encode({ selector: 'id=submit' }), ['id=submit']);
assert.deepEqual(fillCommandCodec.decode(['id=email', 'qa@example.com']), {
kind: 'selector',
target: { selector: 'id=email' },
text: 'qa@example.com',
});
assert.deepEqual(fillCommandCodec.decode(['@e4', 'Email', 'qa@example.com']), {
kind: 'ref',
target: { ref: '@e4', label: 'Email' },
text: 'qa@example.com',
});
assert.deepEqual(fillCommandCodec.decode(['10', '20', 'hello']), {
kind: 'point',
target: { x: 10, y: 20 },
text: 'hello',
});
assert.deepEqual(
fillCommandCodec.encode({
ref: '@e4',
label: 'Email',
text: 'qa@example.com',
}),
['@e4', 'Email', 'qa@example.com'],
);
assert.deepEqual(longPressCommandCodec.decode(['@e4', '800']), {
ref: '@e4',
durationMs: 800,
});
assert.deepEqual(longPressCommandCodec.decode(['10', '20', '800']), {
x: 10,
y: 20,
durationMs: 800,
});
assert.deepEqual(
longPressCommandCodec.encode({ selector: 'label="Last message"', durationMs: 800 }),
['label="Last message"', '800'],
);
});
test('find and is codecs round-trip command action positionals', () => {
const findOptions = findCommandCodec.decode(['label', 'Continue', 'wait', '3000'], {
...BASE_FLAGS,
platform: 'ios',
findFirst: true,
});
assert.equal(findOptions.platform, 'ios');
assert.equal(findOptions.locator, 'label');
assert.equal(findOptions.query, 'Continue');
assert.equal(findOptions.action, 'wait');
assert.equal(findOptions.timeoutMs, 3000);
assert.equal(findOptions.first, true);
assert.deepEqual(findCommandCodec.encode(findOptions), ['label', 'Continue', 'wait', '3000']);
const isOptions = isCommandCodec.decode(['text', 'id=title', 'Welcome'], BASE_FLAGS);
assert.equal(isOptions.predicate, 'text');
assert.equal(isOptions.selector, 'id=title');
assert.equal(isOptions.value, 'Welcome');
assert.deepEqual(isCommandCodec.encode(isOptions), ['text', 'id=title', 'Welcome']);
});
test('settings codec owns positional grammar for command and client paths', () => {
const location = settingsCommandCodec.decode(['location', 'set', '37.3349', '-122.009'], {
...BASE_FLAGS,
platform: 'ios',
});
assert.equal(location.platform, 'ios');
assert.equal(location.setting, 'location');
assert.equal(location.state, 'set');
assert.equal(location.latitude, 37.3349);
assert.equal(location.longitude, -122.009);
assert.deepEqual(settingsCommandCodec.encode(location), [
'location',
'set',
'37.3349',
'-122.009',
]);
assert.deepEqual(
settingsCommandCodec.encode({
setting: 'permission',
state: 'grant',
permission: 'camera',
mode: 'limited',
}),
['permission', 'grant', 'camera', 'limited'],
);
});