From c91c18ebc5e4ad0b507f56833849698ee8dbf00c Mon Sep 17 00:00:00 2001 From: Qun Cheng Date: Mon, 18 Nov 2024 17:19:25 -0800 Subject: [PATCH] Update unit tests --- .../test/material/bottom_app_bar_test.dart | 2 +- .../test/material/expansion_tile_test.dart | 14 +++++++++-- .../test/material/icon_button_test.dart | 2 +- .../material/page_transitions_theme_test.dart | 25 +++++++++++++------ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/flutter/test/material/bottom_app_bar_test.dart b/packages/flutter/test/material/bottom_app_bar_test.dart index b20bf90a433..77a8b9d5f91 100644 --- a/packages/flutter/test/material/bottom_app_bar_test.dart +++ b/packages/flutter/test/material/bottom_app_bar_test.dart @@ -218,7 +218,7 @@ void main() { final BottomAppBar bottomAppBar = tester.widget(find.byType(BottomAppBar)); expect(bottomAppBar.padding, customPadding); final Rect babRect = tester.getRect(find.byType(BottomAppBar)); - final Rect childRect = tester.getRect(find.byType(ColoredBox)); + final Rect childRect = tester.getRect(find.byType(ColoredBox).last); expect(childRect, const Rect.fromLTRB(250, 530, 550, 590)); expect(babRect, const Rect.fromLTRB(240, 520, 560, 600)); }); diff --git a/packages/flutter/test/material/expansion_tile_test.dart b/packages/flutter/test/material/expansion_tile_test.dart index 338988b5b47..34310bcea0f 100644 --- a/packages/flutter/test/material/expansion_tile_test.dart +++ b/packages/flutter/test/material/expansion_tile_test.dart @@ -1567,7 +1567,12 @@ void main() { )); final Size materialAppSize = tester.getSize(find.byType(MaterialApp)); - final Size titleSize = tester.getSize(find.byType(ColoredBox)); + final Size titleSize = tester.getSize( + find.descendant( + of: find.byType(ExpansionTile), + matching: find.byType(ColoredBox) + ) + ); expect(titleSize.width, materialAppSize.width); }); @@ -1585,7 +1590,12 @@ void main() { )); final Size materialAppSize = tester.getSize(find.byType(MaterialApp)); - final Size titleSize = tester.getSize(find.byType(ColoredBox)); + final Size titleSize = tester.getSize( + find.descendant( + of: find.byType(ExpansionTile), + matching: find.byType(ColoredBox) + ) + ); expect(titleSize.width, materialAppSize.width - 32.0); }); diff --git a/packages/flutter/test/material/icon_button_test.dart b/packages/flutter/test/material/icon_button_test.dart index 6f2f695cfe7..2a505b25057 100644 --- a/packages/flutter/test/material/icon_button_test.dart +++ b/packages/flutter/test/material/icon_button_test.dart @@ -3017,7 +3017,7 @@ void main() { ), ); - final Offset topLeft = tester.getTopLeft(find.byType(ColoredBox)); + final Offset topLeft = tester.getTopLeft(find.byType(ColoredBox).last); final TestGesture gesture = await tester.createGesture( kind: PointerDeviceKind.mouse, ); diff --git a/packages/flutter/test/material/page_transitions_theme_test.dart b/packages/flutter/test/material/page_transitions_theme_test.dart index 9393865f1ae..a760a8b0f64 100644 --- a/packages/flutter/test/material/page_transitions_theme_test.dart +++ b/packages/flutter/test/material/page_transitions_theme_test.dart @@ -128,7 +128,7 @@ void main() { await tester.tap(find.text('push')); await tester.pump(const Duration(milliseconds: 400)); - final Finder coloredBoxFinder = find.byType(ColoredBox); + final Finder coloredBoxFinder = find.byType(ColoredBox).last; expect(coloredBoxFinder, findsOneWidget); final ColoredBox coloredBox = tester.widget(coloredBoxFinder); expect(coloredBox.color, Colors.pink); @@ -176,7 +176,7 @@ void main() { await tester.tap(find.text('push')); await tester.pump(const Duration(milliseconds: 400)); - final Finder coloredBoxFinder = find.byType(ColoredBox); + final Finder coloredBoxFinder = find.byType(ColoredBox).last; expect(coloredBoxFinder, findsOneWidget); final ColoredBox coloredBox = tester.widget(coloredBoxFinder); expect(coloredBox.color, Colors.lightGreen); @@ -214,11 +214,13 @@ void main() { await tester.tap(find.text('push')); await tester.pump(const Duration(milliseconds: 799)); expect(find.text('page b'), findsNothing); - expect(find.byType(ColoredBox), findsOneWidget); // ColoredBox only exists during animation. + ColoredBox coloredBox = tester.widget(find.byType(ColoredBox).last); + expect(coloredBox.color, isNot(Colors.transparent)); // Color is not transparent during animation. await tester.pump(const Duration(milliseconds: 801)); expect(find.text('page b'), findsOneWidget); - expect(find.byType(ColoredBox), findsNothing); + coloredBox = tester.widget(find.byType(ColoredBox).last); + expect(coloredBox.color, Colors.transparent); // Color is transparent during animation. }, variant: TargetPlatformVariant.only(TargetPlatform.android)); testWidgets('Animation duration changes accordingly when page transition builder changes', (WidgetTester tester) async { @@ -269,22 +271,29 @@ void main() { await tester.tap(find.text('push')); await tester.pump(const Duration(milliseconds: 799)); expect(find.text('page b'), findsNothing); - expect(find.byType(ColoredBox), findsOneWidget); // ColoredBox only exists during animation. + ColoredBox coloredBox = tester.widget(find.byType(ColoredBox).last); + expect(coloredBox.color, isNot(Colors.transparent)); // The color is not transparent during animation. await tester.pump(const Duration(milliseconds: 801)); expect(find.text('page b'), findsOneWidget); - expect(find.byType(ColoredBox), findsNothing); + coloredBox = tester.widget(find.byType(ColoredBox).last); + expect(coloredBox.color, Colors.transparent); // The color is transparent during animation. - await tester.pumpWidget(buildApp(const CupertinoPageTransitionsBuilder())); + await tester.pumpWidget(buildApp(const FadeUpwardsPageTransitionsBuilder())); + await tester.pumpAndSettle(); + expect(find.descendant( + of: find.byType(MaterialApp), + matching: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_FadeUpwardsPageTransition'), + ), findsOneWidget); await tester.tap(find.text('pop')); await tester.pump(const Duration(milliseconds: 299)); expect(find.text('page b'), findsOneWidget); expect(find.byType(ColoredBox), findsNothing); // ColoredBox doesn't exist in CupertinoPageTransition. await tester.pump(const Duration(milliseconds: 301)); + expect(find.text('page b'), findsNothing); expect(find.text('push'), findsOneWidget); // The first page expect(find.byType(ColoredBox), findsNothing); - }, variant: TargetPlatformVariant.only(TargetPlatform.android));