diff --git a/packages/flutter/test/cupertino/picker_test.dart b/packages/flutter/test/cupertino/picker_test.dart index ce7a2d63f2..ba6e31ae0d 100644 --- a/packages/flutter/test/cupertino/picker_test.dart +++ b/packages/flutter/test/cupertino/picker_test.dart @@ -10,6 +10,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../rendering/rendering_tester.dart'; +import '../widgets/semantics_tester.dart'; class SpyFixedExtentScrollController extends FixedExtentScrollController { /// Override for test visibility only. @@ -54,6 +55,51 @@ void main() { ); }); + testWidgets('Picker semantics', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + await tester.pumpWidget( + CupertinoApp( + home: SizedBox( + height: 300.0, + width: 300.0, + child: CupertinoPicker( + itemExtent: 50.0, + onSelectedItemChanged: (_) {}, + children: List.generate(13, (int index) { + return SizedBox(height: 50.0, width: 300.0, child: Text(index.toString())); + }), + ), + ), + ), + ); + expect( + semantics, + includesNodeWith( + value: '0', + increasedValue: '1', + actions: [SemanticsAction.increase], + ), + ); + + final FixedExtentScrollController hourListController = + tester.widget(find.byType(ListWheelScrollView)).controller! + as FixedExtentScrollController; + + hourListController.jumpToItem(11); + await tester.pumpAndSettle(); + expect( + semantics, + includesNodeWith( + value: '11', + increasedValue: '12', + decreasedValue: '10', + actions: [SemanticsAction.increase, SemanticsAction.decrease], + ), + ); + semantics.dispose(); + }); + group('layout', () { // Regression test for https://github.com/flutter/flutter/issues/22999 testWidgets('CupertinoPicker.builder test', (WidgetTester tester) async { diff --git a/packages/flutter/test/widgets/semantics_tester.dart b/packages/flutter/test/widgets/semantics_tester.dart index 26d67499a0..2d0d0cbbe2 100644 --- a/packages/flutter/test/widgets/semantics_tester.dart +++ b/packages/flutter/test/widgets/semantics_tester.dart @@ -560,6 +560,8 @@ class SemanticsTester { String? label, String? value, String? hint, + String? increasedValue, + String? decreasedValue, TextDirection? textDirection, List? actions, List? flags, @@ -597,6 +599,12 @@ class SemanticsTester { if (hint != null && node.hint != hint) { return false; } + if (increasedValue != null && node.increasedValue != increasedValue) { + return false; + } + if (decreasedValue != null && node.decreasedValue != decreasedValue) { + return false; + } if (attributedHint != null && (attributedHint.string != node.attributedHint.string || !_stringAttributesEqual(attributedHint.attributes, node.attributedHint.attributes))) { @@ -916,6 +924,8 @@ class _IncludesNodeWith extends Matcher { this.label, this.value, this.hint, + this.increasedValue, + this.decreasedValue, this.textDirection, this.actions, this.flags, @@ -931,6 +941,8 @@ class _IncludesNodeWith extends Matcher { actions != null || flags != null || tags != null || + increasedValue != null || + decreasedValue != null || scrollPosition != null || scrollExtentMax != null || scrollExtentMin != null || @@ -943,6 +955,8 @@ class _IncludesNodeWith extends Matcher { final String? label; final String? value; final String? hint; + final String? increasedValue; + final String? decreasedValue; final TextDirection? textDirection; final List? actions; final List? flags; @@ -963,6 +977,8 @@ class _IncludesNodeWith extends Matcher { label: label, value: value, hint: hint, + increasedValue: increasedValue, + decreasedValue: decreasedValue, textDirection: textDirection, actions: actions, flags: flags, @@ -1000,6 +1016,8 @@ class _IncludesNodeWith extends Matcher { if (actions != null) 'actions "${actions!.join(', ')}"', if (flags != null) 'flags "${flags!.join(', ')}"', if (tags != null) 'tags "${tags!.join(', ')}"', + if (increasedValue != null) 'increasedValue "$increasedValue"', + if (decreasedValue != null) 'decreasedValue "$decreasedValue"', if (scrollPosition != null) 'scrollPosition "$scrollPosition"', if (scrollExtentMax != null) 'scrollExtentMax "$scrollExtentMax"', if (scrollExtentMin != null) 'scrollExtentMin "$scrollExtentMin"', @@ -1021,6 +1039,8 @@ Matcher includesNodeWith({ AttributedString? attributedValue, String? hint, AttributedString? attributedHint, + String? increasedValue, + String? decreasedValue, TextDirection? textDirection, List? actions, List? flags, @@ -1039,6 +1059,8 @@ Matcher includesNodeWith({ hint: hint, attributedHint: attributedHint, textDirection: textDirection, + increasedValue: increasedValue, + decreasedValue: decreasedValue, actions: actions, flags: flags, tags: tags,