Merge pull request #842 from abarth/test_mimic

Add a basic test for Mimic tree movement
This commit is contained in:
Adam Barth 2015-08-25 17:26:09 -07:00
commit 31a1886a5a
2 changed files with 83 additions and 0 deletions

View File

@ -40,6 +40,15 @@ class WidgetTester {
TestApp _app;
RenderView _renderView;
void walkWidgets(WidgetTreeWalker walker) {
void walk(Widget widget) {
walker(widget);
widget.walkChildren(walk);
}
_app.walkChildren(walk);
}
void pumpFrame(WidgetBuilder builder) {
_app.builder = builder;
Component.flushBuild();

View File

@ -0,0 +1,74 @@
import 'package:sky/widgets.dart';
import 'package:test/test.dart';
import 'build_utils.dart';
void main() {
test('Mimic can track tree movements', () {
GlobalKey globalKey = new GlobalKey();
WidgetTester tester = new WidgetTester();
tester.pumpFrame(() {
return new Flex([
new Mimicable(
key: globalKey,
child: new Container(
key: new Key.stringify('inner'),
height: 10.0,
width: 10.0
)
)
]);
});
bool mimicReady = false;
tester.pumpFrame(() {
return new Flex([
new Mimicable(
key: globalKey,
child: new Container(
height: 10.0,
width: 10.0
)
),
new SizedBox(
height: 10.0,
width: 10.0,
child: new Mimic(
original: globalKey,
onMimicReady: () {
mimicReady = true;
}
)
)
]);
});
expect(mimicReady, isTrue);
tester.pumpFrame(() {
return new Flex([
new Container(
key: new Key.stringify('outer'),
height: 10.0,
width: 10.0,
child: new Mimicable(
key: globalKey,
child: new Container(
key: new Key.stringify('inner'),
height: 10.0,
width: 10.0
)
)
),
new SizedBox(
height: 10.0,
width: 10.0,
child: new Mimic(original: globalKey)
)
]);
});
});
}