Commit 8bb09dbc authored by Jim Beveridge's avatar Jim Beveridge

Added rotation test for new PageableList code.

parent 13baf51e
......@@ -41,12 +41,6 @@ class PageableListAppState extends State<PageableListApp> {
ScrollDirection scrollDirection = ScrollDirection.horizontal;
bool itemsWrap = false;
void updatePageSize(Size newSize) {
setState(() {
pageSize = newSize;
});
}
Widget buildCard(BuildContext context, CardModel cardModel, int index) {
Widget card = new Card(
color: cardModel.color,
......
......@@ -3,17 +3,19 @@
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
const Size pageSize = const Size(800.0, 600.0);
Size pageSize = new Size(600.0, 300.0);
const List<int> defaultPages = const <int>[0, 1, 2, 3, 4, 5];
final List<GlobalKey> globalKeys = defaultPages.map((_) => new GlobalKey()).toList();
int currentPage = null;
bool itemsWrap = false;
Widget buildPage(BuildContext context, int page, int index) {
return new Container(
key: new ValueKey<int>(page),
key: globalKeys[page],
width: pageSize.width,
height: pageSize.height,
child: new Text(page.toString())
......@@ -21,15 +23,20 @@ Widget buildPage(BuildContext context, int page, int index) {
}
Widget buildFrame({ List<int> pages: defaultPages }) {
// The test framework forces the frame (and so the PageableList)
// to be 800x600. The pageSize constant reflects this.
return new PageableList<int>(
final list = new PageableList<int>(
items: pages,
itemBuilder: buildPage,
itemsWrap: itemsWrap,
scrollDirection: ScrollDirection.horizontal,
onPageChanged: (int page) { currentPage = page; }
);
// The test framework forces the frame to be 800x600, so we need to create
// an outer container where we can change the size.
return new Center(
child: new Container(
width: pageSize.width, height: pageSize.height, child: list)
);
}
void page(WidgetTester tester, Offset offset) {
......@@ -57,8 +64,24 @@ void main() {
expect(currentPage, isNull);
pageLeft(tester);
expect(currentPage, equals(1));
expect(tester.findText('0'), isNull);
expect(tester.findText('1'), isNotNull);
expect(tester.findText('2'), isNull);
expect(tester.findText('3'), isNull);
expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNull);
pageRight(tester);
expect(currentPage, equals(0));
expect(tester.findText('0'), isNotNull);
expect(tester.findText('1'), isNull);
expect(tester.findText('2'), isNull);
expect(tester.findText('3'), isNull);
expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNull);
pageRight(tester);
expect(currentPage, equals(0));
});
......@@ -118,4 +141,34 @@ void main() {
});
});
test('PageableList resize parent', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Container());
currentPage = null;
itemsWrap = true;
tester.pumpWidget(buildFrame());
expect(currentPage, isNull);
pageRight(tester);
expect(currentPage, equals(5));
RenderBox box = globalKeys[5].currentContext.findRenderObject();
expect(box.size.width, equals(pageSize.width));
expect(box.size.height, equals(pageSize.height));
pageSize = new Size(pageSize.height, pageSize.width);
tester.pumpWidget(buildFrame());
expect(tester.findText('0'), isNull);
expect(tester.findText('1'), isNull);
expect(tester.findText('2'), isNull);
expect(tester.findText('3'), isNull);
expect(tester.findText('4'), isNull);
expect(tester.findText('5'), isNotNull);
box = globalKeys[5].currentContext.findRenderObject();
expect(box.size.width, equals(pageSize.width));
expect(box.size.height, equals(pageSize.height));
});
});
}
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