Skip to content

Commit 99a427a

Browse files
[cupertino_ui] Migrate segmented_control_test.dart to SemanticsHandle (#11982)
Part of flutter/flutter#182636 and flutter/flutter#188395 This PR: * Removed the cross-import of `widgets/semantics_tester.dart`. Replaced `SemanticsTester` with `SemanticsHandle`. * Removed `@Skip` annotation, all tests in this file has passed. `semantics_tester.dart` has existed in `cupertino_ui`, so we can directly import `semantics_tester.dart`; * Moved the file to `test/` folder. ## Pre-Review Checklist
1 parent 7a9c621 commit 99a427a

1 file changed

Lines changed: 59 additions & 81 deletions

File tree

packages/cupertino_ui/temporarily_disabled_tests/segmented_control_test.dart renamed to packages/cupertino_ui/test/segmented_control_test.dart

Lines changed: 59 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@Skip(
6-
'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.',
7-
)
85
// This file is run as part of a reduced test set in CI on Mac and Windows
96
// machines.
107
@Tags(<String>['reduced-test-set'])
@@ -19,8 +16,6 @@ import 'package:flutter/rendering.dart';
1916
import 'package:flutter/services.dart';
2017
import 'package:flutter_test/flutter_test.dart';
2118

22-
import '../widgets/semantics_tester.dart';
23-
2419
RenderBox getRenderSegmentedControl(WidgetTester tester) {
2520
return tester.allRenderObjects.firstWhere((RenderObject currentObject) {
2621
return currentObject.toStringShort().contains('_RenderSegmentedControl');
@@ -813,8 +808,6 @@ void main() {
813808
});
814809

815810
testWidgets('Segmented control semantics', (WidgetTester tester) async {
816-
final semantics = SemanticsTester(tester);
817-
818811
final children = <int, Widget>{};
819812
children[0] = const Text('Child 1');
820813
children[1] = const Text('Child 2');
@@ -841,91 +834,76 @@ void main() {
841834
),
842835
);
843836

837+
// Assert parent role.
838+
final SemanticsNode segmentedControlNode = tester.getSemantics(
839+
find.byType(CupertinoSegmentedControl<int>),
840+
);
841+
expect(segmentedControlNode.role, ui.SemanticsRole.radioGroup);
842+
843+
// Assert Child 1 (selected).
844844
expect(
845-
semantics,
846-
hasSemantics(
847-
TestSemantics.root(
848-
children: <TestSemantics>[
849-
TestSemantics.rootChild(
850-
role: SemanticsRole.radioGroup,
851-
children: <TestSemantics>[
852-
TestSemantics(
853-
label: 'Child 1',
854-
flags: <SemanticsFlag>[
855-
SemanticsFlag.isButton,
856-
SemanticsFlag.isInMutuallyExclusiveGroup,
857-
SemanticsFlag.hasSelectedState,
858-
SemanticsFlag.isSelected,
859-
SemanticsFlag.isFocusable,
860-
],
861-
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
862-
),
863-
TestSemantics(
864-
label: 'Child 2',
865-
flags: <SemanticsFlag>[
866-
SemanticsFlag.isButton,
867-
SemanticsFlag.isInMutuallyExclusiveGroup,
868-
// Declares that it is selectable, but not currently selected.
869-
SemanticsFlag.hasSelectedState,
870-
SemanticsFlag.isFocusable,
871-
],
872-
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
873-
),
874-
],
875-
),
876-
],
877-
),
878-
ignoreId: true,
879-
ignoreRect: true,
880-
ignoreTransform: true,
845+
find.semantics.byLabel('Child 1'),
846+
isSemantics(
847+
label: 'Child 1',
848+
isButton: true,
849+
isInMutuallyExclusiveGroup: true,
850+
hasSelectedState: true,
851+
isSelected: true,
852+
isFocusable: true,
853+
hasTapAction: true,
854+
hasFocusAction: true,
881855
),
882856
);
883857

858+
// Assert Child 2 (unselected).
859+
expect(
860+
find.semantics.byLabel('Child 2'),
861+
isSemantics(
862+
label: 'Child 2',
863+
isButton: true,
864+
isInMutuallyExclusiveGroup: true,
865+
hasSelectedState: true,
866+
isSelected: false,
867+
isFocusable: true,
868+
hasTapAction: true,
869+
hasFocusAction: true,
870+
),
871+
);
872+
873+
// Tap Child 2
884874
await tester.tap(find.text('Child 2'));
885875
await tester.pump();
886876

877+
// Assert Child 1 (now unselected).
887878
expect(
888-
semantics,
889-
hasSemantics(
890-
TestSemantics.root(
891-
children: <TestSemantics>[
892-
TestSemantics.rootChild(
893-
role: SemanticsRole.radioGroup,
894-
children: <TestSemantics>[
895-
TestSemantics(
896-
label: 'Child 1',
897-
flags: <SemanticsFlag>[
898-
SemanticsFlag.isButton,
899-
SemanticsFlag.isInMutuallyExclusiveGroup,
900-
// Declares that it is selectable, but not currently selected.
901-
SemanticsFlag.hasSelectedState,
902-
SemanticsFlag.isFocusable,
903-
],
904-
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
905-
),
906-
TestSemantics(
907-
label: 'Child 2',
908-
flags: <SemanticsFlag>[
909-
SemanticsFlag.isButton,
910-
SemanticsFlag.isInMutuallyExclusiveGroup,
911-
SemanticsFlag.hasSelectedState,
912-
SemanticsFlag.isSelected,
913-
SemanticsFlag.isFocusable,
914-
SemanticsFlag.isFocused,
915-
],
916-
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
917-
),
918-
],
919-
),
920-
],
921-
),
922-
ignoreId: true,
923-
ignoreRect: true,
924-
ignoreTransform: true,
879+
find.semantics.byLabel('Child 1'),
880+
isSemantics(
881+
label: 'Child 1',
882+
isButton: true,
883+
isInMutuallyExclusiveGroup: true,
884+
hasSelectedState: true,
885+
isSelected: false,
886+
isFocusable: true,
887+
hasTapAction: true,
888+
hasFocusAction: true,
925889
),
926890
);
927891

928-
semantics.dispose();
892+
// Assert Child 2 (now selected and focused).
893+
expect(
894+
find.semantics.byLabel('Child 2'),
895+
isSemantics(
896+
label: 'Child 2',
897+
isButton: true,
898+
isInMutuallyExclusiveGroup: true,
899+
hasSelectedState: true,
900+
isSelected: true,
901+
isFocusable: true,
902+
isFocused: true,
903+
hasTapAction: true,
904+
hasFocusAction: true,
905+
),
906+
);
929907
});
930908

931909
testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async {

0 commit comments

Comments
 (0)