| 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_binding.test.template_binding_test; | 5 library template_binding.test.template_binding_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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 | 1140 |
| 1141 m[0] = toObservable({'name': 'Item 1 changed'}); | 1141 m[0] = toObservable({'name': 'Item 1 changed'}); |
| 1142 | 1142 |
| 1143 i = 1; | 1143 i = 1; |
| 1144 performMicrotaskCheckpoint(); | 1144 performMicrotaskCheckpoint(); |
| 1145 expect(div.nodes[i++].text, 'Item 1 changed'); | 1145 expect(div.nodes[i++].text, 'Item 1 changed'); |
| 1146 expect(div.nodes[i++].tagName, 'TEMPLATE'); | 1146 expect(div.nodes[i++].tagName, 'TEMPLATE'); |
| 1147 expect(div.nodes[i++].text, 'Item 2'); | 1147 expect(div.nodes[i++].text, 'Item 2'); |
| 1148 }); | 1148 }); |
| 1149 | 1149 |
| 1150 observeTest('Attribute Template Option/Optgroup', () { | 1150 // Note: we don't need a zone for this test, and we don't want to alter timing |
| 1151 // since we're testing a rather subtle relationship between select and option. |
| 1152 test('Attribute Template Option/Optgroup', () { |
| 1151 var div = createTestHtml( | 1153 var div = createTestHtml( |
| 1152 '<template bind>' | 1154 '<template bind>' |
| 1153 '<select selectedIndex="{{ selected }}">' | 1155 '<select selectedIndex="{{ selected }}">' |
| 1154 '<optgroup template repeat="{{ groups }}" label="{{ name }}">' | 1156 '<optgroup template repeat="{{ groups }}" label="{{ name }}">' |
| 1155 '<option template repeat="{{ items }}">{{ val }}</option>' | 1157 '<option template repeat="{{ items }}">{{ val }}</option>' |
| 1156 '</optgroup>' | 1158 '</optgroup>' |
| 1157 '</select>' | 1159 '</select>' |
| 1158 '</template>'); | 1160 '</template>'); |
| 1159 | 1161 |
| 1160 var m = toObservable({ | 1162 var m = toObservable({ |
| 1161 'selected': 1, | 1163 'selected': 1, |
| 1162 'groups': [{ | 1164 'groups': [{ |
| 1163 'name': 'one', 'items': [{ 'val': 0 }, { 'val': 1 }] | 1165 'name': 'one', 'items': [{ 'val': 0 }, { 'val': 1 }] |
| 1164 }], | 1166 }], |
| 1165 }); | 1167 }); |
| 1166 | 1168 |
| 1167 recursivelySetTemplateModel(div, m); | 1169 recursivelySetTemplateModel(div, m); |
| 1168 performMicrotaskCheckpoint(); | 1170 Observable.dirtyCheck(); |
| 1169 | 1171 |
| 1170 var select = div.nodes[0].nextNode; | 1172 // Use a timer so it's slower than mutation observers. |
| 1171 expect(select.nodes.length, 2); | 1173 return new Future(() { |
| 1174 var select = div.nodes[0].nextNode; |
| 1175 expect(select.nodes.length, 2); |
| 1172 | 1176 |
| 1173 scheduleMicrotask(expectAsync0(() { | 1177 expect(select.selectedIndex, 1, reason: 'selected index should update by ' |
| 1174 scheduleMicrotask(expectAsync0(() { | 1178 'animationFrame time'); |
| 1175 // TODO(jmesserly): this should be called sooner. | |
| 1176 expect(select.selectedIndex, 1); | |
| 1177 })); | |
| 1178 })); | |
| 1179 expect(select.nodes[0].tagName, 'TEMPLATE'); | |
| 1180 expect((templateBind(templateBind(select.nodes[0]).ref) | |
| 1181 .content.nodes[0] as Element).tagName, 'OPTGROUP'); | |
| 1182 | 1179 |
| 1183 var optgroup = select.nodes[1]; | 1180 expect(select.nodes[0].tagName, 'TEMPLATE'); |
| 1184 expect(optgroup.nodes[0].tagName, 'TEMPLATE'); | 1181 expect((templateBind(templateBind(select.nodes[0]).ref) |
| 1185 expect(optgroup.nodes[1].tagName, 'OPTION'); | 1182 .content.nodes[0] as Element).tagName, 'OPTGROUP'); |
| 1186 expect(optgroup.nodes[1].text, '0'); | 1183 |
| 1187 expect(optgroup.nodes[2].tagName, 'OPTION'); | 1184 var optgroup = select.nodes[1]; |
| 1188 expect(optgroup.nodes[2].text, '1'); | 1185 expect(optgroup.nodes[0].tagName, 'TEMPLATE'); |
| 1186 expect(optgroup.nodes[1].tagName, 'OPTION'); |
| 1187 expect(optgroup.nodes[1].text, '0'); |
| 1188 expect(optgroup.nodes[2].tagName, 'OPTION'); |
| 1189 expect(optgroup.nodes[2].text, '1'); |
| 1190 }); |
| 1189 }); | 1191 }); |
| 1190 | 1192 |
| 1191 observeTest('NestedIterateTableMixedSemanticNative', () { | 1193 observeTest('NestedIterateTableMixedSemanticNative', () { |
| 1192 if (!parserHasNativeTemplate) return; | 1194 if (!parserHasNativeTemplate) return; |
| 1193 | 1195 |
| 1194 var div = createTestHtml( | 1196 var div = createTestHtml( |
| 1195 '<table><tbody>' | 1197 '<table><tbody>' |
| 1196 '<template repeat="{{}}">' | 1198 '<template repeat="{{}}">' |
| 1197 '<tr>' | 1199 '<tr>' |
| 1198 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' | 1200 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 prepareBinding(path, name, node) { | 1856 prepareBinding(path, name, node) { |
| 1855 if (name != 'text' || path != 'age') return null; | 1857 if (name != 'text' || path != 'age') return null; |
| 1856 | 1858 |
| 1857 return (model, node) { | 1859 return (model, node) { |
| 1858 expect(model['age'], expectedAge); | 1860 expect(model['age'], expectedAge); |
| 1859 count++; | 1861 count++; |
| 1860 return model; | 1862 return model; |
| 1861 }; | 1863 }; |
| 1862 } | 1864 } |
| 1863 } | 1865 } |
| OLD | NEW |