-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathandroid.test.ts
More file actions
136 lines (126 loc) · 4.82 KB
/
android.test.ts
File metadata and controls
136 lines (126 loc) · 4.82 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
130
131
132
133
134
135
136
import test from 'node:test';
import { createIntegrationTestContext, runCliJson } from './test-helpers.ts';
const session = ['--session', 'android-test'];
const settingsSectionLabels = [
'Apps',
'Apps & notifications',
'Network & internet',
'Network and internet',
'Connected devices',
'Display',
'Battery',
'Notifications',
'Security',
'Privacy',
];
const settingsSectionSelector = settingsSectionLabels
.map((label) => (label.includes(' ') || label.includes('&') ? `label="${label}"` : `label=${label}`))
.join(' || ');
const settingsCrashDialogLabels = ['Wait', 'Close app'];
const settingsCrashDialogSelector = settingsCrashDialogLabels
.map((label) => (label.includes(' ') ? `label="${label}"` : `label=${label}`))
.join(' || ');
test.after(() => {
runCliJson(['close', '--platform', 'android', ...session]);
});
test('android settings commands', () => {
const integration = createIntegrationTestContext({
platform: 'android',
testName: 'android settings commands',
});
const openArgs = ['open', 'settings', '--platform', 'android', '--json', ...session];
integration.runStep('open settings', openArgs);
const appStateArgs = ['appstate', '--json', ...session];
const appState = integration.runStep('appstate', appStateArgs);
const openedPackage = String(appState.json?.data?.package ?? '').toLowerCase();
integration.assertResult(
openedPackage.includes('settings'),
'appstate package is settings',
appStateArgs,
appState,
{
detail: `expected appstate package to include "settings", received ${JSON.stringify(appState.json?.data?.package)}`,
},
);
const snapshotArgs = ['snapshot', '-i', '--json', ...session];
let snapshot = integration.runStep('snapshot', snapshotArgs);
integration.assertResult(Array.isArray(snapshot.json?.data?.nodes), 'snapshot nodes', snapshotArgs, snapshot, {
detail: 'expected snapshot to include a nodes array',
});
if (snapshotHasAnyLabel(snapshot, settingsCrashDialogLabels)) {
const dismissCrashDialogArgs = ['click', settingsCrashDialogSelector, '--json', ...session];
const dismissCrashDialog = integration.runStep(
'dismiss settings crash dialog',
dismissCrashDialogArgs,
);
integration.assertResult(
dismissCrashDialog.json?.success,
'dismiss settings crash dialog success',
dismissCrashDialogArgs,
dismissCrashDialog,
{ detail: 'expected click on crash dialog action to return success=true' },
);
integration.runStep('re-open settings after crash dialog', openArgs);
snapshot = integration.runStep('snapshot after crash dialog', snapshotArgs);
integration.assertResult(
Array.isArray(snapshot.json?.data?.nodes),
'snapshot after crash dialog nodes',
snapshotArgs,
snapshot,
{ detail: 'expected snapshot after crash dialog recovery to include a nodes array' },
);
}
integration.assertResult(
snapshotHasAnyLabel(snapshot, settingsSectionLabels),
'snapshot contains settings section labels',
snapshotArgs,
snapshot,
{
detail: `expected snapshot to include one of ${JSON.stringify(settingsSectionLabels)}`,
},
);
const clickArgs = ['click', settingsSectionSelector, '--json', ...session];
const openSection = integration.runStep('open settings section', clickArgs);
integration.assertResult(
openSection.json?.success,
'open settings section success',
clickArgs,
openSection,
{ detail: 'expected selector-based click to return success=true' },
);
const snapshotAppsArgs = ['snapshot', '-i', '--json', ...session];
const snapshotApps = integration.runStep('snapshot apps', snapshotAppsArgs);
integration.assertResult(
Array.isArray(snapshotApps.json?.data?.nodes),
'snapshot apps nodes',
snapshotAppsArgs,
snapshotApps,
{
detail: 'expected snapshot after click to include a nodes array',
},
);
const appStateAfterClick = integration.runStep('appstate after click', appStateArgs);
const packageAfterClick = String(appStateAfterClick.json?.data?.package ?? '').toLowerCase();
integration.assertResult(
packageAfterClick.includes('settings'),
'appstate after click package is settings',
appStateArgs,
appStateAfterClick,
{
detail: `expected appstate package after click to include "settings", received ${JSON.stringify(appStateAfterClick.json?.data?.package)}`,
},
);
const backArgs = ['back', '--json', ...session];
integration.runStep('back', backArgs);
});
function snapshotHasAnyLabel(
result: ReturnType<typeof runCliJson>,
candidateLabels: string[],
): boolean {
const nodes = Array.isArray(result.json?.data?.nodes) ? result.json.data.nodes : [];
return nodes.some((node: { label?: string }) => {
const label = node?.label;
if (typeof label !== 'string') return false;
return candidateLabels.includes(label);
});
}