| 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 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1040 |
| 1041 m[0] = toSymbols({'name': 'Item 1 changed'}); | 1041 m[0] = toSymbols({'name': 'Item 1 changed'}); |
| 1042 | 1042 |
| 1043 i = 1; | 1043 i = 1; |
| 1044 deliverChanges(m); | 1044 deliverChanges(m); |
| 1045 expect(div.nodes[i++].text, 'Item 1 changed'); | 1045 expect(div.nodes[i++].text, 'Item 1 changed'); |
| 1046 expect(div.nodes[i++].tagName, 'TEMPLATE'); | 1046 expect(div.nodes[i++].tagName, 'TEMPLATE'); |
| 1047 expect(div.nodes[i++].text, 'Item 2'); | 1047 expect(div.nodes[i++].text, 'Item 2'); |
| 1048 }); | 1048 }); |
| 1049 | 1049 |
| 1050 test('Attribute Template Option', () { | 1050 test('Attribute Template Option/Optgroup', () { |
| 1051 var div = createTestHtml( | 1051 var div = createTestHtml( |
| 1052 '<template bind>' | 1052 '<template bind>' |
| 1053 '<select>' | 1053 '<select>' |
| 1054 '<option template repeat>{{ val }}</option>' | 1054 '<optgroup template repeat="{{ groups }}" label="{{ name }}">' |
| 1055 '<option template repeat="{{ items }}">{{ val }}</option>' |
| 1056 '</optgroup>' |
| 1055 '</select>' | 1057 '</select>' |
| 1056 '</template>'); | 1058 '</template>'); |
| 1057 | 1059 |
| 1058 var m = toSymbols([{ 'val': 0 }, { 'val': 1 }]); | 1060 var m = toSymbols({ |
| 1061 'selected': 1, |
| 1062 'groups': [{ |
| 1063 'name': 'one', 'items': [{ 'val': 0 }, { 'val': 1 }] |
| 1064 }], |
| 1065 }); |
| 1059 | 1066 |
| 1060 recursivelySetTemplateModel(div, m); | 1067 recursivelySetTemplateModel(div, m); |
| 1061 deliverChanges(m); | 1068 deliverChanges(m); |
| 1062 | 1069 |
| 1063 var select = div.nodes[0].nextNode; | 1070 var select = div.nodes[0].nextNode; |
| 1064 expect(select.nodes.length, 3); | 1071 expect(select.nodes.length, 2); |
| 1065 expect(select.nodes[0].tagName, 'TEMPLATE'); | 1072 expect(select.nodes[0].tagName, 'TEMPLATE'); |
| 1066 expect(select.nodes[0].ref.content.nodes[0].tagName, 'OPTION'); | 1073 expect(select.nodes[0].ref.content.nodes[0].tagName, 'OPTGROUP'); |
| 1067 expect(select.nodes[1].tagName, 'OPTION'); | 1074 |
| 1068 expect(select.nodes[1].text, '0'); | 1075 var optgroup = select.nodes[1]; |
| 1069 expect(select.nodes[2].tagName, 'OPTION'); | 1076 expect(optgroup.nodes[0].tagName, 'TEMPLATE'); |
| 1070 expect(select.nodes[2].text, '1'); | 1077 expect(optgroup.nodes[1].tagName, 'OPTION'); |
| 1078 expect(optgroup.nodes[1].text, '0'); |
| 1079 expect(optgroup.nodes[2].tagName, 'OPTION'); |
| 1080 expect(optgroup.nodes[2].text, '1'); |
| 1071 }); | 1081 }); |
| 1072 | 1082 |
| 1073 test('NestedIterateTableMixedSemanticNative', () { | 1083 test('NestedIterateTableMixedSemanticNative', () { |
| 1074 if (!TemplateElement.supported) return; | 1084 if (!TemplateElement.supported) return; |
| 1075 | 1085 |
| 1076 var div = createTestHtml( | 1086 var div = createTestHtml( |
| 1077 '<table><tbody>' | 1087 '<table><tbody>' |
| 1078 '<template repeat="{{}}">' | 1088 '<template repeat="{{}}">' |
| 1079 '<tr>' | 1089 '<tr>' |
| 1080 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' | 1090 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 }); | 1469 }); |
| 1460 | 1470 |
| 1461 test('bindModel to polyfilled shadow root', () { | 1471 test('bindModel to polyfilled shadow root', () { |
| 1462 var root = createTestHtml('Hi {{ name }}'); | 1472 var root = createTestHtml('Hi {{ name }}'); |
| 1463 var model = toSymbolMap({'name': 'Leela'}); | 1473 var model = toSymbolMap({'name': 'Leela'}); |
| 1464 mdv.bindModel(root, model); | 1474 mdv.bindModel(root, model); |
| 1465 deliverChangeRecords(); | 1475 deliverChangeRecords(); |
| 1466 expect(root.text, 'Hi Leela'); | 1476 expect(root.text, 'Hi Leela'); |
| 1467 }); | 1477 }); |
| 1468 | 1478 |
| 1479 test('BindShadowDOM Template Ref', () { |
| 1480 if (ShadowRoot.supported) { |
| 1481 var root = createShadowTestHtml( |
| 1482 '<template id=foo>Hi</template><template bind ref=foo></template>'); |
| 1483 recursivelySetTemplateModel(root, toSymbolMap({})); |
| 1484 deliverChangeRecords(); |
| 1485 expect(root.nodes.length, 3); |
| 1486 } |
| 1487 }); |
| 1488 |
| 1469 // https://github.com/toolkitchen/mdv/issues/8 | 1489 // https://github.com/toolkitchen/mdv/issues/8 |
| 1470 test('UnbindingInNestedBind', () { | 1490 test('UnbindingInNestedBind', () { |
| 1471 var div = createTestHtml( | 1491 var div = createTestHtml( |
| 1472 '<template bind="{{outer}}" if="{{outer}}" syntax="testHelper">' | 1492 '<template bind="{{outer}}" if="{{outer}}" syntax="testHelper">' |
| 1473 '<template bind="{{inner}}" if="{{inner}}">' | 1493 '<template bind="{{inner}}" if="{{inner}}">' |
| 1474 '{{ age }}' | 1494 '{{ age }}' |
| 1475 '</template>' | 1495 '</template>' |
| 1476 '</template>'); | 1496 '</template>'); |
| 1477 | 1497 |
| 1478 var syntax = new UnbindingInNestedBindSyntax(); | 1498 var syntax = new UnbindingInNestedBindSyntax(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 result[k] = _deepToSymbol(v); | 1660 result[k] = _deepToSymbol(v); |
| 1641 }); | 1661 }); |
| 1642 return result; | 1662 return result; |
| 1643 } | 1663 } |
| 1644 if (value is Iterable) { | 1664 if (value is Iterable) { |
| 1645 return value.map(_deepToSymbol).toList(); | 1665 return value.map(_deepToSymbol).toList(); |
| 1646 } | 1666 } |
| 1647 return value; | 1667 return value; |
| 1648 } | 1668 } |
| 1649 | 1669 |
| OLD | NEW |