Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { expect, test } from 'vitest';
import { shouldIncludeAndroidNode } from '../ui-hierarchy-inclusion.ts';
import type { AndroidNode } from '../ui-hierarchy-node.ts';
import {
ANDROID_DEVICE_NAME_DIALOG_RAW_NODES,
walkInteractiveOnlyAndroidFixture,
} from '../ui-hierarchy.fixtures.ts';

test('interactive inclusion keeps positive agent targets and rejects degenerate geometry', () => {
expect(
Expand All @@ -10,6 +14,7 @@ test('interactive inclusion keeps positive agent targets and rejects degenerate
false,
false,
false,
false,
),
).toBe(true);
expect(
Expand All @@ -19,17 +24,41 @@ test('interactive inclusion keeps positive agent targets and rejects degenerate
false,
false,
false,
false,
),
).toBe(false);
});

test('interactive inclusion keeps a semantic Compose proxy only in actionable context', () => {
const semanticView = node({ type: 'android.view.View', label: 'Start a call' });
expect(
shouldIncludeAndroidNode(semanticView, { interactiveOnly: true }, true, false, false),
shouldIncludeAndroidNode(semanticView, { interactiveOnly: true }, true, false, false, false),
).toBe(true);
expect(
shouldIncludeAndroidNode(semanticView, { interactiveOnly: true }, false, false, false),
shouldIncludeAndroidNode(semanticView, { interactiveOnly: true }, false, false, false, false),
).toBe(false);
});

test('interactive inclusion keeps an AlertDialog title and drops screen text outside the dialog', () => {
const labels = walkInteractiveOnlyAndroidFixture(ANDROID_DEVICE_NAME_DIALOG_RAW_NODES).map(
(presented) => presented.label,
);
expect(labels).toContain('Device name');
expect(labels).toEqual(expect.arrayContaining(['sdk_gphone64_arm64', 'Cancel', 'OK']));
expect(labels).not.toContain('4:37');
});

test('interactive inclusion keeps passive text only inside an alert panel', () => {
const title = node({ type: 'android.widget.TextView', label: 'Device name' });
expect(
shouldIncludeAndroidNode(title, { interactiveOnly: true }, false, false, false, true),
).toBe(true);
expect(
shouldIncludeAndroidNode(title, { interactiveOnly: true }, false, false, false, false),
).toBe(false);
const panelLayout = node({ type: 'android.widget.LinearLayout', label: 'Panel' });
expect(
shouldIncludeAndroidNode(panelLayout, { interactiveOnly: true }, false, false, false, true),
).toBe(false);
});

Expand All @@ -41,13 +70,14 @@ test('regular inclusion preserves meaningful structural nodes and actionable des
false,
false,
false,
false,
),
).toBe(true);
expect(
shouldIncludeAndroidNode(node({ type: 'android.view.View' }), {}, false, true, false),
shouldIncludeAndroidNode(node({ type: 'android.view.View' }), {}, false, true, false, false),
).toBe(true);
expect(
shouldIncludeAndroidNode(node({ type: 'android.view.View' }), {}, false, false, false),
shouldIncludeAndroidNode(node({ type: 'android.view.View' }), {}, false, false, false, false),
).toBe(false);
});

Expand Down
5 changes: 5 additions & 0 deletions packages/platform-android/src/alert-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ const ANDROID_PERMISSION_ID_PATTERN = /(?:^|:)id\/permission_/i;
const ANDROID_BLOCKING_DIALOG_PATTERN =
/\b(?:is(?:n't| not) responding|keeps stopping|has stopped|close app|app info)\b/i;

/** The AlertController panel that holds a dialog's title, message, and buttons, under the platform or an AppCompat package. */
export function isAndroidAlertPanelIdentifier(identifier: string | null): boolean {
return identifier !== null && /(?:^|:)id\/parentPanel$/i.test(identifier);
}

export function classifyAndroidAlertIdentifier(
identifier: string | null,
): 'button' | 'content' | undefined {
Expand Down
Loading
Loading