| 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 library custom_element_bindings_test; | 5 library custom_element_bindings_test; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'package:mdv/mdv.dart' as mdv; | 8 import 'package:mdv/mdv.dart' as mdv; |
| 9 import 'package:unittest/html_config.dart'; | 9 import 'package:unittest/html_config.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'mdv_test_utils.dart'; | 11 import 'mdv_test_utils.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 mdv.initialize(); | 14 mdv.initialize(); |
| 15 useHtmlConfiguration(); | 15 useHtmlConfiguration(); |
| 16 group('Custom Element Bindings', customElementBindingsTest); | 16 group('Custom Element Bindings', customElementBindingsTest); |
| 17 } | 17 } |
| 18 | 18 |
| 19 sym(x) => new Symbol(x); | |
| 20 | |
| 21 customElementBindingsTest() { | 19 customElementBindingsTest() { |
| 22 var testDiv; | 20 var testDiv; |
| 23 | 21 |
| 24 setUp(() { | 22 setUp(() { |
| 25 document.body.append(testDiv = new DivElement()); | 23 document.body.append(testDiv = new DivElement()); |
| 26 }); | 24 }); |
| 27 | 25 |
| 28 tearDown(() { | 26 tearDown(() { |
| 29 testDiv.remove(); | 27 testDiv.remove(); |
| 30 testDiv = null; | 28 testDiv = null; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 46 observeTest('override bind/unbind/unbindAll', () { | 44 observeTest('override bind/unbind/unbindAll', () { |
| 47 var element = new MyCustomElement(); | 45 var element = new MyCustomElement(); |
| 48 var model = toSymbolMap({'a': new Point(123, 444), 'b': new Monster(100)}); | 46 var model = toSymbolMap({'a': new Point(123, 444), 'b': new Monster(100)}); |
| 49 | 47 |
| 50 element.bind('my-point', model, 'a'); | 48 element.bind('my-point', model, 'a'); |
| 51 element.bind('scary-monster', model, 'b'); | 49 element.bind('scary-monster', model, 'b'); |
| 52 | 50 |
| 53 expect(element.attributes, isNot(contains('my-point'))); | 51 expect(element.attributes, isNot(contains('my-point'))); |
| 54 expect(element.attributes, isNot(contains('scary-monster'))); | 52 expect(element.attributes, isNot(contains('scary-monster'))); |
| 55 | 53 |
| 56 expect(element.myPoint, model[sym('a')]); | 54 expect(element.myPoint, model[#a]); |
| 57 expect(element.scaryMonster, model[sym('b')]); | 55 expect(element.scaryMonster, model[#b]); |
| 58 | 56 |
| 59 model[sym('a')] = null; | 57 model[#a] = null; |
| 60 performMicrotaskCheckpoint(); | 58 performMicrotaskCheckpoint(); |
| 61 expect(element.myPoint, null); | 59 expect(element.myPoint, null); |
| 62 element.unbind('my-point'); | 60 element.unbind('my-point'); |
| 63 | 61 |
| 64 model[sym('a')] = new Point(1, 2); | 62 model[#a] = new Point(1, 2); |
| 65 model[sym('b')] = new Monster(200); | 63 model[#b] = new Monster(200); |
| 66 performMicrotaskCheckpoint(); | 64 performMicrotaskCheckpoint(); |
| 67 expect(element.scaryMonster, model[sym('b')]); | 65 expect(element.scaryMonster, model[#b]); |
| 68 expect(element.myPoint, null, reason: 'a was unbound'); | 66 expect(element.myPoint, null, reason: 'a was unbound'); |
| 69 | 67 |
| 70 element.unbindAll(); | 68 element.unbindAll(); |
| 71 model[sym('b')] = null; | 69 model[#b] = null; |
| 72 performMicrotaskCheckpoint(); | 70 performMicrotaskCheckpoint(); |
| 73 expect(element.scaryMonster.health, 200); | 71 expect(element.scaryMonster.health, 200); |
| 74 }); | 72 }); |
| 75 | 73 |
| 76 observeTest('override attribute setter', () { | 74 observeTest('override attribute setter', () { |
| 77 var element = new WithAttrsCustomElement().real; | 75 var element = new WithAttrsCustomElement().real; |
| 78 var model = toSymbolMap({'a': 1, 'b': 2}); | 76 var model = toSymbolMap({'a': 1, 'b': 2}); |
| 79 element.bind('hidden?', model, 'a'); | 77 element.bind('hidden?', model, 'a'); |
| 80 element.bind('id', model, 'b'); | 78 element.bind('id', model, 'b'); |
| 81 | 79 |
| 82 expect(element.attributes, contains('hidden')); | 80 expect(element.attributes, contains('hidden')); |
| 83 expect(element.attributes['hidden'], ''); | 81 expect(element.attributes['hidden'], ''); |
| 84 expect(element.id, '2'); | 82 expect(element.id, '2'); |
| 85 | 83 |
| 86 model[sym('a')] = null; | 84 model[#a] = null; |
| 87 performMicrotaskCheckpoint(); | 85 performMicrotaskCheckpoint(); |
| 88 expect(element.attributes, isNot(contains('hidden')), | 86 expect(element.attributes, isNot(contains('hidden')), |
| 89 reason: 'null is false-y'); | 87 reason: 'null is false-y'); |
| 90 | 88 |
| 91 model[sym('a')] = false; | 89 model[#a] = false; |
| 92 performMicrotaskCheckpoint(); | 90 performMicrotaskCheckpoint(); |
| 93 expect(element.attributes, isNot(contains('hidden'))); | 91 expect(element.attributes, isNot(contains('hidden'))); |
| 94 | 92 |
| 95 model[sym('a')] = 'foo'; | 93 model[#a] = 'foo'; |
| 96 // TODO(jmesserly): this is here to force an ordering between the two | 94 // TODO(jmesserly): this is here to force an ordering between the two |
| 97 // changes. Otherwise the order depends on what order StreamController | 95 // changes. Otherwise the order depends on what order StreamController |
| 98 // chooses to fire the two listeners in. | 96 // chooses to fire the two listeners in. |
| 99 performMicrotaskCheckpoint(); | 97 performMicrotaskCheckpoint(); |
| 100 | 98 |
| 101 model[sym('b')] = 'x'; | 99 model[#b] = 'x'; |
| 102 performMicrotaskCheckpoint(); | 100 performMicrotaskCheckpoint(); |
| 103 expect(element.attributes, contains('hidden')); | 101 expect(element.attributes, contains('hidden')); |
| 104 expect(element.attributes['hidden'], ''); | 102 expect(element.attributes['hidden'], ''); |
| 105 expect(element.id, 'x'); | 103 expect(element.id, 'x'); |
| 106 | 104 |
| 107 expect(element.xtag.attributes.log, [ | 105 expect(element.xtag.attributes.log, [ |
| 108 ['remove', 'hidden?'], | 106 ['remove', 'hidden?'], |
| 109 ['[]=', 'hidden', ''], | 107 ['[]=', 'hidden', ''], |
| 110 ['[]=', 'id', '2'], | 108 ['[]=', 'id', '2'], |
| 111 ['remove', 'hidden'], | 109 ['remove', 'hidden'], |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 mdv.instanceCreated.add(callback); | 130 mdv.instanceCreated.add(callback); |
| 133 | 131 |
| 134 div.query('template').model = model; | 132 div.query('template').model = model; |
| 135 performMicrotaskCheckpoint(); | 133 performMicrotaskCheckpoint(); |
| 136 | 134 |
| 137 var element = div.nodes[1]; | 135 var element = div.nodes[1]; |
| 138 | 136 |
| 139 expect(element.xtag is MyCustomElement, true, | 137 expect(element.xtag is MyCustomElement, true, |
| 140 reason: '${element.xtag} should be a MyCustomElement'); | 138 reason: '${element.xtag} should be a MyCustomElement'); |
| 141 | 139 |
| 142 expect(element.xtag.myPoint, model[sym('a')]); | 140 expect(element.xtag.myPoint, model[#a]); |
| 143 expect(element.xtag.scaryMonster, model[sym('b')]); | 141 expect(element.xtag.scaryMonster, model[#b]); |
| 144 | 142 |
| 145 expect(element.attributes, isNot(contains('my-point'))); | 143 expect(element.attributes, isNot(contains('my-point'))); |
| 146 expect(element.attributes, isNot(contains('scary-monster'))); | 144 expect(element.attributes, isNot(contains('scary-monster'))); |
| 147 | 145 |
| 148 model[sym('a')] = null; | 146 model[#a] = null; |
| 149 performMicrotaskCheckpoint(); | 147 performMicrotaskCheckpoint(); |
| 150 expect(element.xtag.myPoint, null); | 148 expect(element.xtag.myPoint, null); |
| 151 | 149 |
| 152 div.query('template').model = null; | 150 div.query('template').model = null; |
| 153 performMicrotaskCheckpoint(); | 151 performMicrotaskCheckpoint(); |
| 154 | 152 |
| 155 expect(element.parentNode, null, reason: 'element was detached'); | 153 expect(element.parentNode, null, reason: 'element was detached'); |
| 156 | 154 |
| 157 model[sym('a')] = new Point(1, 2); | 155 model[#a] = new Point(1, 2); |
| 158 model[sym('b')] = new Monster(200); | 156 model[#b] = new Monster(200); |
| 159 performMicrotaskCheckpoint(); | 157 performMicrotaskCheckpoint(); |
| 160 | 158 |
| 161 expect(element.xtag.myPoint, null, reason: 'model was unbound'); | 159 expect(element.xtag.myPoint, null, reason: 'model was unbound'); |
| 162 expect(element.xtag.scaryMonster.health, 100, reason: 'model was unbound'); | 160 expect(element.xtag.scaryMonster.health, 100, reason: 'model was unbound'); |
| 163 | 161 |
| 164 mdv.instanceCreated.remove(callback); | 162 mdv.instanceCreated.remove(callback); |
| 165 }); | 163 }); |
| 166 | 164 |
| 167 } | 165 } |
| 168 | 166 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 bool get isEmpty => _map.isEmpty; | 271 bool get isEmpty => _map.isEmpty; |
| 274 bool get isNotEmpty => _map.isNotEmpty; | 272 bool get isNotEmpty => _map.isNotEmpty; |
| 275 } | 273 } |
| 276 | 274 |
| 277 /** | 275 /** |
| 278 * Sanitizer which does nothing. | 276 * Sanitizer which does nothing. |
| 279 */ | 277 */ |
| 280 class NullTreeSanitizer implements NodeTreeSanitizer { | 278 class NullTreeSanitizer implements NodeTreeSanitizer { |
| 281 void sanitizeTree(Node node) {} | 279 void sanitizeTree(Node node) {} |
| 282 } | 280 } |
| OLD | NEW |