From 25f44bb27160f88e069daab70cf05fadf0af10b1 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 30 Sep 2020 18:02:04 -0700 Subject: [PATCH] test (#67021) --- .../flutter/test/widgets/scrollable_test.dart | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/packages/flutter/test/widgets/scrollable_test.dart b/packages/flutter/test/widgets/scrollable_test.dart index 109196037a..ef2bf39863 100644 --- a/packages/flutter/test/widgets/scrollable_test.dart +++ b/packages/flutter/test/widgets/scrollable_test.dart @@ -834,6 +834,89 @@ void main() { expect(expensiveWidgets, 0); expect(cheapWidgets, 58); }); + + testWidgets('ensureVisible does not move PageViews', (WidgetTester tester) async { + final PageController controller = PageController(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: PageView( + controller: controller, + children: List.generate( + 3, + (int pageIndex) { + return ListView( + key: Key('list_$pageIndex'), + children: List.generate( + 100, + (int listIndex) { + return Row( + children: [ + Container( + key: Key('${pageIndex}_${listIndex}_0'), + color: Colors.red, + width: 200, + height: 10, + ), + Container( + key: Key('${pageIndex}_${listIndex}_1'), + color: Colors.blue, + width: 200, + height: 10, + ), + Container( + key: Key('${pageIndex}_${listIndex}_2'), + color: Colors.green, + width: 200, + height: 10, + ), + ] + ); + } + ), + ); + } + ) + ), + ), + ); + + final Finder targetMidRightPage0 = find.byKey(const Key('0_25_2')); + final Finder targetMidRightPage1 = find.byKey(const Key('1_25_2')); + final Finder targetMidLeftPage1 = find.byKey(const Key('1_25_0')); + + expect(find.byKey(const Key('list_0')), findsOneWidget); + expect(find.byKey(const Key('list_1')), findsNothing); + expect(targetMidRightPage0, findsOneWidget); + expect(targetMidRightPage1, findsNothing); + expect(targetMidLeftPage1, findsNothing); + + await tester.ensureVisible(targetMidRightPage0); + await tester.pumpAndSettle(); + expect(targetMidRightPage0, findsOneWidget); + expect(targetMidRightPage1, findsNothing); + expect(targetMidLeftPage1, findsNothing); + + controller.jumpToPage(1); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('list_0')), findsNothing); + expect(find.byKey(const Key('list_1')), findsOneWidget); + await tester.ensureVisible(targetMidRightPage1); + await tester.pumpAndSettle(); + + expect(targetMidRightPage0, findsNothing); + expect(targetMidRightPage1, findsOneWidget); + expect(targetMidLeftPage1, findsOneWidget); + + await tester.ensureVisible(targetMidLeftPage1); + await tester.pumpAndSettle(); + + expect(targetMidRightPage0, findsNothing); + expect(targetMidRightPage1, findsOneWidget); + expect(targetMidLeftPage1, findsOneWidget); + }); } // ignore: must_be_immutable