| 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 |
| 8 import 'package:polymer_expression/syntax.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 import 'package:unittest/html_enhanced_config.dart'; |
| 11 import 'package:observe/observe.dart'; |
| 12 import 'package:mdv/mdv.dart' as mdv; |
| 13 |
| 14 main() { |
| 15 mdv.initialize(); |
| 16 useHtmlEnhancedConfiguration(); |
| 17 |
| 18 group('syntax', () { |
| 19 setUp(() { |
| 20 document.body.nodes.add(new Element.html(''' |
| 21 <template id="test" bind> |
| 22 <input id="input" value="{{ firstName }}"> |
| 23 </template>''')); |
| 24 }); |
| 25 |
| 26 tearDown(() { |
| 27 query('#test')..unbindAll()..remove(); |
| 28 }); |
| 29 |
| 30 test('should make two-way bindings to inputs', () { |
| 31 var person = new Person('John', 'Messerly', ['A', 'B', 'C']); |
| 32 query('#test') |
| 33 ..bindingDelegate = new PolymerExpressions() |
| 34 ..model = person; |
| 35 return new Future.delayed(new Duration()).then((_) { |
| 36 InputElement input = query('#input'); |
| 37 expect(input.value, 'John'); |
| 38 input.focus(); |
| 39 input.value = 'Justin'; |
| 40 input.blur(); |
| 41 var event = new Event('change'); |
| 42 // TODO(justin): figure out how to trigger keyboard events to test |
| 43 // two-way bindings |
| 44 }); |
| 45 }); |
| 46 |
| 47 }); |
| 48 } |
| 49 |
| 50 class Person extends Object with ChangeNotifierMixin { |
| 51 static const _FIRST_NAME = const Symbol('firstName'); |
| 52 static const _LAST_NAME = const Symbol('lastName'); |
| 53 static const _ITEMS = const Symbol('items'); |
| 54 static const _GET_FULL_NAME = const Symbol('getFullName'); |
| 55 |
| 56 String _firstName; |
| 57 String _lastName; |
| 58 List<String> _items; |
| 59 |
| 60 Person(this._firstName, this._lastName, this._items); |
| 61 |
| 62 String get firstName => _firstName; |
| 63 |
| 64 void set firstName(String value) { |
| 65 _firstName = value; |
| 66 notifyChange(new PropertyChangeRecord(_FIRST_NAME)); |
| 67 } |
| 68 |
| 69 String get lastName => _lastName; |
| 70 |
| 71 void set lastName(String value) { |
| 72 _lastName = value; |
| 73 notifyChange(new PropertyChangeRecord(_LAST_NAME)); |
| 74 } |
| 75 |
| 76 String getFullName() => '$_firstName $_lastName'; |
| 77 |
| 78 List<String> get items => _items; |
| 79 |
| 80 void set items(List<String> value) { |
| 81 _items = value; |
| 82 notifyChange(new PropertyChangeRecord(_ITEMS)); |
| 83 } |
| 84 |
| 85 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; |
| 86 |
| 87 } |
| OLD | NEW |