mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Merge pull request #853 from jimbeveridge/pagetest
Added rotation test for new PageableList code.
This commit is contained in:
commit
f92cd47651
@ -41,12 +41,6 @@ class PageableListAppState extends State<PageableListApp> {
|
|||||||
ScrollDirection scrollDirection = ScrollDirection.horizontal;
|
ScrollDirection scrollDirection = ScrollDirection.horizontal;
|
||||||
bool itemsWrap = false;
|
bool itemsWrap = false;
|
||||||
|
|
||||||
void updatePageSize(Size newSize) {
|
|
||||||
setState(() {
|
|
||||||
pageSize = newSize;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildCard(BuildContext context, CardModel cardModel, int index) {
|
Widget buildCard(BuildContext context, CardModel cardModel, int index) {
|
||||||
Widget card = new Card(
|
Widget card = new Card(
|
||||||
color: cardModel.color,
|
color: cardModel.color,
|
||||||
|
@ -3,17 +3,19 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:test/test.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];
|
const List<int> defaultPages = const <int>[0, 1, 2, 3, 4, 5];
|
||||||
|
final List<GlobalKey> globalKeys = defaultPages.map((_) => new GlobalKey()).toList();
|
||||||
int currentPage = null;
|
int currentPage = null;
|
||||||
bool itemsWrap = false;
|
bool itemsWrap = false;
|
||||||
|
|
||||||
Widget buildPage(BuildContext context, int page, int index) {
|
Widget buildPage(BuildContext context, int page, int index) {
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(page),
|
key: globalKeys[page],
|
||||||
width: pageSize.width,
|
width: pageSize.width,
|
||||||
height: pageSize.height,
|
height: pageSize.height,
|
||||||
child: new Text(page.toString())
|
child: new Text(page.toString())
|
||||||
@ -21,15 +23,20 @@ Widget buildPage(BuildContext context, int page, int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildFrame({ List<int> pages: defaultPages }) {
|
Widget buildFrame({ List<int> pages: defaultPages }) {
|
||||||
// The test framework forces the frame (and so the PageableList)
|
final list = new PageableList<int>(
|
||||||
// to be 800x600. The pageSize constant reflects this.
|
|
||||||
return new PageableList<int>(
|
|
||||||
items: pages,
|
items: pages,
|
||||||
itemBuilder: buildPage,
|
itemBuilder: buildPage,
|
||||||
itemsWrap: itemsWrap,
|
itemsWrap: itemsWrap,
|
||||||
scrollDirection: ScrollDirection.horizontal,
|
scrollDirection: ScrollDirection.horizontal,
|
||||||
onPageChanged: (int page) { currentPage = page; }
|
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) {
|
void page(WidgetTester tester, Offset offset) {
|
||||||
@ -57,8 +64,24 @@ void main() {
|
|||||||
expect(currentPage, isNull);
|
expect(currentPage, isNull);
|
||||||
pageLeft(tester);
|
pageLeft(tester);
|
||||||
expect(currentPage, equals(1));
|
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);
|
pageRight(tester);
|
||||||
expect(currentPage, equals(0));
|
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);
|
pageRight(tester);
|
||||||
expect(currentPage, equals(0));
|
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));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user