| 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:mdv/mdv.dart' as mdv; | |
| 9 import 'package:logging/logging.dart'; | 8 import 'package:logging/logging.dart'; |
| 10 import 'package:observe/observe.dart'; | 9 import 'package:observe/observe.dart'; |
| 11 import 'package:polymer_expressions/polymer_expressions.dart'; | 10 import 'package:polymer_expressions/polymer_expressions.dart'; |
| 11 import 'package:template_binding/template_binding.dart'; |
| 12 import 'package:unittest/html_enhanced_config.dart'; | 12 import 'package:unittest/html_enhanced_config.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 mdv.initialize(); | |
| 17 useHtmlEnhancedConfiguration(); | 16 useHtmlEnhancedConfiguration(); |
| 18 | 17 |
| 19 group('PolymerExpressions', () { | 18 group('PolymerExpressions', () { |
| 20 var testDiv; | 19 var testDiv; |
| 21 | 20 |
| 22 setUp(() { | 21 setUp(() { |
| 23 document.body.append(testDiv = new DivElement()); | 22 document.body.append(testDiv = new DivElement()); |
| 24 }); | 23 }); |
| 25 | 24 |
| 26 tearDown(() { | 25 tearDown(() { |
| 27 testDiv.firstChild.remove(); | 26 testDiv.firstChild.remove(); |
| 28 testDiv = null; | 27 testDiv = null; |
| 29 }); | 28 }); |
| 30 | 29 |
| 31 test('should make two-way bindings to inputs', () { | 30 test('should make two-way bindings to inputs', () { |
| 32 testDiv.nodes.add(new Element.html(''' | 31 testDiv.nodes.add(new Element.html(''' |
| 33 <template id="test" bind> | 32 <template id="test" bind> |
| 34 <input id="input" value="{{ firstName }}"> | 33 <input id="input" value="{{ firstName }}"> |
| 35 </template>''')); | 34 </template>''')); |
| 36 var person = new Person('John', 'Messerly', ['A', 'B', 'C']); | 35 var person = new Person('John', 'Messerly', ['A', 'B', 'C']); |
| 37 query('#test') | 36 templateBind(query('#test')) |
| 38 ..bindingDelegate = new PolymerExpressions() | 37 ..bindingDelegate = new PolymerExpressions() |
| 39 ..model = person; | 38 ..model = person; |
| 40 return new Future.delayed(new Duration()).then((_) { | 39 return new Future.delayed(new Duration()).then((_) { |
| 41 InputElement input = query('#input'); | 40 InputElement input = query('#input'); |
| 42 expect(input.value, 'John'); | 41 expect(input.value, 'John'); |
| 43 input.focus(); | 42 input.focus(); |
| 44 input.value = 'Justin'; | 43 input.value = 'Justin'; |
| 45 input.blur(); | 44 input.blur(); |
| 46 var event = new Event('change'); | 45 var event = new Event('change'); |
| 47 // TODO(justin): figure out how to trigger keyboard events to test | 46 // TODO(justin): figure out how to trigger keyboard events to test |
| 48 // two-way bindings | 47 // two-way bindings |
| 49 }); | 48 }); |
| 50 }); | 49 }); |
| 51 | 50 |
| 52 test('should handle null collections in "in" expressions', () { | 51 test('should handle null collections in "in" expressions', () { |
| 53 testDiv.nodes.add(new Element.html(''' | 52 testDiv.nodes.add(new Element.html(''' |
| 54 <template id="test" bind> | 53 <template id="test" bind> |
| 55 <template repeat="{{ item in items }}"> | 54 <template repeat="{{ item in items }}"> |
| 56 {{ item }} | 55 {{ item }} |
| 57 </template> | 56 </template> |
| 58 </template>''')); | 57 </template>''')); |
| 59 query('#test').bindingDelegate = | 58 templateBind(query('#test')).bindingDelegate = |
| 60 new PolymerExpressions(globals: {'items': null}); | 59 new PolymerExpressions(globals: {'items': null}); |
| 61 // the template should be the only node | 60 // the template should be the only node |
| 62 expect(testDiv.nodes.length, 1); | 61 expect(testDiv.nodes.length, 1); |
| 63 expect(testDiv.nodes[0].id, 'test'); | 62 expect(testDiv.nodes[0].id, 'test'); |
| 64 }); | 63 }); |
| 65 | 64 |
| 66 test('should silently handle bad variable names', () { | 65 test('should silently handle bad variable names', () { |
| 67 var logger = new Logger('polymer_expressions'); | 66 var logger = new Logger('polymer_expressions'); |
| 68 var logFuture = logger.onRecord.toList(); | 67 var logFuture = logger.onRecord.toList(); |
| 69 testDiv.nodes.add(new Element.html(''' | 68 testDiv.nodes.add(new Element.html(''' |
| 70 <template id="test" bind>{{ foo }}</template>''')); | 69 <template id="test" bind>{{ foo }}</template>''')); |
| 71 query('#test').bindingDelegate = new PolymerExpressions(); | 70 templateBind(query('#test')).bindingDelegate = new PolymerExpressions(); |
| 72 return new Future(() { | 71 return new Future(() { |
| 73 logger.clearListeners(); | 72 logger.clearListeners(); |
| 74 return logFuture.then((records) { | 73 return logFuture.then((records) { |
| 75 expect(records.length, 1); | 74 expect(records.length, 1); |
| 76 expect(records.first.message, | 75 expect(records.first.message, |
| 77 contains('Error evaluating expression')); | 76 contains('Error evaluating expression')); |
| 78 expect(records.first.message, contains('foo')); | 77 expect(records.first.message, contains('foo')); |
| 79 }); | 78 }); |
| 80 }); | 79 }); |
| 81 }); | 80 }); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 105 String getFullName() => '$_firstName $_lastName'; | 104 String getFullName() => '$_firstName $_lastName'; |
| 106 | 105 |
| 107 List<String> get items => _items; | 106 List<String> get items => _items; |
| 108 | 107 |
| 109 void set items(List<String> value) { | 108 void set items(List<String> value) { |
| 110 _items = notifyPropertyChange(#items, _items, value); | 109 _items = notifyPropertyChange(#items, _items, value); |
| 111 } | 110 } |
| 112 | 111 |
| 113 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; | 112 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; |
| 114 } | 113 } |
| OLD | NEW |