Adds cupertino picker semantics test (#161768)
Adds a test ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
parent
c289c638fe
commit
a0cb28b831
@ -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<Widget>.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>[SemanticsAction.increase],
|
||||
),
|
||||
);
|
||||
|
||||
final FixedExtentScrollController hourListController =
|
||||
tester.widget<ListWheelScrollView>(find.byType(ListWheelScrollView)).controller!
|
||||
as FixedExtentScrollController;
|
||||
|
||||
hourListController.jumpToItem(11);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
semantics,
|
||||
includesNodeWith(
|
||||
value: '11',
|
||||
increasedValue: '12',
|
||||
decreasedValue: '10',
|
||||
actions: <SemanticsAction>[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 {
|
||||
|
@ -560,6 +560,8 @@ class SemanticsTester {
|
||||
String? label,
|
||||
String? value,
|
||||
String? hint,
|
||||
String? increasedValue,
|
||||
String? decreasedValue,
|
||||
TextDirection? textDirection,
|
||||
List<SemanticsAction>? actions,
|
||||
List<SemanticsFlag>? 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<SemanticsAction>? actions;
|
||||
final List<SemanticsFlag>? 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<SemanticsAction>? actions,
|
||||
List<SemanticsFlag>? flags,
|
||||
@ -1039,6 +1059,8 @@ Matcher includesNodeWith({
|
||||
hint: hint,
|
||||
attributedHint: attributedHint,
|
||||
textDirection: textDirection,
|
||||
increasedValue: increasedValue,
|
||||
decreasedValue: decreasedValue,
|
||||
actions: actions,
|
||||
flags: flags,
|
||||
tags: tags,
|
||||
|
Loading…
x
Reference in New Issue
Block a user