-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathinteraction-outcome-policy.test.ts
More file actions
129 lines (113 loc) · 4.22 KB
/
Copy pathinteraction-outcome-policy.test.ts
File metadata and controls
129 lines (113 loc) · 4.22 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
125
126
127
128
129
import assert from 'node:assert/strict';
import { test } from 'vitest';
import type { SnapshotState } from '../../utils/snapshot.ts';
import {
buildInteractionSurfaceSignature,
classifyInteractionSurfaceChange,
markPendingInteractionOutcome,
stripInternalInteractionOutcomeFlags,
} from '../interaction-outcome-policy.ts';
import type { SessionState } from '../types.ts';
import { IOS_SIMULATOR } from '../../__tests__/test-utils/device-fixtures.ts';
test('classifyInteractionSurfaceChange treats identical surfaces as unchanged', () => {
const before = buildInteractionSurfaceSignature(makeSnapshot('Inbox').nodes);
const after = buildInteractionSurfaceSignature(makeSnapshot('Inbox').nodes);
assert.equal(classifyInteractionSurfaceChange(before, after), 'unchanged');
});
test('classifyInteractionSurfaceChange tolerates tiny rect drift', () => {
const before = buildInteractionSurfaceSignature(makeSnapshot('Inbox', 100).nodes);
const after = buildInteractionSurfaceSignature(makeSnapshot('Inbox', 100.4).nodes);
assert.equal(classifyInteractionSurfaceChange(before, after), 'unchanged');
});
test('classifyInteractionSurfaceChange detects semantic screen changes', () => {
const before = buildInteractionSurfaceSignature(makeSnapshot('Inbox').nodes);
const after = buildInteractionSurfaceSignature(makeSnapshot('Article detail').nodes);
assert.equal(classifyInteractionSurfaceChange(before, after), 'changed');
});
test('classifyInteractionSurfaceChange detects material layout movement', () => {
const before = buildInteractionSurfaceSignature(makeSnapshot('Inbox', 100).nodes);
const after = buildInteractionSurfaceSignature(makeSnapshot('Inbox', 180).nodes);
assert.equal(classifyInteractionSurfaceChange(before, after), 'changed');
});
test('markPendingInteractionOutcome stores retry state only for explicit retry flags', () => {
const session = makeSession();
markPendingInteractionOutcome({
session,
command: 'click',
positionals: ['20', '40'],
flags: {},
preSnapshot: makeSnapshot('Inbox'),
});
assert.equal(session.pendingInteractionOutcome, undefined);
const retrySession = makeSession();
markPendingInteractionOutcome({
session: retrySession,
command: 'click',
positionals: ['20', '40'],
flags: { interactionOutcome: { retryOnNoChange: true } },
preSnapshot: makeSnapshot('Inbox'),
});
assert.equal(retrySession.pendingInteractionOutcome?.action, 'click');
assert.equal(retrySession.pendingInteractionOutcome?.command, 'press');
assert.equal(retrySession.pendingInteractionOutcome?.attemptsRemaining, 2);
assert.equal(retrySession.pendingInteractionOutcome?.flags?.interactionOutcome, undefined);
const refSession = makeSession();
markPendingInteractionOutcome({
session: refSession,
command: 'click',
positionals: ['@e1'],
flags: { interactionOutcome: { retryOnNoChange: true } },
preSnapshot: makeSnapshot('Inbox'),
});
assert.equal(refSession.pendingInteractionOutcome, undefined);
const longPressSession = makeSession();
markPendingInteractionOutcome({
session: longPressSession,
command: 'longpress',
positionals: ['20', '40', '800'],
flags: { interactionOutcome: { retryOnNoChange: true } },
preSnapshot: makeSnapshot('Inbox'),
});
assert.equal(longPressSession.pendingInteractionOutcome, undefined);
});
test('stripInternalInteractionOutcomeFlags removes internal retry controls', () => {
assert.deepEqual(
stripInternalInteractionOutcomeFlags({
platform: 'ios',
interactionOutcome: { retryOnNoChange: true },
}),
{ platform: 'ios' },
);
});
function makeSession(): SessionState {
return {
name: 'ios',
device: IOS_SIMULATOR,
createdAt: Date.now(),
actions: [],
};
}
function makeSnapshot(label: string, y = 100): SnapshotState {
return {
nodes: [
{
ref: 'e1',
index: 0,
type: 'Application',
label: 'App',
rect: { x: 0, y: 0, width: 390, height: 844 },
},
{
ref: 'e2',
index: 1,
parentIndex: 0,
type: 'Button',
identifier: 'primary-action',
label,
rect: { x: 120, y, width: 80, height: 40 },
},
],
createdAt: Date.now(),
backend: 'xctest',
};
}