OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:async'; | |
6 import 'dart:html'; | |
7 import 'package:unittest/unittest.dart'; | |
8 import 'package:unittest/html_config.dart'; | |
9 import 'package:polymer/polymer.dart'; | |
10 | |
11 @CustomTag('my-child-element') | |
12 class MyChildElement extends PolymerElement { | |
13 @published int number; | |
14 @published bool boolean; | |
15 @published String string; | |
16 | |
17 MyChildElement.created() : super.created(); | |
18 } | |
19 | |
20 @CustomTag('my-element') | |
21 class MyElement extends PolymerElement { | |
22 @observable int number = 1; | |
23 @observable bool boolean = false; | |
24 @observable String string = 'a'; | |
25 | |
26 MyElement.created() : super.created(); | |
27 } | |
28 | |
29 main() => initPolymer().run(() { | |
30 useHtmlConfiguration(); | |
31 | |
32 setUp(() => Polymer.onReady); | |
33 | |
34 test('child gets initial values', () { | |
35 var parent = querySelector('my-element'); | |
36 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.
| |
37 | |
38 expect(child.number, 1); | |
39 expect(child.boolean, false); | |
40 expect(child.string, 'a'); | |
41 }); | |
42 | |
43 test('child updates the parent', () { | |
44 var parent = querySelector('my-element'); | |
45 var child = parent.shadowRoot.querySelector('my-child-element'); | |
46 | |
47 // Toggle the value in the child and make sure that propagates around. | |
48 child.number = 2; | |
49 child.boolean = true; | |
50 child.string = 'b'; | |
51 return new Future(() {}).then((_) { | |
52 expect(parent.number, 2); | |
53 expect(parent.boolean, true); | |
54 expect(parent.string, 'b'); | |
55 | |
56 child.number = 1; | |
57 child.boolean = false; | |
58 child.string = 'a'; | |
59 }).then((_) => new Future(() {})).then((_) { | |
60 expect(parent.number, 1); | |
61 expect(parent.boolean, false); | |
62 expect(parent.string, 'a'); | |
63 }); | |
64 }); | |
65 | |
66 test('parent updates the child', () { | |
67 var parent = querySelector('my-element'); | |
68 var child = parent.shadowRoot.querySelector('my-child-element'); | |
69 | |
70 // Toggle the value in the parent and make sure that propagates around. | |
71 parent.number = 2; | |
72 parent.boolean = true; | |
73 parent.string = 'b'; | |
74 return new Future(() {}).then((_) { | |
75 expect(child.number, 2); | |
76 expect(child.boolean, true); | |
77 expect(child.string, 'b'); | |
78 | |
79 parent.number = 1; | |
80 parent.boolean = false; | |
81 parent.string = 'a'; | |
82 }).then((_) => new Future(() {})).then((_) { | |
83 expect(child.number, 1); | |
84 expect(child.boolean, false); | |
85 expect(child.string, 'a'); | |
86 }); | |
87 }); | |
88 }); | |
OLD | NEW |