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 |
11 class XFoo extends PolymerElement { | 19 class XFoo extends PolymerElement { |
12 XFoo.created() : super.created(); | 20 XFoo.created() : super.created(); |
13 | 21 |
14 @PublishedProperty(reflect: true) var foo = ''; | 22 @PublishedProperty(reflect: true) var foo = ''; |
15 @PublishedProperty(reflect: true) String baz = ''; | 23 @PublishedProperty(reflect: true) String baz = ''; |
16 | 24 |
17 @PublishedProperty(reflect: true) var def1, def2; | 25 @PublishedProperty(reflect: true) var def1, def2; |
18 } | 26 } |
19 | 27 |
20 class XBar extends XFoo { | 28 class XBar extends XFoo { |
(...skipping 28 matching lines...) Expand all Loading... |
49 observer.disconnect(); | 57 observer.disconnect(); |
50 completer.complete(); | 58 completer.complete(); |
51 })..observe(node, attributes: true); | 59 })..observe(node, attributes: true); |
52 scheduleMicrotask(Observable.dirtyCheck); | 60 scheduleMicrotask(Observable.dirtyCheck); |
53 return completer.future; | 61 return completer.future; |
54 } | 62 } |
55 | 63 |
56 main() => initPolymer().run(() { | 64 main() => initPolymer().run(() { |
57 useHtmlConfiguration(); | 65 useHtmlConfiguration(); |
58 | 66 |
59 setUp(() => Polymer.onReady); | |
60 | |
61 // Most tests use @CustomTag, here we test out the impertive register: | 67 // Most tests use @CustomTag, here we test out the impertive register: |
62 Polymer.register('x-foo', XFoo); | 68 Polymer.register('x-foo', XFoo); |
63 Polymer.register('x-bar', XBar); | 69 Polymer.register('x-bar', XBar); |
64 Polymer.register('x-zot', XZot); | 70 Polymer.register('x-zot', XZot); |
65 Polymer.register('x-compose', XCompose); | 71 Polymer.register('x-compose', XCompose); |
| 72 Polymer.register('x-attr-publish', XAttrPublish); |
| 73 |
| 74 setUp(() => Polymer.onReady); |
66 | 75 |
67 test('property to attribute reflection', () { | 76 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 |
68 var xcompose = querySelector('x-compose'); | 91 var xcompose = querySelector('x-compose'); |
69 var xfoo = querySelector('x-foo'); | 92 var xfoo = querySelector('x-foo'); |
| 93 expect(xfoo.foo, '', reason: |
| 94 'property published with info object has correct initial value'); |
70 var xbar = querySelector('x-bar'); | 95 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'); |
71 var xzot = querySelector('x-zot'); | 100 var xzot = querySelector('x-zot'); |
72 xfoo.foo = 5; | 101 xfoo.foo = 5; |
73 xfoo.attributes['def1'] = '15'; | 102 xfoo.attributes['def1'] = '15'; |
74 xfoo.def2 = 15; | 103 xfoo.def2 = 15; |
75 | 104 |
76 // Dart note: our test here is more async than JS until we change | 105 // Dart note: our test here is more async than JS until we change |
77 // Polymer.dart bindings to work like observe.js "bindToInstance". | 106 // Polymer.dart bindings to work like observe.js "bindToInstance". |
78 return onAttributeChange(xfoo).then((_) { | 107 return onAttributeChange(xfoo).then((_) { |
79 expect(xcompose.$['bar'].attributes.containsKey('zim'), false, | 108 expect(xcompose.$['bar'].attributes.containsKey('zim'), false, |
80 reason: 'attribute bound to property updates when binding is made'); | 109 reason: 'attribute bound to property updates when binding is made'); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 xzot.zot = 5; | 175 xzot.zot = 5; |
147 }).then((_) => onAttributeChange(xzot)).then((_) { | 176 }).then((_) => onAttributeChange(xzot)).then((_) { |
148 expect(xzot.attributes['str'], xzot.str); | 177 expect(xzot.attributes['str'], xzot.str); |
149 // TODO(jmesserly): the JS test seems backwards of the description text. | 178 // TODO(jmesserly): the JS test seems backwards of the description text. |
150 // Is it because it doesn't do "Platform.flush()"? | 179 // Is it because it doesn't do "Platform.flush()"? |
151 expect(xzot.attributes['zot'], '5', | 180 expect(xzot.attributes['zot'], '5', |
152 reason: 'extendee reflect false not honored'); | 181 reason: 'extendee reflect false not honored'); |
153 }); | 182 }); |
154 }); | 183 }); |
155 }); | 184 }); |
OLD | NEW |