| 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 // Test ported from: | |
| 12 // https://github.com/Polymer/polymer-dev/blob/0.3.4/test/html/computedPropertie
s.html | |
| 13 @CustomTag('x-foo') | |
| 14 class XFoo extends PolymerElement { | |
| 15 XFoo.created() : super.created(); | |
| 16 | |
| 17 // Left like this to illustrate the old-style @published pattern next to the | |
| 18 // new style below. | |
| 19 @published int count; | |
| 20 | |
| 21 @published | |
| 22 String get foo => readValue(#foo); | |
| 23 set foo(String v) => writeValue(#foo, v); | |
| 24 | |
| 25 @published | |
| 26 String get bar => readValue(#bar); | |
| 27 set bar(String v) => writeValue(#bar, v); | |
| 28 | |
| 29 @ComputedProperty('repeat(fooBar, count)') | |
| 30 String get fooBarCounted => readValue(#fooBarCounted); | |
| 31 | |
| 32 @ComputedProperty('foo + "-" + bar') | |
| 33 String get fooBar => readValue(#fooBar); | |
| 34 | |
| 35 @ComputedProperty('this.foo') | |
| 36 String get foo2 => readValue(#foo2); | |
| 37 set foo2(v) => writeValue(#foo2, v); | |
| 38 | |
| 39 @ComputedProperty('bar + ""') | |
| 40 String get bar2 => readValue(#bar2); | |
| 41 set bar2(v) => writeValue(#bar2, v); | |
| 42 | |
| 43 repeat(String s, int count) { | |
| 44 var sb = new StringBuffer(); | |
| 45 for (var i = 0; i < count; i++) { | |
| 46 if (i > 0) sb.write(' '); | |
| 47 sb.write(s); | |
| 48 sb.write('($i)'); | |
| 49 } | |
| 50 return sb.toString(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 main() => initPolymer().then((zone) => zone.run(() { | |
| 55 useHtmlConfiguration(); | |
| 56 | |
| 57 setUp(() => Polymer.onReady); | |
| 58 | |
| 59 test('computed properties basic', () { | |
| 60 var xFoo = querySelector('x-foo'); | |
| 61 var html = xFoo.shadowRoot.innerHtml; | |
| 62 expect(html, 'mee-too:mee-too(0) mee-too(1) mee-too(2)'); | |
| 63 expect(xFoo.fooBar, 'mee-too'); | |
| 64 }); | |
| 65 | |
| 66 // Dart note: the following tests were not in the original JS test. | |
| 67 test('computed properties can be updated', () { | |
| 68 var xFoo = querySelector('x-foo'); | |
| 69 expect(xFoo.foo, 'mee'); | |
| 70 expect(xFoo.foo2, 'mee'); | |
| 71 xFoo.foo2 = 'hi'; | |
| 72 expect(xFoo.foo, 'hi'); | |
| 73 expect(xFoo.foo2, 'hi'); | |
| 74 }); | |
| 75 | |
| 76 test('only assignable expressions can be updated', () { | |
| 77 var xFoo = querySelector('x-foo'); | |
| 78 expect(xFoo.bar, 'too'); | |
| 79 expect(xFoo.bar2, 'too'); | |
| 80 xFoo.bar2 = 'hi'; | |
| 81 expect(xFoo.bar, 'too'); | |
| 82 expect(xFoo.bar2, 'too'); | |
| 83 }); | |
| 84 })); | |
| OLD | NEW |