OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:html'; | 6 import 'dart:html'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'package:unittest/html_config.dart'; | 8 import 'package:unittest/html_config.dart'; |
9 import 'package:polymer/polymer.dart'; | 9 import 'package:polymer/polymer.dart'; |
10 | 10 |
11 | |
12 class XAttrPublish extends PolymerElement { | |
13 XAttrPublish.created() : super.created(); | |
14 | |
15 @PublishedProperty(reflect: false) | |
16 String nog = ''; | |
17 } | |
18 | |
19 class XFoo extends PolymerElement { | 11 class XFoo extends PolymerElement { |
20 XFoo.created() : super.created(); | 12 XFoo.created() : super.created(); |
21 | 13 |
22 @PublishedProperty(reflect: true) var foo = ''; | 14 @PublishedProperty(reflect: true) var foo = ''; |
23 @PublishedProperty(reflect: true) String baz = ''; | 15 @PublishedProperty(reflect: true) String baz = ''; |
24 | 16 |
25 @PublishedProperty(reflect: true) var def1, def2; | 17 @PublishedProperty(reflect: true) var def1, def2; |
26 } | 18 } |
27 | 19 |
28 class XBar extends XFoo { | 20 class XBar extends XFoo { |
(...skipping 28 matching lines...) Expand all Loading... |
57 observer.disconnect(); | 49 observer.disconnect(); |
58 completer.complete(); | 50 completer.complete(); |
59 })..observe(node, attributes: true); | 51 })..observe(node, attributes: true); |
60 scheduleMicrotask(Observable.dirtyCheck); | 52 scheduleMicrotask(Observable.dirtyCheck); |
61 return completer.future; | 53 return completer.future; |
62 } | 54 } |
63 | 55 |
64 main() => initPolymer().run(() { | 56 main() => initPolymer().run(() { |
65 useHtmlConfiguration(); | 57 useHtmlConfiguration(); |
66 | 58 |
| 59 setUp(() => Polymer.onReady); |
| 60 |
67 // Most tests use @CustomTag, here we test out the impertive register: | 61 // Most tests use @CustomTag, here we test out the impertive register: |
68 Polymer.register('x-foo', XFoo); | 62 Polymer.register('x-foo', XFoo); |
69 Polymer.register('x-bar', XBar); | 63 Polymer.register('x-bar', XBar); |
70 Polymer.register('x-zot', XZot); | 64 Polymer.register('x-zot', XZot); |
71 Polymer.register('x-compose', XCompose); | 65 Polymer.register('x-compose', XCompose); |
72 Polymer.register('x-attr-publish', XAttrPublish); | |
73 | |
74 setUp(() => Polymer.onReady); | |
75 | 66 |
76 test('property to attribute reflection', () { | 67 test('property to attribute reflection', () { |
77 var xbasic = querySelector('x-basic'); | |
78 expect(xbasic.getAttribute('nog'), null, reason: | |
79 'property published with `attributes` has correct initial value'); | |
80 xbasic.setAttribute('nog', 'hi'); | |
81 expect(xbasic.getAttribute('nog'), 'hi', reason: | |
82 'deserialization of property published via `attributes`'); | |
83 | |
84 var xattrpublish = querySelector('x-attr-publish'); | |
85 expect(xattrpublish.nog, '', reason: | |
86 'property published with `attributes` has correct initial value'); | |
87 xattrpublish.setAttribute('nog', 'hi'); | |
88 expect(xattrpublish.nog, 'hi', reason: | |
89 'deserialization of property published via `attributes`'); | |
90 | |
91 var xcompose = querySelector('x-compose'); | 68 var xcompose = querySelector('x-compose'); |
92 var xfoo = querySelector('x-foo'); | 69 var xfoo = querySelector('x-foo'); |
93 expect(xfoo.foo, '', reason: | |
94 'property published with info object has correct initial value'); | |
95 var xbar = querySelector('x-bar'); | 70 var xbar = querySelector('x-bar'); |
96 expect(xbar.zim, false, reason: | |
97 'property published with info object has correct initial value'); | |
98 expect(xbar.foo, '', reason: | |
99 'property published with info object has correct initial value'); | |
100 var xzot = querySelector('x-zot'); | 71 var xzot = querySelector('x-zot'); |
101 xfoo.foo = 5; | 72 xfoo.foo = 5; |
102 xfoo.attributes['def1'] = '15'; | 73 xfoo.attributes['def1'] = '15'; |
103 xfoo.def2 = 15; | 74 xfoo.def2 = 15; |
104 | 75 |
105 // Dart note: our test here is more async than JS until we change | 76 // Dart note: our test here is more async than JS until we change |
106 // Polymer.dart bindings to work like observe.js "bindToInstance". | 77 // Polymer.dart bindings to work like observe.js "bindToInstance". |
107 return onAttributeChange(xfoo).then((_) { | 78 return onAttributeChange(xfoo).then((_) { |
108 expect(xcompose.$['bar'].attributes.containsKey('zim'), false, | 79 expect(xcompose.$['bar'].attributes.containsKey('zim'), false, |
109 reason: 'attribute bound to property updates when binding is made'); | 80 reason: 'attribute bound to property updates when binding is made'); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 xzot.zot = 5; | 146 xzot.zot = 5; |
176 }).then((_) => onAttributeChange(xzot)).then((_) { | 147 }).then((_) => onAttributeChange(xzot)).then((_) { |
177 expect(xzot.attributes['str'], xzot.str); | 148 expect(xzot.attributes['str'], xzot.str); |
178 // TODO(jmesserly): the JS test seems backwards of the description text. | 149 // TODO(jmesserly): the JS test seems backwards of the description text. |
179 // Is it because it doesn't do "Platform.flush()"? | 150 // Is it because it doesn't do "Platform.flush()"? |
180 expect(xzot.attributes['zot'], '5', | 151 expect(xzot.attributes['zot'], '5', |
181 reason: 'extendee reflect false not honored'); | 152 reason: 'extendee reflect false not honored'); |
182 }); | 153 }); |
183 }); | 154 }); |
184 }); | 155 }); |
OLD | NEW |