Chromium Code Reviews| 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:html'; | |
| 6 import 'package:unittest/unittest.dart'; | |
| 7 import 'package:unittest/html_config.dart'; | |
| 8 import 'package:polymer/platform.dart' as Platform; | |
| 9 import 'package:polymer/polymer.dart'; | |
| 10 | |
| 11 class XFoo extends PolymerElement { | |
| 12 @observable var foo = ''; | |
| 13 @observable String baz = ''; | |
| 14 } | |
| 15 | |
| 16 class XBar extends XFoo { | |
| 17 @observable int zot = 3; | |
| 18 @observable bool zim = false; | |
| 19 @observable String str = 'str'; | |
| 20 @observable Object obj; | |
| 21 } | |
| 22 | |
| 23 class XCompose extends PolymerElement { | |
| 24 @observable bool zim = false; | |
| 25 } | |
| 26 | |
| 27 main() { | |
| 28 useHtmlConfiguration(); | |
| 29 | |
| 30 // Most tests use @CustomTag, here we test out the impertive register: | |
| 31 Polymer.register('x-foo', XFoo); | |
| 32 Polymer.register('x-bar', XBar); | |
| 33 Polymer.register('x-compose', XCompose); | |
| 34 | |
| 35 test('property attribute reflection', () { | |
| 36 var xcompose = query('x-compose').xtag; | |
| 37 var xfoo = query('x-foo').xtag; | |
| 38 xfoo.foo = 5; | |
| 39 Platform.flush(); | |
| 40 Platform.endOfMicrotask(expectAsync0(() { | |
|
blois
2013/09/27 21:40:52
Would be nice to have a Future version of endOfMic
Jennifer Messerly
2013/09/30 17:44:37
good point. I recall starting that refactoring but
| |
| 41 expect(xcompose.$['bar'].attributes.containsKey('zim'), false, | |
| 42 reason: 'attribute bound to property updates when binding is made'); | |
| 43 | |
| 44 expect('${xfoo.foo}', xfoo.attributes['foo'], | |
| 45 reason: 'attribute reflects property as string'); | |
| 46 xfoo.attributes['foo'] = '27'; | |
| 47 // TODO(jmesserly): why is JS leaving this as a String? From the code it | |
| 48 // looks like it should use the type of 5 and parse it as a number. | |
| 49 expect('${xfoo.foo}', xfoo.attributes['foo'], | |
| 50 reason: 'property reflects attribute'); | |
| 51 // | |
| 52 xfoo.baz = 'Hello'; | |
| 53 Platform.flush(); | |
| 54 Platform.endOfMicrotask(expectAsync0(() { | |
| 55 expect(xfoo.baz, xfoo.attributes['baz'], | |
| 56 reason: 'attribute reflects property'); | |
| 57 // | |
| 58 var xbar = query('x-bar').xtag; | |
| 59 // | |
| 60 xbar.foo = 'foo!'; | |
| 61 xbar.zot = 27; | |
| 62 xbar.zim = true; | |
| 63 xbar.str = 'str!'; | |
| 64 xbar.obj = {'hello': 'world'}; | |
| 65 Platform.flush(); | |
| 66 Platform.endOfMicrotask(expectAsync0(() { | |
| 67 expect(xbar.foo, xbar.attributes['foo'], | |
| 68 reason: 'inherited published property is reflected'); | |
| 69 expect('${xbar.zot}', xbar.attributes['zot'], | |
| 70 reason: 'attribute reflects property as number'); | |
| 71 expect(xbar.attributes['zim'], '', reason: | |
| 72 'attribute reflects true valued boolean property as ' | |
| 73 'having attribute'); | |
| 74 expect(xbar.str, xbar.attributes['str'], | |
| 75 reason: 'attribute reflects property as published string'); | |
| 76 expect(xbar.attributes.containsKey('obj'), false, | |
| 77 reason: 'attribute does not reflect object property'); | |
| 78 xbar.attributes['zim'] = 'false'; | |
| 79 xbar.attributes['foo'] = 'foo!!'; | |
| 80 xbar.attributes['zot'] = '54'; | |
| 81 xbar.attributes['str'] = 'str!!'; | |
| 82 xbar.attributes['obj'] = "{'hello': 'world'}"; | |
| 83 expect(xbar.foo, xbar.attributes['foo'], | |
| 84 reason: 'property reflects attribute as string'); | |
| 85 expect(xbar.zot, 54, | |
| 86 reason: 'property reflects attribute as number'); | |
| 87 expect(xbar.zim, false, | |
| 88 reason: 'property reflects attribute as boolean'); | |
| 89 expect(xbar.str, 'str!!', | |
| 90 reason: 'property reflects attribute as published string'); | |
| 91 expect(xbar.obj, {'hello': 'world'}, | |
| 92 reason: 'property reflects attribute as object'); | |
| 93 xbar.zim = false; | |
| 94 Platform.flush(); | |
| 95 Platform.endOfMicrotask(expectAsync0(() { | |
| 96 expect(xbar.attributes.containsKey('zim'), false, reason: | |
| 97 'attribute reflects false valued boolean property as NOT ' | |
| 98 'having attribute'); | |
| 99 var objAttr = xbar.attributes['obj']; | |
| 100 xbar.obj = 'hi'; | |
| 101 Platform.endOfMicrotask(expectAsync0(() { | |
| 102 expect(xbar.attributes['obj'], objAttr, reason: | |
| 103 'do not reflect property with default type of object'); | |
| 104 })); | |
| 105 })); | |
| 106 })); | |
| 107 })); | |
| 108 })); | |
| 109 }); | |
| 110 } | |
| OLD | NEW |