Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: pkg/polymer_expressions/test/syntax_test.dart

Issue 207433002: Changes in polymer-expressions to prepare for codegen in polymer: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:logging/logging.dart';
9 import 'package:observe/observe.dart'; 8 import 'package:observe/observe.dart';
10 import 'package:observe/mirrors_used.dart'; // make test smaller. 9 import 'package:observe/mirrors_used.dart'; // make test smaller.
11 import 'package:polymer_expressions/polymer_expressions.dart'; 10 import 'package:polymer_expressions/polymer_expressions.dart';
12 import 'package:template_binding/template_binding.dart'; 11 import 'package:template_binding/template_binding.dart';
13 import 'package:unittest/html_config.dart'; 12 import 'package:unittest/html_config.dart';
14 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
15 14
16 main() { 15 main() {
17 useHtmlConfiguration(); 16 useHtmlConfiguration();
18 17
(...skipping 11 matching lines...) Expand all
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 templateBind(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(() {}).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 templateBind(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 completer = new Completer();
68 var logFuture = logger.onRecord.toList(); 67 runZoned(() {
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 templateBind(query('#test')) 70 templateBind(query('#test'))
72 ..bindingDelegate = new PolymerExpressions() 71 ..bindingDelegate = new PolymerExpressions()
73 ..model = []; 72 ..model = [];
74 return new Future(() { 73 return new Future(() {});
75 logger.clearListeners(); 74 }, onError: (e, s) {
76 return logFuture.then((records) { 75 expect('$e', contains('foo'));
77 expect(records.length, 1); 76 completer.complete(true);
78 expect(records.first.message,
79 contains('Error evaluating expression'));
80 expect(records.first.message, contains('foo'));
81 });
82 }); 77 });
78 return completer.future;
83 }); 79 });
84 }); 80 });
85 } 81 }
86 82
87 @reflectable 83 @reflectable
88 class Person extends ChangeNotifier { 84 class Person extends ChangeNotifier {
89 String _firstName; 85 String _firstName;
90 String _lastName; 86 String _lastName;
91 List<String> _items; 87 List<String> _items;
92 88
(...skipping 14 matching lines...) Expand all
107 String getFullName() => '$_firstName $_lastName'; 103 String getFullName() => '$_firstName $_lastName';
108 104
109 List<String> get items => _items; 105 List<String> get items => _items;
110 106
111 void set items(List<String> value) { 107 void set items(List<String> value) {
112 _items = notifyPropertyChange(#items, _items, value); 108 _items = notifyPropertyChange(#items, _items, value);
113 } 109 }
114 110
115 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)"; 111 String toString() => "Person(firstName: $_firstName, lastName: $_lastName)";
116 } 112 }
OLDNEW
« no previous file with comments | « pkg/polymer_expressions/test/eval_test.dart ('k') | pkg/polymer_expressions/test/visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698