Unverified Commit 56da3710 authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Update AutoComplete test for M3 migration (#130883)

This PR updates unit tests from autocomplete_test.dart for M3 migration.

More info in https://github.com/flutter/flutter/issues/127064

I replaced magic numbers (64.0 and 187.0) and found ways to compute them without relying on the Material version.
parent 2afe8aa5
...@@ -459,9 +459,7 @@ void main() { ...@@ -459,9 +459,7 @@ void main() {
const Color highlightColor = Color(0xFF112233); const Color highlightColor = Color(0xFF112233);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData.light(useMaterial3: false).copyWith( theme: ThemeData.light().copyWith(focusColor: highlightColor),
focusColor: highlightColor,
),
home: Scaffold( home: Scaffold(
body: Autocomplete<String>( body: Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) { optionsBuilder: (TextEditingValue textEditingValue) {
...@@ -481,27 +479,39 @@ void main() { ...@@ -481,27 +479,39 @@ void main() {
final ListView list = find.byType(ListView).evaluate().first.widget as ListView; final ListView list = find.byType(ListView).evaluate().first.widget as ListView;
expect(list.semanticChildCount, 6); expect(list.semanticChildCount, 6);
// Highlighted item should be at the top final Rect optionsGroupRect = tester.getRect(find.byType(ListView));
expect(tester.getTopLeft(find.text('chameleon')).dy, equals(64.0)); const double optionsGroupPadding = 16.0;
// Highlighted item should be at the top.
checkOptionHighlight(tester, 'chameleon', highlightColor); checkOptionHighlight(tester, 'chameleon', highlightColor);
expect(
tester.getTopLeft(find.text('chameleon')).dy,
equals(optionsGroupRect.top + optionsGroupPadding),
);
// Move down the list of options // Move down the list of options.
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'elephant'.
await tester.pump(); await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'goose'.
await tester.pump(); await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'lemur'.
await tester.pump(); await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
// First item should have scrolled off the top, and not be selected. // Highlighted item 'lemur' should be centered in the options popup.
expect(find.text('chameleon'), findsNothing); checkOptionHighlight(tester, 'lemur', highlightColor);
expect(
tester.getCenter(find.text('lemur')).dy,
equals(optionsGroupRect.center.dy),
);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Select 'mouse'.
await tester.pumpAndSettle();
// Highlighted item 'lemur' should be centered in the options popup
expect(tester.getTopLeft(find.text('mouse')).dy, equals(187.0));
checkOptionHighlight(tester, 'mouse', highlightColor); checkOptionHighlight(tester, 'mouse', highlightColor);
// First item should have scrolled off the top, and not be selected.
expect(find.text('chameleon'), findsNothing);
// The other items on screen should not be selected. // The other items on screen should not be selected.
checkOptionHighlight(tester, 'goose', null); checkOptionHighlight(tester, 'goose', null);
checkOptionHighlight(tester, 'lemur', null); checkOptionHighlight(tester, 'lemur', null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment