| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:html'; | 6 import 'dart:html'; |
| 7 | 7 |
| 8 import 'package:observe/observe.dart'; | 8 import 'package:observe/observe.dart'; |
| 9 import 'package:observe/mirrors_used.dart'; // make test smaller. | 9 import 'package:observe/mirrors_used.dart'; // make test smaller. |
| 10 import 'package:polymer_expressions/polymer_expressions.dart'; | 10 import 'package:polymer_expressions/polymer_expressions.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 testDiv.firstChild.remove(); | 26 testDiv.firstChild.remove(); |
| 27 testDiv = null; | 27 testDiv = null; |
| 28 }); | 28 }); |
| 29 | 29 |
| 30 test('should make two-way bindings to inputs', () { | 30 test('should make two-way bindings to inputs', () { |
| 31 testDiv.nodes.add(new Element.html(''' | 31 testDiv.nodes.add(new Element.html(''' |
| 32 <template id="test" bind> | 32 <template id="test" bind> |
| 33 <input id="input" value="{{ firstName }}"> | 33 <input id="input" value="{{ firstName }}"> |
| 34 </template>''')); | 34 </template>''')); |
| 35 var person = new Person('John', 'Messerly', ['A', 'B', 'C']); | 35 var person = new Person('John', 'Messerly', ['A', 'B', 'C']); |
| 36 templateBind(query('#test')) | 36 templateBind(querySelector('#test')) |
| 37 ..bindingDelegate = new PolymerExpressions() | 37 ..bindingDelegate = new PolymerExpressions() |
| 38 ..model = person; | 38 ..model = person; |
| 39 return new Future(() {}).then((_) { | 39 return new Future(() {}).then((_) { |
| 40 InputElement input = query('#input'); | 40 InputElement input = querySelector('#input'); |
| 41 expect(input.value, 'John'); | 41 expect(input.value, 'John'); |
| 42 input.focus(); | 42 input.focus(); |
| 43 input.value = 'Justin'; | 43 input.value = 'Justin'; |
| 44 input.blur(); | 44 input.blur(); |
| 45 var event = new Event('change'); | 45 var event = new Event('change'); |
| 46 // TODO(justin): figure out how to trigger keyboard events to test | 46 // TODO(justin): figure out how to trigger keyboard events to test |
| 47 // two-way bindings | 47 // two-way bindings |
| 48 }); | 48 }); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test('should handle null collections in "in" expressions', () { | 51 test('should handle null collections in "in" expressions', () { |
| 52 testDiv.nodes.add(new Element.html(''' | 52 testDiv.nodes.add(new Element.html(''' |
| 53 <template id="test" bind> | 53 <template id="test" bind> |
| 54 <template repeat="{{ item in items }}"> | 54 <template repeat="{{ item in items }}"> |
| 55 {{ item }} | 55 {{ item }} |
| 56 </template> | 56 </template> |
| 57 </template>''')); | 57 </template>''')); |
| 58 templateBind(query('#test')).bindingDelegate = | 58 templateBind(querySelector('#test')).bindingDelegate = |
| 59 new PolymerExpressions(globals: {'items': null}); | 59 new PolymerExpressions(globals: {'items': null}); |
| 60 // the template should be the only node | 60 // the template should be the only node |
| 61 expect(testDiv.nodes.length, 1); | 61 expect(testDiv.nodes.length, 1); |
| 62 expect(testDiv.nodes[0].id, 'test'); | 62 expect(testDiv.nodes[0].id, 'test'); |
| 63 }); | 63 }); |
| 64 | 64 |
| 65 test('should silently handle bad variable names', () { | 65 test('should silently handle bad variable names', () { |
| 66 var completer = new Completer(); | 66 var completer = new Completer(); |
| 67 runZoned(() { | 67 runZoned(() { |
| 68 testDiv.nodes.add(new Element.html(''' | 68 testDiv.nodes.add(new Element.html(''' |
| 69 <template id="test" bind>{{ foo }}</template>''')); | 69 <template id="test" bind>{{ foo }}</template>''')); |
| 70 templateBind(query('#test')) | 70 templateBind(querySelector('#test')) |
| 71 ..bindingDelegate = new PolymerExpressions() | 71 ..bindingDelegate = new PolymerExpressions() |
| 72 ..model = []; | 72 ..model = []; |
| 73 return new Future(() {}); | 73 return new Future(() {}); |
| 74 }, onError: (e, s) { | 74 }, onError: (e, s) { |
| 75 expect('$e', contains('foo')); | 75 expect('$e', contains('foo')); |
| 76 completer.complete(true); | 76 completer.complete(true); |
| 77 }); | 77 }); |
| 78 return completer.future; | 78 return completer.future; |
| 79 }); | 79 }); |
| 80 }); | 80 }); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 103 String getFullName() => '$_firstName $_lastName'; | 103 String getFullName() => '$_firstName $_lastName'; |
| 104 | 104 |
| 105 List<String> get items => _items; | 105 List<String> get items => _items; |
| 106 | 106 |
| 107 void set items(List<String> value) { | 107 void set items(List<String> value) { |
| 108 _items = notifyPropertyChange(#items, _items, value); | 108 _items = notifyPropertyChange(#items, _items, value); |
| 109 } | 109 } |
| 110 | 110 |
| 111 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; | 111 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; |
| 112 } | 112 } |
| OLD | NEW |