Unverified Commit 6d4121c0 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Fix tests that rely on FadeTransition incorrectly and depend on implementation...

Fix tests that rely on FadeTransition incorrectly and depend on implementation details of FadeUpwardsTransitionBuilder (#51150)
parent 5ee41472
...@@ -119,7 +119,18 @@ void main() { ...@@ -119,7 +119,18 @@ void main() {
expect(selectedIcon.fontSize, equals(24.0)); expect(selectedIcon.fontSize, equals(24.0));
expect(unselectedIcon.color, equals(captionColor)); expect(unselectedIcon.color, equals(captionColor));
expect(unselectedIcon.fontSize, equals(24.0)); expect(unselectedIcon.fontSize, equals(24.0));
expect(_getOpacity(tester, 'Alarm'), equals(1.0)); // There should not be any [Opacity] or [FadeTransition] widgets
// since showUnselectedLabels and showSelectedLabels are true.
final Finder findOpacity = find.descendant(
of: find.byType(BottomNavigationBar),
matching: find.byType(Opacity),
);
final Finder findFadeTransition = find.descendant(
of: find.byType(BottomNavigationBar),
matching: find.byType(FadeTransition),
);
expect(findOpacity, findsNothing);
expect(findFadeTransition, findsNothing);
expect(_getMaterial(tester).elevation, equals(8.0)); expect(_getMaterial(tester).elevation, equals(8.0));
}); });
...@@ -472,7 +483,18 @@ void main() { ...@@ -472,7 +483,18 @@ void main() {
); );
expect(tester.renderObject<RenderParagraph>(find.text('AC')).text.style.color, equals(selectedColor)); expect(tester.renderObject<RenderParagraph>(find.text('AC')).text.style.color, equals(selectedColor));
expect(tester.renderObject<RenderParagraph>(find.text('Alarm')).text.style.color, equals(unselectedColor)); expect(tester.renderObject<RenderParagraph>(find.text('Alarm')).text.style.color, equals(unselectedColor));
expect(_getOpacity(tester, 'Alarm'), equals(1.0)); // There should not be any [Opacity] or [FadeTransition] widgets
// since showUnselectedLabels and showSelectedLabels are true.
final Finder findOpacity = find.descendant(
of: find.byType(BottomNavigationBar),
matching: find.byType(Opacity),
);
final Finder findFadeTransition = find.descendant(
of: find.byType(BottomNavigationBar),
matching: find.byType(FadeTransition),
);
expect(findOpacity, findsNothing);
expect(findFadeTransition, findsNothing);
}); });
......
...@@ -84,6 +84,13 @@ void main() { ...@@ -84,6 +84,13 @@ void main() {
'debugCheckHasScaffold control test', (WidgetTester tester) async { 'debugCheckHasScaffold control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
home: Builder( home: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
showBottomSheet<void>(context: context, showBottomSheet<void>(context: context,
......
...@@ -401,7 +401,14 @@ void main() { ...@@ -401,7 +401,14 @@ void main() {
testWidgets('test adaptable transitions switch during execution', (WidgetTester tester) async { testWidgets('test adaptable transitions switch during execution', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.android), theme: ThemeData(
platform: TargetPlatform.android,
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
home: const Material(child: Text('Page 1')), home: const Material(child: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
......
...@@ -47,7 +47,7 @@ void main() { ...@@ -47,7 +47,7 @@ void main() {
expect(find.byType(CupertinoPageTransition), findsOneWidget); expect(find.byType(CupertinoPageTransition), findsOneWidget);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Default PageTranstionsTheme builds a _FadeUpwardsPageTransition for android', (WidgetTester tester) async { testWidgets('Default PageTransitionsTheme builds a _FadeUpwardsPageTransition for android', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: FlatButton( child: FlatButton(
......
...@@ -6999,14 +6999,13 @@ void main() { ...@@ -6999,14 +6999,13 @@ void main() {
renderEditable.selectWord(cause: SelectionChangedCause.longPress); renderEditable.selectWord(cause: SelectionChangedCause.longPress);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final List<FadeTransition> transitions = final List<FadeTransition> transitions = find.descendant(
find.byType(FadeTransition).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList(); of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TextSelectionHandleOverlay'),
// On Android, an empty app contains a single FadeTransition. The following matching: find.byType(FadeTransition),
// two are the left and right text selection handles, respectively. ).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList();
expect(transitions.length, 3); expect(transitions.length, 2);
final FadeTransition left = transitions[1]; final FadeTransition left = transitions[0];
final FadeTransition right = transitions[2]; final FadeTransition right = transitions[1];
expect(left.opacity.value, equals(1.0)); expect(left.opacity.value, equals(1.0));
expect(right.opacity.value, equals(1.0)); expect(right.opacity.value, equals(1.0));
}); });
......
...@@ -2971,12 +2971,13 @@ void main() { ...@@ -2971,12 +2971,13 @@ void main() {
// Check that the animations are functional and going in the right // Check that the animations are functional and going in the right
// direction. // direction.
final List<FadeTransition> transitions = final List<FadeTransition> transitions = find.descendant(
find.byType(FadeTransition).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList(); of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TextSelectionHandleOverlay'),
// On Android, an empty app contains a single FadeTransition. The following matching: find.byType(FadeTransition),
// two are the left and right text selection handles, respectively. ).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList();
final FadeTransition left = transitions[1]; expect(transitions.length, 2);
final FadeTransition right = transitions[2]; final FadeTransition left = transitions[0];
final FadeTransition right = transitions[1];
if (expectedLeftVisibleBefore) if (expectedLeftVisibleBefore)
expect(left.opacity.value, equals(1.0)); expect(left.opacity.value, equals(1.0));
......
...@@ -834,6 +834,13 @@ Future<void> main() async { ...@@ -834,6 +834,13 @@ Future<void> main() async {
// Show a 100x100 Hero tagged 'H' with key homeHeroKey // Show a 100x100 Hero tagged 'H' with key homeHeroKey
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
home: Scaffold( home: Scaffold(
body: Builder( body: Builder(
builder: (BuildContext context) { // Navigator.push() needs context builder: (BuildContext context) { // Navigator.push() needs context
......
...@@ -187,6 +187,13 @@ void main() { ...@@ -187,6 +187,13 @@ void main() {
testWidgets('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async { testWidgets('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async {
const String kHeroTag = 'hero'; const String kHeroTag = 'hero';
final Widget myApp = MaterialApp( final Widget myApp = MaterialApp(
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
initialRoute: '/', initialRoute: '/',
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/': (BuildContext context) => const Material(child: Hero( '/': (BuildContext context) => const Material(child: Hero(
......
...@@ -952,6 +952,13 @@ void main() { ...@@ -952,6 +952,13 @@ void main() {
Route<void> routeB; Route<void> routeB;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
navigatorKey: key, navigatorKey: key,
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
home: FlatButton( home: FlatButton(
child: const Text('A'), child: const Text('A'),
onPressed: () { onPressed: () {
...@@ -1474,6 +1481,13 @@ void main() { ...@@ -1474,6 +1481,13 @@ void main() {
final Key topRoute = UniqueKey(); final Key topRoute = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
),
),
navigatorKey: navigator, navigatorKey: navigator,
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/' : (BuildContext context) => StatefulTestWidget(key: bottomRoute), '/' : (BuildContext context) => StatefulTestWidget(key: bottomRoute),
......
...@@ -3575,13 +3575,13 @@ void main() { ...@@ -3575,13 +3575,13 @@ void main() {
renderEditable.selectWord(cause: SelectionChangedCause.longPress); renderEditable.selectWord(cause: SelectionChangedCause.longPress);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final List<Widget> transitions = final List<FadeTransition> transitions = find.descendant(
find.byType(FadeTransition).evaluate().map((Element e) => e.widget).toList(); of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TextSelectionHandleOverlay'),
// On Android, an empty app contains a single FadeTransition. The following matching: find.byType(FadeTransition),
// two are the left and right text selection handles, respectively. ).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList();
expect(transitions.length, 3); expect(transitions.length, 2);
final FadeTransition left = transitions[1] as FadeTransition; final FadeTransition left = transitions[0];
final FadeTransition right = transitions[2] as FadeTransition; final FadeTransition right = transitions[1];
expect(left.opacity.value, equals(1.0)); expect(left.opacity.value, equals(1.0));
expect(right.opacity.value, equals(1.0)); expect(right.opacity.value, equals(1.0));
......
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