Files
Garage-SDKs/garage_ui/test/text_field_semantics_focus_test.dart
ImBenjiandClaude Opus 5.5 b269201919 The Garage SDKs, in the open
garage_auth, garage_entitlements, garage_iap and garage_ui, moved out of
Garage-Services and Metro-Map-Maker into one public repo. MIT, one readme,
docs under docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013F4NWNvYcdeSgqbWMT1VQ7
2026-09-23 18:49:21 +01:00

57 lines
1.8 KiB
Dart

import "package:flutter/semantics.dart";
import "package:flutter/widgets.dart";
import "package:flutter_test/flutter_test.dart";
import "package:garage_ui/garage_ui.dart";
import "support/test_scheme.dart";
// with the semantics tree on, flutter web focuses a field by asking through
// semantics rather than by a tap on the field. It used to go unanswered.
Widget _host(Widget child) => Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: GarageTheme(
data: ThemeData(colorScheme: testScheme),
child: Overlay(
initialEntries: [
OverlayEntry(
builder: (_) => Center(child: SizedBox(width: 300, child: child)),
),
],
),
),
),
);
void main() {
for (final action in [SemanticsAction.tap, SemanticsAction.focus]) {
testWidgets("$action from semantics focuses the field", (tester) async {
final handle = tester.ensureSemantics();
final focus = FocusNode();
addTearDown(focus.dispose);
await tester.pumpWidget(_host(TextField(focusNode: focus)));
expect(focus.hasFocus, isFalse);
final node = tester.getSemantics(find.byType(EditableText));
node.owner!.performAction(node.id, action);
await tester.pump();
expect(focus.hasFocus, isTrue);
handle.dispose();
});
}
testWidgets("a disabled field doesnt offer to be focused", (tester) async {
final handle = tester.ensureSemantics();
await tester.pumpWidget(_host(const TextField(enabled: false)));
final node = tester.getSemantics(find.byType(EditableText));
final data = node.getSemanticsData();
expect(data.hasAction(SemanticsAction.tap), isFalse);
expect(data.hasAction(SemanticsAction.focus), isFalse);
handle.dispose();
});
}