| 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 template_element_test; | 5 library template_element_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 observeTest('Template bind, no parent', () { | 100 observeTest('Template bind, no parent', () { |
| 101 var div = createTestHtml('<template bind>text</template>'); | 101 var div = createTestHtml('<template bind>text</template>'); |
| 102 var template = div.nodes[0]; | 102 var template = div.nodes[0]; |
| 103 template.remove(); | 103 template.remove(); |
| 104 | 104 |
| 105 recursivelySetTemplateModel(template, toSymbolMap({})); | 105 recursivelySetTemplateModel(template, toSymbolMap({})); |
| 106 performMicrotaskCheckpoint(); | 106 performMicrotaskCheckpoint(); |
| 107 expect(template.nodes.length, 0); | 107 expect(template.nodes.length, 0); |
| 108 expect(template.nextNode, null); | 108 expect(template.nextNode, null); |
| 109 // TODO(jmesserly): the JS tests assert that observer callbacks had no | |
| 110 // exceptions. How do we replicate this? | |
| 111 }); | 109 }); |
| 112 | 110 |
| 113 observeTest('Template bind, no defaultView', () { | 111 observeTest('Template bind, no defaultView', () { |
| 114 var div = createTestHtml('<template bind>text</template>'); | 112 var div = createTestHtml('<template bind>text</template>'); |
| 115 var template = div.nodes[0]; | 113 var template = div.nodes[0]; |
| 116 var doc = document.implementation.createHtmlDocument(''); | 114 var doc = document.implementation.createHtmlDocument(''); |
| 117 doc.adoptNode(div); | 115 doc.adoptNode(div); |
| 118 recursivelySetTemplateModel(template, toSymbolMap({})); | 116 recursivelySetTemplateModel(template, toSymbolMap({})); |
| 119 performMicrotaskCheckpoint(); | 117 performMicrotaskCheckpoint(); |
| 120 expect(div.nodes.length, 1); | 118 expect(div.nodes.length, 1); |
| 121 // TODO(jmesserly): the JS tests assert that observer callbacks had no | |
| 122 // exceptions. How do we replicate this? | |
| 123 }); | 119 }); |
| 124 | 120 |
| 125 observeTest('Template-Empty Bind', () { | 121 observeTest('Template-Empty Bind', () { |
| 126 var div = createTestHtml('<template bind>text</template>'); | 122 var div = createTestHtml('<template bind>text</template>'); |
| 127 recursivelySetTemplateModel(div, null); | 123 recursivelySetTemplateModel(div, null); |
| 128 performMicrotaskCheckpoint(); | 124 performMicrotaskCheckpoint(); |
| 129 expect(div.nodes.length, 2); | 125 expect(div.nodes.length, 2); |
| 130 expect(div.nodes.last.text, 'text'); | 126 expect(div.nodes.last.text, 'text'); |
| 131 }); | 127 }); |
| 132 | 128 |
| 129 observeTest('Template Bind If', () { |
| 130 var div = createTestHtml('<template bind if="{{ foo }}">text</template>'); |
| 131 // Note: changed this value from 0->null because zero is not falsey in Dart. |
| 132 // See https://code.google.com/p/dart/issues/detail?id=11956 |
| 133 var m = toSymbolMap({ 'foo': null }); |
| 134 recursivelySetTemplateModel(div, m); |
| 135 performMicrotaskCheckpoint(); |
| 136 expect(div.nodes.length, 1); |
| 137 |
| 138 m[sym('foo')] = 1; |
| 139 performMicrotaskCheckpoint(); |
| 140 expect(div.nodes.length, 2); |
| 141 expect(div.lastChild.text, 'text'); |
| 142 }); |
| 143 |
| 144 observeTest('Template Bind If, 2', () { |
| 145 var div = createTestHtml( |
| 146 '<template bind="{{ foo }}" if="{{ bar }}">{{ bat }}</template>'); |
| 147 var m = toSymbolMap({ 'bar': null, 'foo': { 'bat': 'baz' } }); |
| 148 recursivelySetTemplateModel(div, m); |
| 149 performMicrotaskCheckpoint(); |
| 150 expect(div.nodes.length, 1); |
| 151 |
| 152 m[sym('bar')] = 1; |
| 153 performMicrotaskCheckpoint(); |
| 154 expect(div.nodes.length, 2); |
| 155 expect(div.lastChild.text, 'baz'); |
| 156 }); |
| 157 |
| 158 observeTest('Template If', () { |
| 159 var div = createTestHtml('<template if="{{ foo }}">text</template>'); |
| 160 // Note: changed this value from 0->null because zero is not falsey in Dart. |
| 161 // See https://code.google.com/p/dart/issues/detail?id=11956 |
| 162 var m = toSymbolMap({ 'foo': null }); |
| 163 recursivelySetTemplateModel(div, m); |
| 164 performMicrotaskCheckpoint(); |
| 165 expect(div.nodes.length, 1); |
| 166 |
| 167 m[sym('foo')] = 1; |
| 168 performMicrotaskCheckpoint(); |
| 169 expect(div.nodes.length, 2); |
| 170 expect(div.lastChild.text, 'text'); |
| 171 }); |
| 172 |
| 133 observeTest('TextTemplateWithNullStringBinding', () { | 173 observeTest('TextTemplateWithNullStringBinding', () { |
| 134 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); | 174 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); |
| 135 var model = toSymbolMap({'b': 'B'}); | 175 var model = toSymbolMap({'b': 'B'}); |
| 136 recursivelySetTemplateModel(div, model); | 176 recursivelySetTemplateModel(div, model); |
| 137 | 177 |
| 138 deliverChanges(model); | 178 deliverChanges(model); |
| 139 expect(div.nodes.length, 2); | 179 expect(div.nodes.length, 2); |
| 140 expect(div.nodes.last.text, 'aBc'); | 180 expect(div.nodes.last.text, 'aBc'); |
| 141 | 181 |
| 142 model[sym('b')] = 'b'; | 182 model[sym('b')] = 'b'; |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 k = k is String ? sym(k) : _deepToSymbol(k); | 1737 k = k is String ? sym(k) : _deepToSymbol(k); |
| 1698 result[k] = _deepToSymbol(v); | 1738 result[k] = _deepToSymbol(v); |
| 1699 }); | 1739 }); |
| 1700 return result; | 1740 return result; |
| 1701 } | 1741 } |
| 1702 if (value is Iterable) { | 1742 if (value is Iterable) { |
| 1703 return value.map(_deepToSymbol).toList(); | 1743 return value.map(_deepToSymbol).toList(); |
| 1704 } | 1744 } |
| 1705 return value; | 1745 return value; |
| 1706 } | 1746 } |
| OLD | NEW |