Unverified Commit b6c56fde authored by Dan Field's avatar Dan Field Committed by GitHub

Add test for TabBarView (#67799)

parent 6219b308
......@@ -7,10 +7,12 @@
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Future<void> pumpTest(
WidgetTester tester,
......@@ -917,6 +919,93 @@ void main() {
expect(targetMidRightPage1, findsOneWidget);
expect(targetMidLeftPage1, findsOneWidget);
});
testWidgets('ensureVisible does not move TabViews', (WidgetTester tester) async {
final TickerProvider vsync = TestTickerProvider();
final TabController controller = TabController(
length: 3,
vsync: vsync,
);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: TabBarView(
controller: controller,
children: List<ListView>.generate(
3,
(int pageIndex) {
return ListView(
key: Key('list_$pageIndex'),
children: List<Widget>.generate(
100,
(int listIndex) {
return Row(
children: <Widget>[
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.index = 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
......@@ -950,3 +1039,10 @@ class ExtraSuperPessimisticScrollPhysics extends ScrollPhysics {
return ExtraSuperPessimisticScrollPhysics(parent: buildParent(ancestor));
}
}
class TestTickerProvider extends TickerProvider {
@override
Ticker createTicker(TickerCallback onTick) {
return Ticker(onTick);
}
}
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