@@ -43,114 +43,6 @@ void main() {
|
||||
expect(backs, 1);
|
||||
});
|
||||
|
||||
group('hasHorizontalNeighbor', () {
|
||||
testWidgets('reports interior vs. edge neighbors for a flat button row', (tester) async {
|
||||
final container = FocusNode(debugLabel: 'row', skipTraversal: true);
|
||||
final play = FocusNode(debugLabel: 'play');
|
||||
final download = FocusNode(debugLabel: 'download');
|
||||
final more = FocusNode(debugLabel: 'more');
|
||||
for (final node in [container, play, download, more]) {
|
||||
addTearDown(node.dispose);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Focus(
|
||||
focusNode: container,
|
||||
skipTraversal: true,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FilledButton(focusNode: play, onPressed: () {}, child: const Text('Play')),
|
||||
IconButton(focusNode: download, onPressed: () {}, icon: const Icon(Icons.download)),
|
||||
IconButton(focusNode: more, onPressed: () {}, icon: const Icon(Icons.more_vert)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
// The ordinal helper assumes one traversal node per button, in reading
|
||||
// order. Assert it so a framework change that breaks the assumption fails
|
||||
// loudly here rather than silently re-opening the black hole.
|
||||
expect(container.traversalDescendants.length, 3);
|
||||
|
||||
play.requestFocus();
|
||||
await tester.pump();
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.left), isFalse);
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.right), isTrue);
|
||||
|
||||
download.requestFocus();
|
||||
await tester.pump();
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.left), isTrue);
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.right), isTrue);
|
||||
|
||||
more.requestFocus();
|
||||
await tester.pump();
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.right), isFalse);
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.left), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('single-item row has no horizontal neighbor either way (rating-chip case)', (tester) async {
|
||||
final container = FocusNode(debugLabel: 'row', skipTraversal: true);
|
||||
final only = FocusNode(debugLabel: 'chip');
|
||||
addTearDown(container.dispose);
|
||||
addTearDown(only.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Focus(
|
||||
focusNode: container,
|
||||
skipTraversal: true,
|
||||
child: Focus(focusNode: only, child: const SizedBox(width: 50, height: 50)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
only.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.left), isFalse);
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.right), isFalse);
|
||||
});
|
||||
|
||||
testWidgets('returns false when focus is outside the container', (tester) async {
|
||||
final container = FocusNode(debugLabel: 'row');
|
||||
final inside = FocusNode(debugLabel: 'inside');
|
||||
final outside = FocusNode(debugLabel: 'outside');
|
||||
for (final node in [container, inside, outside]) {
|
||||
addTearDown(node.dispose);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
Focus(
|
||||
focusNode: container,
|
||||
child: Focus(focusNode: inside, child: const SizedBox(width: 40, height: 40)),
|
||||
),
|
||||
Focus(focusNode: outside, child: const SizedBox(width: 40, height: 40)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
outside.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.left), isFalse);
|
||||
expect(hasHorizontalNeighbor(container, TraversalDirection.right), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('dpadKeyHandler trapHorizontalEdges', () {
|
||||
testWidgets('consumes edge LEFT/RIGHT so focus cannot escape the group', (tester) async {
|
||||
final trapped = FocusNode(debugLabel: 'trapped');
|
||||
@@ -301,5 +193,68 @@ void main() {
|
||||
expect(navigatedLeft, isTrue);
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'left-target');
|
||||
});
|
||||
|
||||
testWidgets('moves through detail actions when trailer is inserted before shuffle', (tester) async {
|
||||
final play = FocusNode(debugLabel: 'detail_play');
|
||||
final outside = FocusNode(debugLabel: 'outside');
|
||||
addTearDown(play.dispose);
|
||||
addTearDown(outside.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
FocusableActionBar(
|
||||
actions: [
|
||||
FocusableAction(
|
||||
debugLabel: 'unused_play_label',
|
||||
focusNode: play,
|
||||
icon: Icons.play_arrow,
|
||||
onPressed: () {},
|
||||
),
|
||||
FocusableAction(debugLabel: 'detail_trailer', icon: Icons.theaters, onPressed: () {}),
|
||||
FocusableAction(debugLabel: 'detail_shuffle', icon: Icons.shuffle, onPressed: () {}),
|
||||
FocusableAction(debugLabel: 'detail_download', icon: Icons.download, onPressed: () {}),
|
||||
FocusableAction(debugLabel: 'detail_watched', icon: Icons.check, onPressed: () {}),
|
||||
FocusableAction(debugLabel: 'detail_more', icon: Icons.more_vert, onPressed: () {}),
|
||||
],
|
||||
),
|
||||
Focus(focusNode: outside, child: const SizedBox(width: 50, height: 50)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
play.requestFocus();
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_play');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_trailer');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_shuffle');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_download');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_watched');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_more');
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
expect(FocusManager.instance.primaryFocus?.debugLabel, 'detail_more');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user