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
@@ -0,0 +1,96 @@
import { expect, test } from 'vitest';
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
import { buildIosInteractiveSnapshotPresentation } from './semantic-index.ts';

const FULL_SCREEN = { x: 0, y: 0, width: 402, height: 874 };
const SETTINGS_BACK_BUTTON = {
type: 'Button',
label: 'Settings',
rect: { x: 16, y: 62, width: 44, height: 44 },
};

function presented(nodes: RawSnapshotNode[]) {
return buildIosInteractiveSnapshotPresentation(nodes).nodes.map((node) => [
node.type,
node.label,
node.parentIndex,
]);
}

test('a SwiftUI app root that shares the back button label stays the root', () => {
const nodes = [
{
index: 0,
depth: 0,
type: 'Other',
subrole: 'UIApplication',
label: 'Settings',
rect: FULL_SCREEN,
},
{ index: 1, depth: 1, parentIndex: 0, ...SETTINGS_BACK_BUTTON },
];

expect(presented(nodes)).toEqual([
['Other', 'Settings', undefined],
['Button', 'Settings', 0],
]);
});

test('a SwiftUI app root that shares its list label stays the root', () => {
const nodes = [
{
index: 0,
depth: 0,
type: 'Other',
subrole: 'UIApplication',
label: 'Notes',
rect: FULL_SCREEN,
},
{
index: 1,
depth: 1,
parentIndex: 0,
type: 'CollectionView',
label: 'Notes',
rect: FULL_SCREEN,
},
];

expect(presented(nodes)).toEqual([
['Other', 'Notes', undefined],
['CollectionView', 'Notes', 0],
]);
});

test('a wrapper that shares its list label still collapses', () => {
const nodes = [
{ index: 0, depth: 0, type: 'Application', label: 'App', rect: FULL_SCREEN },
{ index: 1, depth: 1, parentIndex: 0, type: 'Other', label: 'Notes', rect: FULL_SCREEN },
{
index: 2,
depth: 2,
parentIndex: 1,
type: 'CollectionView',
label: 'Notes',
rect: FULL_SCREEN,
},
];

expect(presented(nodes)).toEqual([
['Application', 'App', undefined],
['CollectionView', 'Notes', 0],
]);
});

test('a full-screen wrapper that shares its button label still collapses', () => {
const nodes = [
{ index: 0, depth: 0, type: 'Application', label: 'App', rect: FULL_SCREEN },
{ index: 1, depth: 1, parentIndex: 0, type: 'Other', label: 'Settings', rect: FULL_SCREEN },
{ index: 2, depth: 2, parentIndex: 1, ...SETTINGS_BACK_BUTTON },
];

expect(presented(nodes)).toEqual([
['Application', 'App', undefined],
['Button', 'Settings', 0],
]);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
import { normalizeType } from '@agent-device/contracts/snapshot';
import { isViewportRootNode, normalizeType } from '@agent-device/contracts/snapshot';
import {
areRectsApproximatelyEqual,
findDescendant,
Expand Down Expand Up @@ -41,7 +41,8 @@ function collectRepeatedStaticSuppressionForNode(
if (type !== 'other') {
return;
}
const semanticDescendant = findEquivalentSemanticDescendant(nodes, position, nodeLabel);
const semanticDescendant =
!isViewportRootNode(node) && findEquivalentSemanticDescendant(nodes, position, nodeLabel);
if (semanticDescendant) {
context.suppressNode(node, [semanticDescendant]);
return;
Expand Down Expand Up @@ -85,6 +86,7 @@ export function collectIosActionWrapperSuppression(
context: SnapshotTreeRuleContext,
): void {
forEachOtherNodeWithLabel(nodes, (node, nodeLabel, position) => {
if (isViewportRootNode(node)) return;
const semanticDescendant = findDescendant(nodes, position, (descendant) => {
return (
isSemanticActionNode(descendant) &&
Expand Down
Loading
Loading