| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 test('Template', () { | 76 test('Template', () { |
| 77 var div = createTestHtml('<template bind={{}}>text</template>'); | 77 var div = createTestHtml('<template bind={{}}>text</template>'); |
| 78 recursivelySetTemplateModel(div, null); | 78 recursivelySetTemplateModel(div, null); |
| 79 deliverChangeRecords(); | 79 deliverChangeRecords(); |
| 80 expect(div.nodes.length, 2); | 80 expect(div.nodes.length, 2); |
| 81 expect(div.nodes.last.text, 'text'); | 81 expect(div.nodes.last.text, 'text'); |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 test('Template bind, no parent', () { |
| 85 var div = createTestHtml('<template bind>text</template>'); |
| 86 var template = div.nodes[0]; |
| 87 template.remove(); |
| 88 |
| 89 recursivelySetTemplateModel(template, toSymbolMap({})); |
| 90 deliverChangeRecords(); |
| 91 expect(template.nodes.length, 0); |
| 92 expect(template.nextNode, null); |
| 93 // TODO(jmesserly): the JS tests assert that observer callbacks had no |
| 94 // exceptions. How do we replicate this? |
| 95 }); |
| 96 |
| 97 test('Template bind, no defaultView', () { |
| 98 var div = createTestHtml('<template bind>text</template>'); |
| 99 var template = div.nodes[0]; |
| 100 var doc = document.implementation.createHtmlDocument(''); |
| 101 doc.adoptNode(div); |
| 102 recursivelySetTemplateModel(template, toSymbolMap({})); |
| 103 deliverChangeRecords(); |
| 104 expect(div.nodes.length, 1); |
| 105 // TODO(jmesserly): the JS tests assert that observer callbacks had no |
| 106 // exceptions. How do we replicate this? |
| 107 }); |
| 108 |
| 84 test('Template-Empty Bind', () { | 109 test('Template-Empty Bind', () { |
| 85 var div = createTestHtml('<template bind>text</template>'); | 110 var div = createTestHtml('<template bind>text</template>'); |
| 86 recursivelySetTemplateModel(div, null); | 111 recursivelySetTemplateModel(div, null); |
| 87 deliverChangeRecords(); | 112 deliverChangeRecords(); |
| 88 expect(div.nodes.length, 2); | 113 expect(div.nodes.length, 2); |
| 89 expect(div.nodes.last.text, 'text'); | 114 expect(div.nodes.last.text, 'text'); |
| 90 }); | 115 }); |
| 91 | 116 |
| 92 test('TextTemplateWithNullStringBinding', () { | 117 test('TextTemplateWithNullStringBinding', () { |
| 93 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); | 118 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 963 |
| 939 m[0] = toSymbols({'name': 'Item 1 changed'}); | 964 m[0] = toSymbols({'name': 'Item 1 changed'}); |
| 940 | 965 |
| 941 i = 1; | 966 i = 1; |
| 942 deliverChanges(m); | 967 deliverChanges(m); |
| 943 expect(div.nodes[i++].text, 'Item 1 changed'); | 968 expect(div.nodes[i++].text, 'Item 1 changed'); |
| 944 expect(div.nodes[i++].tagName, 'TEMPLATE'); | 969 expect(div.nodes[i++].tagName, 'TEMPLATE'); |
| 945 expect(div.nodes[i++].text, 'Item 2'); | 970 expect(div.nodes[i++].text, 'Item 2'); |
| 946 }); | 971 }); |
| 947 | 972 |
| 973 test('Attribute Template Option', () { |
| 974 var div = createTestHtml( |
| 975 '<template bind>' |
| 976 '<select>' |
| 977 '<option template repeat>{{ val }}</option>' |
| 978 '</select>' |
| 979 '</template>'); |
| 980 |
| 981 var m = toSymbols([{ 'val': 0 }, { 'val': 1 }]); |
| 982 |
| 983 recursivelySetTemplateModel(div, m); |
| 984 deliverChanges(m); |
| 985 |
| 986 var select = div.nodes[0].nextNode; |
| 987 expect(select.nodes.length, 3); |
| 988 expect(select.nodes[0].tagName, 'TEMPLATE'); |
| 989 expect(select.nodes[0].ref.content.nodes[0].tagName, 'OPTION'); |
| 990 expect(select.nodes[1].tagName, 'OPTION'); |
| 991 expect(select.nodes[1].text, '0'); |
| 992 expect(select.nodes[2].tagName, 'OPTION'); |
| 993 expect(select.nodes[2].text, '1'); |
| 994 }); |
| 995 |
| 948 test('NestedIterateTableMixedSemanticNative', () { | 996 test('NestedIterateTableMixedSemanticNative', () { |
| 949 if (!TemplateElement.supported) return; | 997 if (!TemplateElement.supported) return; |
| 950 | 998 |
| 951 var div = createTestHtml( | 999 var div = createTestHtml( |
| 952 '<table><tbody>' | 1000 '<table><tbody>' |
| 953 '<template repeat="{{}}">' | 1001 '<template repeat="{{}}">' |
| 954 '<tr>' | 1002 '<tr>' |
| 955 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' | 1003 '<td template repeat="{{}}" class="{{ val }}">{{ val }}</td>' |
| 956 '</tr>' | 1004 '</tr>' |
| 957 '</template>' | 1005 '</template>' |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 result[k] = _deepToSymbol(v); | 1563 result[k] = _deepToSymbol(v); |
| 1516 }); | 1564 }); |
| 1517 return result; | 1565 return result; |
| 1518 } | 1566 } |
| 1519 if (value is Iterable) { | 1567 if (value is Iterable) { |
| 1520 return value.map(_deepToSymbol).toList(); | 1568 return value.map(_deepToSymbol).toList(); |
| 1521 } | 1569 } |
| 1522 return value; | 1570 return value; |
| 1523 } | 1571 } |
| 1524 | 1572 |
| OLD | NEW |