-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[cupertino_ui] Migrate segmented_control_test.dart to SemanticsHandle
#11982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,6 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| @Skip( | ||
| 'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.', | ||
| ) | ||
| // This file is run as part of a reduced test set in CI on Mac and Windows | ||
| // machines. | ||
| @Tags(<String>['reduced-test-set']) | ||
|
|
@@ -19,8 +16,6 @@ import 'package:flutter/rendering.dart'; | |
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| import '../widgets/semantics_tester.dart'; | ||
|
|
||
| RenderBox getRenderSegmentedControl(WidgetTester tester) { | ||
| return tester.allRenderObjects.firstWhere((RenderObject currentObject) { | ||
| return currentObject.toStringShort().contains('_RenderSegmentedControl'); | ||
|
|
@@ -813,8 +808,6 @@ void main() { | |
| }); | ||
|
|
||
| testWidgets('Segmented control semantics', (WidgetTester tester) async { | ||
| final semantics = SemanticsTester(tester); | ||
|
|
||
| final children = <int, Widget>{}; | ||
| children[0] = const Text('Child 1'); | ||
| children[1] = const Text('Child 2'); | ||
|
|
@@ -841,91 +834,76 @@ void main() { | |
| ), | ||
| ); | ||
|
|
||
| // Assert parent role. | ||
| final SemanticsNode segmentedControlNode = tester.getSemantics( | ||
| find.byType(CupertinoSegmentedControl<int>), | ||
| ); | ||
| expect(segmentedControlNode.role, ui.SemanticsRole.radioGroup); | ||
|
|
||
| // Assert Child 1 (selected). | ||
| expect( | ||
| semantics, | ||
| hasSemantics( | ||
| TestSemantics.root( | ||
| children: <TestSemantics>[ | ||
| TestSemantics.rootChild( | ||
| role: SemanticsRole.radioGroup, | ||
| children: <TestSemantics>[ | ||
| TestSemantics( | ||
| label: 'Child 1', | ||
| flags: <SemanticsFlag>[ | ||
| SemanticsFlag.isButton, | ||
| SemanticsFlag.isInMutuallyExclusiveGroup, | ||
| SemanticsFlag.hasSelectedState, | ||
| SemanticsFlag.isSelected, | ||
| SemanticsFlag.isFocusable, | ||
| ], | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus], | ||
| ), | ||
| TestSemantics( | ||
| label: 'Child 2', | ||
| flags: <SemanticsFlag>[ | ||
| SemanticsFlag.isButton, | ||
| SemanticsFlag.isInMutuallyExclusiveGroup, | ||
| // Declares that it is selectable, but not currently selected. | ||
| SemanticsFlag.hasSelectedState, | ||
| SemanticsFlag.isFocusable, | ||
| ], | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ignoreId: true, | ||
| ignoreRect: true, | ||
| ignoreTransform: true, | ||
| find.semantics.byLabel('Child 1'), | ||
| isSemantics( | ||
| label: 'Child 1', | ||
| isButton: true, | ||
| isInMutuallyExclusiveGroup: true, | ||
| hasSelectedState: true, | ||
| isSelected: true, | ||
| isFocusable: true, | ||
| hasTapAction: true, | ||
| hasFocusAction: true, | ||
| ), | ||
| ); | ||
|
|
||
| // Assert Child 2 (unselected). | ||
| expect( | ||
| find.semantics.byLabel('Child 2'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| isSemantics( | ||
| label: 'Child 2', | ||
| isButton: true, | ||
| isInMutuallyExclusiveGroup: true, | ||
| hasSelectedState: true, | ||
| isSelected: false, | ||
| isFocusable: true, | ||
| hasTapAction: true, | ||
| hasFocusAction: true, | ||
| ), | ||
| ); | ||
|
|
||
| // Tap Child 2 | ||
| await tester.tap(find.text('Child 2')); | ||
| await tester.pump(); | ||
|
|
||
| // Assert Child 1 (now unselected). | ||
| expect( | ||
| semantics, | ||
| hasSemantics( | ||
| TestSemantics.root( | ||
| children: <TestSemantics>[ | ||
| TestSemantics.rootChild( | ||
| role: SemanticsRole.radioGroup, | ||
| children: <TestSemantics>[ | ||
| TestSemantics( | ||
| label: 'Child 1', | ||
| flags: <SemanticsFlag>[ | ||
| SemanticsFlag.isButton, | ||
| SemanticsFlag.isInMutuallyExclusiveGroup, | ||
| // Declares that it is selectable, but not currently selected. | ||
| SemanticsFlag.hasSelectedState, | ||
| SemanticsFlag.isFocusable, | ||
| ], | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus], | ||
| ), | ||
| TestSemantics( | ||
| label: 'Child 2', | ||
| flags: <SemanticsFlag>[ | ||
| SemanticsFlag.isButton, | ||
| SemanticsFlag.isInMutuallyExclusiveGroup, | ||
| SemanticsFlag.hasSelectedState, | ||
| SemanticsFlag.isSelected, | ||
| SemanticsFlag.isFocusable, | ||
| SemanticsFlag.isFocused, | ||
| ], | ||
| actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ignoreId: true, | ||
| ignoreRect: true, | ||
| ignoreTransform: true, | ||
| find.semantics.byLabel('Child 1'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| isSemantics( | ||
| label: 'Child 1', | ||
| isButton: true, | ||
| isInMutuallyExclusiveGroup: true, | ||
| hasSelectedState: true, | ||
| isSelected: false, | ||
| isFocusable: true, | ||
| hasTapAction: true, | ||
| hasFocusAction: true, | ||
| ), | ||
| ); | ||
|
|
||
| semantics.dispose(); | ||
| // Assert Child 2 (now selected and focused). | ||
| expect( | ||
| find.semantics.byLabel('Child 2'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| isSemantics( | ||
| label: 'Child 2', | ||
| isButton: true, | ||
| isInMutuallyExclusiveGroup: true, | ||
| hasSelectedState: true, | ||
| isSelected: true, | ||
| isFocusable: true, | ||
| isFocused: true, | ||
| hasTapAction: true, | ||
| hasFocusAction: true, | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
find.semanticsproperty does not exist onCommonFinders. To find a widget by its semantics label, usefind.bySemanticsLabelinstead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find.semanticsdoes exist.