Skip to content

Commit 4e91840

Browse files
authored
fix: harden android settings integration test (#58)
1 parent 57062c8 commit 4e91840

1 file changed

Lines changed: 64 additions & 10 deletions

File tree

test/integration/android.test.ts

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ import test from 'node:test';
22
import { createIntegrationTestContext, runCliJson } from './test-helpers.ts';
33

44
const session = ['--session', 'android-test'];
5+
const settingsSectionLabels = [
6+
'Apps',
7+
'Apps & notifications',
8+
'Network & internet',
9+
'Network and internet',
10+
'Connected devices',
11+
'Display',
12+
'Battery',
13+
'Notifications',
14+
'Security',
15+
'Privacy',
16+
];
17+
const settingsSectionSelector = settingsSectionLabels
18+
.map((label) => (label.includes(' ') || label.includes('&') ? `label="${label}"` : `label=${label}`))
19+
.join(' || ');
20+
const settingsCrashDialogLabels = ['Wait', 'Close app'];
21+
const settingsCrashDialogSelector = settingsCrashDialogLabels
22+
.map((label) => (label.includes(' ') ? `label="${label}"` : `label=${label}`))
23+
.join(' || ');
524

625
test.after(() => {
726
runCliJson(['close', '--platform', 'android', ...session]);
@@ -29,20 +48,43 @@ test('android settings commands', () => {
2948
);
3049

3150
const snapshotArgs = ['snapshot', '-i', '--json', ...session];
32-
const snapshot = integration.runStep('snapshot', snapshotArgs);
51+
let snapshot = integration.runStep('snapshot', snapshotArgs);
3352
integration.assertResult(Array.isArray(snapshot.json?.data?.nodes), 'snapshot nodes', snapshotArgs, snapshot, {
3453
detail: 'expected snapshot to include a nodes array',
3554
});
55+
if (snapshotHasAnyLabel(snapshot, settingsCrashDialogLabels)) {
56+
const dismissCrashDialogArgs = ['click', settingsCrashDialogSelector, '--json', ...session];
57+
const dismissCrashDialog = integration.runStep(
58+
'dismiss settings crash dialog',
59+
dismissCrashDialogArgs,
60+
);
61+
integration.assertResult(
62+
dismissCrashDialog.json?.success,
63+
'dismiss settings crash dialog success',
64+
dismissCrashDialogArgs,
65+
dismissCrashDialog,
66+
{ detail: 'expected click on crash dialog action to return success=true' },
67+
);
68+
integration.runStep('re-open settings after crash dialog', openArgs);
69+
snapshot = integration.runStep('snapshot after crash dialog', snapshotArgs);
70+
integration.assertResult(
71+
Array.isArray(snapshot.json?.data?.nodes),
72+
'snapshot after crash dialog nodes',
73+
snapshotArgs,
74+
snapshot,
75+
{ detail: 'expected snapshot after crash dialog recovery to include a nodes array' },
76+
);
77+
}
78+
integration.assertResult(
79+
snapshotHasAnyLabel(snapshot, settingsSectionLabels),
80+
'snapshot contains settings section labels',
81+
snapshotArgs,
82+
snapshot,
83+
{
84+
detail: `expected snapshot to include one of ${JSON.stringify(settingsSectionLabels)}`,
85+
},
86+
);
3687

37-
const settingsSectionSelector = [
38-
'label=Apps',
39-
'label="Apps & notifications"',
40-
'label="Network & internet"',
41-
'label="Connected devices"',
42-
'label=Display',
43-
'label=Battery',
44-
'label=Notifications',
45-
].join(' || ');
4688
const clickArgs = ['click', settingsSectionSelector, '--json', ...session];
4789
const openSection = integration.runStep('open settings section', clickArgs);
4890
integration.assertResult(
@@ -80,3 +122,15 @@ test('android settings commands', () => {
80122
const backArgs = ['back', '--json', ...session];
81123
integration.runStep('back', backArgs);
82124
});
125+
126+
function snapshotHasAnyLabel(
127+
result: ReturnType<typeof runCliJson>,
128+
candidateLabels: string[],
129+
): boolean {
130+
const nodes = Array.isArray(result.json?.data?.nodes) ? result.json.data.nodes : [];
131+
return nodes.some((node: { label?: string }) => {
132+
const label = node?.label;
133+
if (typeof label !== 'string') return false;
134+
return candidateLabels.includes(label);
135+
});
136+
}

0 commit comments

Comments
 (0)