Index: pkg/polymer/test/two_way_bind_test.dart |
diff --git a/pkg/polymer/test/two_way_bind_test.dart b/pkg/polymer/test/two_way_bind_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c4a052e30b060ff3f474bb027acb60c637ec5ec7 |
--- /dev/null |
+++ b/pkg/polymer/test/two_way_bind_test.dart |
@@ -0,0 +1,88 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'dart:async'; |
+import 'dart:html'; |
+import 'package:unittest/unittest.dart'; |
+import 'package:unittest/html_config.dart'; |
+import 'package:polymer/polymer.dart'; |
+ |
+@CustomTag('my-child-element') |
+class MyChildElement extends PolymerElement { |
Siggi Cherem (dart-lang)
2014/07/09 17:53:06
maybe the type and element names too?
jakemac
2014/07/09 18:24:47
Done.
|
+ @published int number; |
+ @published bool boolean; |
+ @published String string; |
+ |
+ MyChildElement.created() : super.created(); |
+} |
+ |
+@CustomTag('my-element') |
+class MyElement extends PolymerElement { |
+ @observable int number = 1; |
+ @observable bool boolean = false; |
+ @observable String string = 'a'; |
+ |
+ MyElement.created() : super.created(); |
+} |
+ |
+main() => initPolymer().run(() { |
+ useHtmlConfiguration(); |
+ |
+ setUp(() => Polymer.onReady); |
+ |
+ test('child gets initial values', () { |
+ var outer = querySelector('my-element'); |
+ var inner = outer.shadowRoot.querySelector('my-child-element'); |
+ |
+ expect(inner.number, 1); |
+ expect(inner.boolean, false); |
+ expect(inner.string, 'a'); |
+ }); |
+ |
+ test('child updates the parent', () { |
+ var outer = querySelector('my-element'); |
+ var inner = outer.shadowRoot.querySelector('my-child-element'); |
+ |
+ // Toggle the value in the child and make sure that propagates around. |
+ inner.number = 2; |
+ inner.boolean = true; |
+ inner.string = 'b'; |
+ return new Future(() {}).then((_) { |
+ expect(outer.number, 2); |
+ expect(outer.boolean, true); |
+ expect(outer.string, 'b'); |
+ |
+ inner.number = 1; |
+ inner.boolean = false; |
+ inner.string = 'a'; |
+ }).then((_) => new Future(() {})).then((_) { |
+ expect(outer.number, 1); |
+ expect(outer.boolean, false); |
+ expect(outer.string, 'a'); |
+ }); |
+ }); |
+ |
+ test('parent updates the child', () { |
+ var outer = querySelector('my-element'); |
+ var inner = outer.shadowRoot.querySelector('my-child-element'); |
+ |
+ // Toggle the value in the parent and make sure that propagates around. |
+ outer.number = 2; |
+ outer.boolean = true; |
+ outer.string = 'b'; |
+ return new Future(() {}).then((_) { |
+ expect(inner.number, 2); |
+ expect(inner.boolean, true); |
+ expect(inner.string, 'b'); |
+ |
+ outer.number = 1; |
+ outer.boolean = false; |
+ outer.string = 'a'; |
+ }).then((_) => new Future(() {})).then((_) { |
+ expect(inner.number, 1); |
+ expect(inner.boolean, false); |
+ expect(inner.string, 'a'); |
+ }); |
+ }); |
+}); |