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 library polymer.test.property_change_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:html'; |
| 9 import 'package:polymer/polymer.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:unittest/html_config.dart'; |
| 12 |
| 13 var _changes = 0; |
| 14 final _done = new Completer(); |
| 15 |
| 16 checkDone() { |
| 17 if (6 == ++_changes) { |
| 18 _done.complete(); |
| 19 } |
| 20 } |
| 21 |
| 22 @CustomTag('x-test') |
| 23 class XTest extends PolymerElement { |
| 24 @observable String bar = ''; |
| 25 @observable String pie; |
| 26 @observable Map a; |
| 27 |
| 28 XTest.created() : super.created(); |
| 29 |
| 30 ready() { |
| 31 bar = 'bar'; |
| 32 pie = 'pie'; |
| 33 a = {'b': {'c': 'exists'}}; |
| 34 } |
| 35 |
| 36 barChanged() { |
| 37 // Dart note: unlike polymer-js we support multiple observers, due to how |
| 38 // our @ObserveProperty metadata translated. |
| 39 // _done.completeError('barChanged should not be called.'); |
| 40 expect('bar', 'bar', reason: 'barChanged called'); |
| 41 checkDone(); |
| 42 } |
| 43 |
| 44 @ObserveProperty('bar pie') |
| 45 validate() { |
| 46 window.console.log('validate'); |
| 47 expect('bar', 'bar', reason: 'custom change observer called'); |
| 48 expect('pie', 'pie', reason: 'custom change observer called'); |
| 49 checkDone(); |
| 50 } |
| 51 |
| 52 // Dart note: test that we can observe "pie" twice. |
| 53 @ObserveProperty('pie') |
| 54 validateYummyPie() { |
| 55 window.console.log('validateYummyPie'); |
| 56 expect('pie', 'pie', reason: 'validateYummyPie called'); |
| 57 checkDone(); |
| 58 } |
| 59 |
| 60 @ObserveProperty('a.b.c') |
| 61 validateSubPath(oldValue, newValue) { |
| 62 window.console.log('validateSubPath $oldValue $newValue'); |
| 63 expect(newValue, 'exists', reason: 'subpath change observer called'); |
| 64 checkDone(); |
| 65 } |
| 66 } |
| 67 |
| 68 @CustomTag('x-test2') |
| 69 class XTest2 extends XTest { |
| 70 @observable String noogle; |
| 71 |
| 72 XTest2.created() : super.created(); |
| 73 |
| 74 @ObserveProperty('noogle') |
| 75 validate() => super.validate(); |
| 76 |
| 77 ready() { |
| 78 super.ready(); |
| 79 noogle = 'noogle'; |
| 80 } |
| 81 } |
| 82 |
| 83 main() => initPolymer().then((zone) => zone.run(() { |
| 84 useHtmlConfiguration(); |
| 85 |
| 86 setUp(() => Polymer.onReady); |
| 87 |
| 88 test('changes detected', () => _done.future); |
| 89 })); |
OLD | NEW |