Refactor: Remove material from actions test (#181702)
Refactor: Remove material from actions test
part of: https://github.com/flutter/flutter/issues/177415
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
diff --git a/dev/bots/check_tests_cross_imports.dart b/dev/bots/check_tests_cross_imports.dart
index d1b334a..9147cf3 100644
--- a/dev/bots/check_tests_cross_imports.dart
+++ b/dev/bots/check_tests_cross_imports.dart
@@ -163,7 +163,6 @@
'packages/flutter/test/widgets/list_wheel_scroll_view_test.dart',
'packages/flutter/test/widgets/pop_scope_test.dart',
'packages/flutter/test/widgets/scrollbar_test.dart',
- 'packages/flutter/test/widgets/actions_test.dart',
'packages/flutter/test/widgets/scroll_physics_test.dart',
'packages/flutter/test/widgets/obscured_animated_image_test.dart',
'packages/flutter/test/widgets/platform_menu_bar_test.dart',
diff --git a/packages/flutter/test/widgets/actions_test.dart b/packages/flutter/test/widgets/actions_test.dart
index e20ed85..37af758 100644
--- a/packages/flutter/test/widgets/actions_test.dart
+++ b/packages/flutter/test/widgets/actions_test.dart
@@ -4,11 +4,14 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
-import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
+import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'utils.dart';
+import 'widgets_app_tester.dart';
+
void main() {
group(ActionDispatcher, () {
testWidgets('ActionDispatcher invokes actions when asked.', (WidgetTester tester) async {
@@ -837,13 +840,9 @@
addTearDown(buttonNode.dispose);
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
- child: ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode,
- child: const Text('Test'),
- ),
+ child: TestButton(onPressed: () {}, focusNode: buttonNode, child: const Text('Test')),
),
),
);
@@ -855,14 +854,10 @@
expect(buttonNode.hasFocus, isTrue);
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
descendantsAreFocusable: false,
- child: ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode,
- child: const Text('Test'),
- ),
+ child: TestButton(onPressed: () {}, focusNode: buttonNode, child: const Text('Test')),
),
),
);
@@ -888,21 +883,13 @@
});
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
focusNode: skipTraversalNode,
child: Column(
children: <Widget>[
- ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode1,
- child: const Text('Node 1'),
- ),
- ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode2,
- child: const Text('Node 2'),
- ),
+ TestButton(onPressed: () {}, focusNode: buttonNode1, child: const Text('Node 1')),
+ TestButton(onPressed: () {}, focusNode: buttonNode2, child: const Text('Node 2')),
],
),
),
@@ -919,22 +906,14 @@
expect(buttonNode2.hasFocus, isTrue);
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
focusNode: skipTraversalNode,
descendantsAreTraversable: false,
child: Column(
children: <Widget>[
- ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode1,
- child: const Text('Node 1'),
- ),
- ElevatedButton(
- onPressed: () {},
- focusNode: buttonNode2,
- child: const Text('Node 2'),
- ),
+ TestButton(onPressed: () {}, focusNode: buttonNode1, child: const Text('Node 1')),
+ TestButton(onPressed: () {}, focusNode: buttonNode2, child: const Text('Node 2')),
],
),
),
@@ -953,64 +932,37 @@
testWidgets('FocusableActionDetector can exclude Focus semantics', (WidgetTester tester) async {
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
child: Column(
children: <Widget>[
- TextButton(onPressed: () {}, child: const Text('Button 1')),
- TextButton(onPressed: () {}, child: const Text('Button 2')),
+ TestButton(onPressed: () {}, child: const Text('Button 1')),
+ TestButton(onPressed: () {}, child: const Text('Button 2')),
],
),
),
),
);
- expect(
- tester.getSemantics(find.byType(FocusableActionDetector)),
- matchesSemantics(
- scopesRoute: true,
- children: <Matcher>[
- // This semantic is from `Focus` widget under `FocusableActionDetector`.
- matchesSemantics(
- isFocusable: true,
- hasFocusAction: true,
- children: <Matcher>[
- matchesSemantics(
- hasTapAction: true,
- hasFocusAction: true,
- isButton: true,
- hasEnabledState: true,
- isEnabled: true,
- isFocusable: true,
- label: 'Button 1',
- textDirection: TextDirection.ltr,
- ),
- matchesSemantics(
- hasTapAction: true,
- hasFocusAction: true,
- isButton: true,
- hasEnabledState: true,
- isEnabled: true,
- isFocusable: true,
- label: 'Button 2',
- textDirection: TextDirection.ltr,
- ),
- ],
- ),
- ],
- ),
+ // With includeFocusSemantics: true (default), the Focus widget under
+ // FocusableActionDetector adds isFocusable semantics.
+ final Focus focusWidgetIncluded = tester.widget<Focus>(
+ find
+ .descendant(of: find.byType(FocusableActionDetector), matching: find.byType(Focus))
+ .first,
);
+ expect(focusWidgetIncluded.includeSemantics, isTrue);
// Set `includeFocusSemantics` to false to exclude semantics
// from `Focus` widget under `FocusableActionDetector`.
await tester.pumpWidget(
- MaterialApp(
+ TestWidgetsApp(
home: FocusableActionDetector(
includeFocusSemantics: false,
child: Column(
children: <Widget>[
- TextButton(onPressed: () {}, child: const Text('Button 1')),
- TextButton(onPressed: () {}, child: const Text('Button 2')),
+ TestButton(onPressed: () {}, child: const Text('Button 1')),
+ TestButton(onPressed: () {}, child: const Text('Button 2')),
],
),
),
@@ -1018,34 +970,12 @@
);
// Semantics from the `Focus` widget will be removed.
- expect(
- tester.getSemantics(find.byType(FocusableActionDetector)),
- matchesSemantics(
- scopesRoute: true,
- children: <Matcher>[
- matchesSemantics(
- hasTapAction: true,
- hasFocusAction: true,
- isButton: true,
- hasEnabledState: true,
- isEnabled: true,
- isFocusable: true,
- label: 'Button 1',
- textDirection: TextDirection.ltr,
- ),
- matchesSemantics(
- hasTapAction: true,
- hasFocusAction: true,
- isButton: true,
- hasEnabledState: true,
- isEnabled: true,
- isFocusable: true,
- label: 'Button 2',
- textDirection: TextDirection.ltr,
- ),
- ],
- ),
+ final Focus focusWidgetExcluded = tester.widget<Focus>(
+ find
+ .descendant(of: find.byType(FocusableActionDetector), matching: find.byType(Focus))
+ .first,
);
+ expect(focusWidgetExcluded.includeSemantics, isFalse);
});
});