From f44e4c0615d48337b4e003f5ce37a3fc73668697 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 25 Aug 2015 16:50:44 -0700 Subject: [PATCH] Add a basic test for Mimic tree movement --- sky/unit/test/widget/build_utils.dart | 9 ++++ sky/unit/test/widget/mimic_test.dart | 74 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 sky/unit/test/widget/mimic_test.dart diff --git a/sky/unit/test/widget/build_utils.dart b/sky/unit/test/widget/build_utils.dart index 3ef1bdb532f..c5b2b635ed2 100644 --- a/sky/unit/test/widget/build_utils.dart +++ b/sky/unit/test/widget/build_utils.dart @@ -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(); diff --git a/sky/unit/test/widget/mimic_test.dart b/sky/unit/test/widget/mimic_test.dart new file mode 100644 index 00000000000..50834e7d874 --- /dev/null +++ b/sky/unit/test/widget/mimic_test.dart @@ -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) + ) + ]); + }); + + }); +}