Chromium Code Reviews| 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..72098f7bc14040c5562dd50d9aba729cc1eb095e |
| --- /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 { |
| + @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 parent = querySelector('my-element'); |
| + var child = parent.shadowRoot.querySelector('my-child-element'); |
|
Siggi Cherem (dart-lang)
2014/07/09 16:55:49
sometimes parent/child confuses me because I think
jakemac
2014/07/09 17:42:16
Done.
|
| + |
| + expect(child.number, 1); |
| + expect(child.boolean, false); |
| + expect(child.string, 'a'); |
| + }); |
| + |
| + test('child updates the parent', () { |
| + var parent = querySelector('my-element'); |
| + var child = parent.shadowRoot.querySelector('my-child-element'); |
| + |
| + // Toggle the value in the child and make sure that propagates around. |
| + child.number = 2; |
| + child.boolean = true; |
| + child.string = 'b'; |
| + return new Future(() {}).then((_) { |
| + expect(parent.number, 2); |
| + expect(parent.boolean, true); |
| + expect(parent.string, 'b'); |
| + |
| + child.number = 1; |
| + child.boolean = false; |
| + child.string = 'a'; |
| + }).then((_) => new Future(() {})).then((_) { |
| + expect(parent.number, 1); |
| + expect(parent.boolean, false); |
| + expect(parent.string, 'a'); |
| + }); |
| + }); |
| + |
| + test('parent updates the child', () { |
| + var parent = querySelector('my-element'); |
| + var child = parent.shadowRoot.querySelector('my-child-element'); |
| + |
| + // Toggle the value in the parent and make sure that propagates around. |
| + parent.number = 2; |
| + parent.boolean = true; |
| + parent.string = 'b'; |
| + return new Future(() {}).then((_) { |
| + expect(child.number, 2); |
| + expect(child.boolean, true); |
| + expect(child.string, 'b'); |
| + |
| + parent.number = 1; |
| + parent.boolean = false; |
| + parent.string = 'a'; |
| + }).then((_) => new Future(() {})).then((_) { |
| + expect(child.number, 1); |
| + expect(child.boolean, false); |
| + expect(child.string, 'a'); |
| + }); |
| + }); |
| +}); |