Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: pkg/mdv/test/template_element_test.dart

Issue 18162004: [package:mdv] port createInstance change (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 '</template>' 1535 '</template>'
1536 '</template>'); 1536 '</template>');
1537 recursivelySetTemplateModel(div, null); 1537 recursivelySetTemplateModel(div, null);
1538 // TODO(jmesserly): how to fix this test? 1538 // TODO(jmesserly): how to fix this test?
1539 // Perhaps revive the original? 1539 // Perhaps revive the original?
1540 // https://github.com/toolkitchen/mdv/commit/8bc1e3466aeb6930150c0d3148f0e83 0184bf599#L3R1278 1540 // https://github.com/toolkitchen/mdv/commit/8bc1e3466aeb6930150c0d3148f0e83 0184bf599#L3R1278
1541 //expect(!!ChangeSummary._errorThrownDuringCallback, false); 1541 //expect(!!ChangeSummary._errorThrownDuringCallback, false);
1542 }); 1542 });
1543 1543
1544 test('CreateInstance', () { 1544 test('CreateInstance', () {
1545 var div = createTestHtml( 1545 TemplateElement.syntax['Test'] = new TestBindingSyntax();
1546 '<template bind="{{a}}">' 1546 try {
1547 '<template bind="{{b}}">' 1547 var div = createTestHtml(
1548 '{{text}}' 1548 '<template bind="{{a}}">'
1549 '</template>' 1549 '<template bind="{{b}}">'
1550 '</template>'); 1550 '{{ foo }}:{{ replaceme }}'
1551 var outer = div.nodes.first; 1551 '</template>'
1552 '</template>');
1553 var outer = div.nodes.first;
1554 var model = toSymbolMap({'b': {'foo': 'bar'}});
1552 1555
1553 var instance = outer.createInstance(); 1556 var host = new DivElement();
1554 expect(outer.content.nodes.first, instance.nodes.first.ref); 1557 var instance = outer.createInstance(model, 'Test');
1558 expect(outer.content.nodes.first, instance.nodes.first.ref);
1559 expect(instance.firstChild.attributes['syntax'], 'Test');
1555 1560
1556 var instance2 = outer.createInstance(); 1561 host.append(instance);
1557 expect(instance2.nodes.first.ref, instance.nodes.first.ref); 1562 deliverChangeRecords();
1563 expect(host.firstChild.nextNode.text, 'bar:replaced');
1564 } finally {
1565 TemplateElement.syntax.remove('Test');
1566 }
1558 }); 1567 });
1559 1568
1560 test('Bootstrap', () { 1569 test('Bootstrap', () {
1561 var div = new DivElement(); 1570 var div = new DivElement();
1562 div.innerHtml = 1571 div.innerHtml =
1563 '<template>' 1572 '<template>'
1564 '<div></div>' 1573 '<div></div>'
1565 '<template>' 1574 '<template>'
1566 'Hello' 1575 'Hello'
1567 '</template>' 1576 '</template>'
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 expect(called, false); 1611 expect(called, false);
1603 1612
1604 recursivelySetTemplateModel(div, null); 1613 recursivelySetTemplateModel(div, null);
1605 deliverChangeRecords(); 1614 deliverChangeRecords();
1606 expect(called, true); 1615 expect(called, true);
1607 1616
1608 sub.cancel(); 1617 sub.cancel();
1609 }); 1618 });
1610 } 1619 }
1611 1620
1621 class TestBindingSyntax extends CustomBindingSyntax {
1622 getBinding(model, String path, name, node) {
1623 if (path.trim() == 'replaceme') return new ObservableBox('replaced');
1624 return null;
1625 }
1626 }
1627
1612 class UnbindingInNestedBindSyntax extends CustomBindingSyntax { 1628 class UnbindingInNestedBindSyntax extends CustomBindingSyntax {
1613 int expectedAge = 42; 1629 int expectedAge = 42;
1614 int count = 0; 1630 int count = 0;
1615 1631
1616 getBinding(model, path, name, node) { 1632 getBinding(model, path, name, node) {
1617 if (name != 'text' || path != 'age') 1633 if (name != 'text' || path != 'age')
1618 return; 1634 return;
1619 1635
1620 expect(model[sym('age')], expectedAge); 1636 expect(model[sym('age')], expectedAge);
1621 count++; 1637 count++;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 k = k is String ? sym(k) : _deepToSymbol(k); 1675 k = k is String ? sym(k) : _deepToSymbol(k);
1660 result[k] = _deepToSymbol(v); 1676 result[k] = _deepToSymbol(v);
1661 }); 1677 });
1662 return result; 1678 return result;
1663 } 1679 }
1664 if (value is Iterable) { 1680 if (value is Iterable) {
1665 return value.map(_deepToSymbol).toList(); 1681 return value.map(_deepToSymbol).toList();
1666 } 1682 }
1667 return value; 1683 return value;
1668 } 1684 }
1669
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698