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