Skip to content

Commit

Permalink
Test cover more tests with leak tracking. (#133712)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Aug 31, 2023
1 parent c1256d5 commit 127b90e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,20 @@ void main() {
expect(find.byKey(key), findsOneWidget);
});

testWidgets('Can build from EditableTextState', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can build from EditableTextState', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
final TextEditingController controller = TextEditingController();
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 400,
child: EditableText(
controller: TextEditingController(),
controller: controller,
backgroundCursorColor: const Color(0xff00ffff),
focusNode: FocusNode(),
focusNode: focusNode,
style: const TextStyle(),
cursorColor: const Color(0xff00ffff),
selectionControls: materialTextSelectionHandleControls,
Expand Down Expand Up @@ -170,6 +172,8 @@ void main() {
case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton), findsOneWidget);
}
controller.dispose();
focusNode.dispose();
},
skip: kIsWeb, // [intended] on web the browser handles the context menu.
variant: TargetPlatformVariant.all(),
Expand Down Expand Up @@ -233,13 +237,14 @@ void main() {
);

group('buttonItems', () {
testWidgets('getEditableTextButtonItems builds the correct button items per-platform', (WidgetTester tester) async {
testWidgetsWithLeakTracking('getEditableTextButtonItems builds the correct button items per-platform', (WidgetTester tester) async {
// Fill the clipboard so that the Paste option is available in the text
// selection menu.
await Clipboard.setData(const ClipboardData(text: 'Clipboard data'));

Set<ContextMenuButtonType> buttonTypes = <ContextMenuButtonType>{};
final TextEditingController controller = TextEditingController();
final FocusNode focusNode = FocusNode();

await tester.pumpWidget(
MaterialApp(
Expand All @@ -248,7 +253,7 @@ void main() {
child: EditableText(
controller: controller,
backgroundCursorColor: Colors.grey,
focusNode: FocusNode(),
focusNode: focusNode,
style: const TextStyle(),
cursorColor: Colors.red,
selectionControls: materialTextSelectionHandleControls,
Expand Down Expand Up @@ -323,12 +328,15 @@ void main() {
case TargetPlatform.macOS:
expect(buttonTypes, isNot(contains(ContextMenuButtonType.selectAll)));
}

focusNode.dispose();
controller.dispose();
},
variant: TargetPlatformVariant.all(),
skip: kIsWeb, // [intended]
);

testWidgets('getAdaptiveButtons builds the correct button widgets per-platform', (WidgetTester tester) async {
testWidgetsWithLeakTracking('getAdaptiveButtons builds the correct button widgets per-platform', (WidgetTester tester) async {
const String buttonText = 'Click me';

await tester.pumpWidget(
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/app_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,7 @@ void main() {
expect(tester.getRect(find.byKey(key)), const Rect.fromLTRB(0, 0, 100, 56));
});

testWidgets("AppBar with EndDrawer doesn't have leading", (WidgetTester tester) async {
testWidgetsWithLeakTracking("AppBar with EndDrawer doesn't have leading", (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
appBar: AppBar(),
Expand Down
27 changes: 13 additions & 14 deletions packages/flutter/test/material/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void main() {
];

testWidgetsWithLeakTracking('can filter and select a list of string options', (WidgetTester tester) async {

late String lastSelection;
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -107,7 +106,7 @@ void main() {
expect(list.semanticChildCount, 6);
});

testWidgets('can filter and select a list of custom User options', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can filter and select a list of custom User options', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
Expand Down Expand Up @@ -161,7 +160,7 @@ void main() {
expect(list.semanticChildCount, 1);
});

testWidgets('displayStringForOption is displayed in the options', (WidgetTester tester) async {
testWidgetsWithLeakTracking('displayStringForOption is displayed in the options', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
Expand Down Expand Up @@ -204,7 +203,7 @@ void main() {
expect(field.controller!.text, kOptionsUsers.first.name);
});

testWidgets('can build a custom field', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can build a custom field', (WidgetTester tester) async {
final GlobalKey fieldKey = GlobalKey();
await tester.pumpWidget(
MaterialApp(
Expand All @@ -228,7 +227,7 @@ void main() {
expect(find.byType(TextFormField), findsNothing);
});

testWidgets('can build custom options', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can build custom options', (WidgetTester tester) async {
final GlobalKey optionsKey = GlobalKey();
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -257,7 +256,7 @@ void main() {
expect(find.byKey(optionsKey), findsOneWidget);
});

testWidgets('the default Autocomplete options widget has a maximum height of 200', (WidgetTester tester) async {
testWidgetsWithLeakTracking('the default Autocomplete options widget has a maximum height of 200', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: Scaffold(
body: Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
Expand All @@ -278,7 +277,7 @@ void main() {
expect(resultingHeight, equals(200));
});

testWidgets('the options height restricts to max desired height', (WidgetTester tester) async {
testWidgetsWithLeakTracking('the options height restricts to max desired height', (WidgetTester tester) async {
const double desiredHeight = 150.0;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
Expand Down Expand Up @@ -307,7 +306,7 @@ void main() {
expect(resultingHeight, equals(desiredHeight));
});

testWidgets('The height of options shrinks to height of resulting items, if less than maxHeight', (WidgetTester tester) async {
testWidgetsWithLeakTracking('The height of options shrinks to height of resulting items, if less than maxHeight', (WidgetTester tester) async {
// Returns a Future with the height of the default [Autocomplete] options widget
// after the provided text had been entered into the [Autocomplete] field.
Future<double> getDefaultOptionsHeight(
Expand Down Expand Up @@ -355,7 +354,7 @@ void main() {
expect(oneItemsHeight, lessThan(twoItemsHeight));
});

testWidgets('initialValue sets initial text field value', (WidgetTester tester) async {
testWidgetsWithLeakTracking('initialValue sets initial text field value', (WidgetTester tester) async {
late String lastSelection;
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -416,7 +415,7 @@ void main() {
}
}

testWidgets('keyboard navigation of the options properly highlights the option', (WidgetTester tester) async {
testWidgetsWithLeakTracking('keyboard navigation of the options properly highlights the option', (WidgetTester tester) async {
const Color highlightColor = Color(0xFF112233);
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -455,7 +454,7 @@ void main() {
checkOptionHighlight(tester, 'elephant', highlightColor);
});

testWidgets('keyboard navigation keeps the highlighted option scrolled into view', (WidgetTester tester) async {
testWidgetsWithLeakTracking('keyboard navigation keeps the highlighted option scrolled into view', (WidgetTester tester) async {
const Color highlightColor = Color(0xFF112233);
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -519,7 +518,7 @@ void main() {
});

group('optionsViewOpenDirection', () {
testWidgets('default (down)', (WidgetTester tester) async {
testWidgetsWithLeakTracking('default (down)', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
Expand All @@ -534,7 +533,7 @@ void main() {
expect(actual, equals(OptionsViewOpenDirection.down));
});

testWidgets('down', (WidgetTester tester) async {
testWidgetsWithLeakTracking('down', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
Expand All @@ -550,7 +549,7 @@ void main() {
expect(actual, equals(OptionsViewOpenDirection.down));
});

testWidgets('up', (WidgetTester tester) async {
testWidgetsWithLeakTracking('up', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/material/button_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void main() {

group('layoutBehavior', () {

testWidgets('ButtonBar has a min height of 52 when using ButtonBarLayoutBehavior.constrained', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ButtonBar has a min height of 52 when using ButtonBarLayoutBehavior.constrained', (WidgetTester tester) async {
await tester.pumpWidget(
const SingleChildScrollView(
child: ListBody(
Expand All @@ -363,7 +363,7 @@ void main() {
expect(tester.getBottomRight(buttonBar).dy - tester.getTopRight(buttonBar).dy, 52.0);
});

testWidgets('ButtonBar has padding applied when using ButtonBarLayoutBehavior.padded', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ButtonBar has padding applied when using ButtonBarLayoutBehavior.padded', (WidgetTester tester) async {
await tester.pumpWidget(
const SingleChildScrollView(
child: ListBody(
Expand Down

0 comments on commit 127b90e

Please sign in to comment.