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

Side by Side Diff: pkg/template_binding/test/node_bind_test.dart

Issue 50203004: port TemplateBinding to ed3266266e751b5ab1f75f8e0509d0d5f0ef35d8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 library template_binding.test.node_bindings_test; 5 library template_binding.test.node_bind_test;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 @MirrorsUsed(targets: const [NodeBinding], override: 9 import 'package:observe/observe.dart' show toObservable, PathObserver;
10 'template_binding.test.node_bindings_test') 10 import 'package:template_binding/template_binding.dart' show nodeBind;
11 import 'dart:mirrors'; 11 import 'package:template_binding/src/node_binding.dart' show getObserverForTest;
12 12
13 import 'package:observe/observe.dart' show toObservable, PathObserver;
14 import 'package:template_binding/template_binding.dart'
15 show nodeBind, NodeBinding;
16 import 'package:unittest/html_config.dart'; 13 import 'package:unittest/html_config.dart';
17 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
18 import 'utils.dart'; 15 import 'utils.dart';
19 16
20 // Note: this file ported from 17 // Note: this file ported from
21 // https://github.com/toolkitchen/mdv/blob/master/tests/node_bindings.js 18 // https://github.com/toolkitchen/mdv/blob/master/tests/node_bindings.js
22 19
23 main() { 20 main() {
24 useHtmlConfiguration(); 21 useHtmlConfiguration();
25 22
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }); 62 });
66 63
67 observeTest('Path unreachable', () { 64 observeTest('Path unreachable', () {
68 var text = testDiv.append(new Text('hi')); 65 var text = testDiv.append(new Text('hi'));
69 var model = 1; 66 var model = 1;
70 nodeBind(text).bind('text', model, 'a'); 67 nodeBind(text).bind('text', model, 'a');
71 expect(text.text, ''); 68 expect(text.text, '');
72 }); 69 });
73 70
74 observeTest('Observer is Model', () { 71 observeTest('Observer is Model', () {
75 _observer(x) => reflect(x).getField(
76 privateSymbol(NodeBinding, '_observer')).reflectee;
77
78 var text = new Text(''); 72 var text = new Text('');
79 var model = toObservable({'a': {'b': {'c': 1}}}); 73 var model = toObservable({'a': {'b': {'c': 1}}});
80 var observer = new PathObserver(model, 'a.b.c'); 74 var observer = new PathObserver(model, 'a.b.c');
81 nodeBind(text).bind('text', observer, 'value'); 75 nodeBind(text).bind('text', observer, 'value');
82 expect(text.text, '1'); 76 expect(text.text, '1');
83 77
84 var binding = nodeBind(text).bindings['text']; 78 var binding = nodeBind(text).bindings['text'];
85 expect(binding, isNotNull); 79 expect(binding, isNotNull);
86 expect(privateField(binding, '_observer'), observer, 80 expect(getObserverForTest(binding), observer,
87 reason: 'should reuse observer'); 81 reason: 'should reuse observer');
88 82
89 model['a']['b']['c'] = 2; 83 model['a']['b']['c'] = 2;
90 performMicrotaskCheckpoint(); 84 performMicrotaskCheckpoint();
91 expect(text.text, '2'); 85 expect(text.text, '2');
92 nodeBind(text).unbind('text'); 86 nodeBind(text).unbind('text');
93 }); 87 });
94 } 88 }
95 89
96 elementBindings() { 90 elementBindings() {
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 model['opt2'] = 'X'; 641 model['opt2'] = 'X';
648 performMicrotaskCheckpoint(); 642 performMicrotaskCheckpoint();
649 expect(select.value, 'X'); 643 expect(select.value, 'X');
650 expect(model['selected'], 'X'); 644 expect(model['selected'], 'X');
651 645
652 model['selected'] = 'a'; 646 model['selected'] = 'a';
653 performMicrotaskCheckpoint(); 647 performMicrotaskCheckpoint();
654 expect(select.value, 'a'); 648 expect(select.value, 'a');
655 }); 649 });
656 } 650 }
657
658 privateField(x, name) => reflect(x).getField(
659 privateSymbol(reflect(x).type, name)).reflectee;
660
661 // TODO(jmesserly): fix this when it's easier to get a private symbol.
662 privateSymbol(TypeMirror type, String name) {
663 while (type != null) {
664 var symbol = type.variables.keys.firstWhere(
665 (s) => MirrorSystem.getName(s) == name, orElse: () => null);
666 if (symbol != null) return symbol;
667 type = type.superclass;
668 }
669 return null;
670 }
OLDNEW
« no previous file with comments | « pkg/template_binding/test/custom_element_bindings_test.dart ('k') | pkg/template_binding/test/node_bindings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698