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

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

Issue 17552019: Reorganize mdv and observe packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 7 years, 6 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
« no previous file with comments | « pkg/mdv/test/observe_utils.dart ('k') | pkg/mdv_observe/lib/mdv_observe.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
11 import 'package:mdv_observe/mdv_observe.dart'; 11 import 'package:mdv/mdv.dart' as mdv;
12 import 'package:observe/observe.dart';
12 import 'package:unittest/html_config.dart'; 13 import 'package:unittest/html_config.dart';
13 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
14 import 'mdv_observe_utils.dart'; 15 import 'observe_utils.dart';
15 16
16 // Note: this file ported from 17 // Note: this file ported from
17 // https://github.com/toolkitchen/mdv/blob/master/tests/template_element.js 18 // https://github.com/toolkitchen/mdv/blob/master/tests/template_element.js
18 // TODO(jmesserly): submit a small cleanup patch to original. I fixed some 19 // TODO(jmesserly): submit a small cleanup patch to original. I fixed some
19 // cases where "div" and "t" were unintentionally using the JS global scope; 20 // cases where "div" and "t" were unintentionally using the JS global scope;
20 // look for "assertNodesAre". 21 // look for "assertNodesAre".
21 22
22 main() { 23 main() {
24 mdv.initialize();
23 useHtmlConfiguration(); 25 useHtmlConfiguration();
24 group('Template Element', templateElementTests); 26 group('Template Element', templateElementTests);
25 } 27 }
26 28
27 templateElementTests() { 29 templateElementTests() {
28 var testDiv; 30 var testDiv;
29 31
30 setUp(() { 32 setUp(() {
31 document.body.append(testDiv = new DivElement()); 33 document.body.append(testDiv = new DivElement());
32 }); 34 });
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 expect(div.nodes[3].text, 'Name: Leela'); 1207 expect(div.nodes[3].text, 'Name: Leela');
1206 }); 1208 });
1207 1209
1208 test('ChangeFromBindToRepeat', () { 1210 test('ChangeFromBindToRepeat', () {
1209 var div = createTestHtml( 1211 var div = createTestHtml(
1210 '<template bind="{{a}}">' 1212 '<template bind="{{a}}">'
1211 '{{ length }}' 1213 '{{ length }}'
1212 '</template>'); 1214 '</template>');
1213 var template = div.nodes.first; 1215 var template = div.nodes.first;
1214 1216
1217 // Note: this test data is a little different from the JS version, because
1218 // we allow binding to the "length" field of the Map in preference to
1219 // binding keys.
1215 var m = toSymbols({ 1220 var m = toSymbols({
1216 'a': [ 1221 'a': [
1217 {'length': 0}, 1222 [],
1218 { 1223 { 'b': [1,2,3,4] },
1219 'length': 1, 1224 // Note: this will use the Map "length" property, not the "length" key.
1220 'b': {'length': 4} 1225 {'length': 42, 'c': 123}
1221 },
1222 {'length': 2}
1223 ] 1226 ]
1224 }); 1227 });
1225 recursivelySetTemplateModel(div, m); 1228 recursivelySetTemplateModel(div, m);
1226 deliverChanges(m); 1229 deliverChanges(m);
1227 1230
1228 expect(div.nodes.length, 2); 1231 expect(div.nodes.length, 2);
1229 expect(div.nodes[1].text, '3'); 1232 expect(div.nodes[1].text, '3');
1230 1233
1231 template.unbind('bind'); 1234 template.unbind('bind');
1232 template.bind('repeat', m, 'a'); 1235 template.bind('repeat', m, 'a');
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 recursivelySetTemplateModel(root, model); 1320 recursivelySetTemplateModel(root, model);
1318 deliverChanges(model); 1321 deliverChanges(model);
1319 expect(root.nodes[1].text, 'Hi Leela'); 1322 expect(root.nodes[1].text, 'Hi Leela');
1320 } 1323 }
1321 }); 1324 });
1322 1325
1323 test('BindShadowDOM bindModel', () { 1326 test('BindShadowDOM bindModel', () {
1324 if (ShadowRoot.supported) { 1327 if (ShadowRoot.supported) {
1325 var root = createShadowTestHtml('Hi {{ name }}'); 1328 var root = createShadowTestHtml('Hi {{ name }}');
1326 var model = toSymbolMap({'name': 'Leela'}); 1329 var model = toSymbolMap({'name': 'Leela'});
1327 TemplateElement.bindModel(root, model); 1330 mdv.bindModel(root, model);
1328 deliverChangeRecords(); 1331 deliverChangeRecords();
1329 expect(root.text, 'Hi Leela'); 1332 expect(root.text, 'Hi Leela');
1330 } 1333 }
1331 }); 1334 });
1332 1335
1333 test('bindModel to polyfilled shadow root', () { 1336 test('bindModel to polyfilled shadow root', () {
1334 var root = createTestHtml('Hi {{ name }}'); 1337 var root = createTestHtml('Hi {{ name }}');
1335 var model = toSymbolMap({'name': 'Leela'}); 1338 var model = toSymbolMap({'name': 'Leela'});
1336 TemplateElement.bindModel(root, model); 1339 mdv.bindModel(root, model);
1337 deliverChangeRecords(); 1340 deliverChangeRecords();
1338 expect(root.text, 'Hi Leela'); 1341 expect(root.text, 'Hi Leela');
1339 }); 1342 });
1340 1343
1341 // https://github.com/toolkitchen/mdv/issues/8 1344 // https://github.com/toolkitchen/mdv/issues/8
1342 test('UnbindingInNestedBind', () { 1345 test('UnbindingInNestedBind', () {
1343 var div = createTestHtml( 1346 var div = createTestHtml(
1344 '<template bind="{{outer}}" if="{{outer}}" syntax="testHelper">' 1347 '<template bind="{{outer}}" if="{{outer}}" syntax="testHelper">'
1345 '<template bind="{{inner}}" if="{{inner}}">' 1348 '<template bind="{{inner}}" if="{{inner}}">'
1346 '{{ age }}' 1349 '{{ age }}'
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 TemplateElement.bootstrap(template); 1441 TemplateElement.bootstrap(template);
1439 template2 = template.content.nodes.first; 1442 template2 = template.content.nodes.first;
1440 expect(template2.content.nodes.length, 2); 1443 expect(template2.content.nodes.length, 2);
1441 var template3 = template2.content.nodes.first.nextNode; 1444 var template3 = template2.content.nodes.first.nextNode;
1442 expect(template3.content.nodes.length, 1); 1445 expect(template3.content.nodes.length, 1);
1443 expect(template3.content.nodes.first.text, 'Hello'); 1446 expect(template3.content.nodes.first.text, 'Hello');
1444 }); 1447 });
1445 1448
1446 test('instanceCreated hack', () { 1449 test('instanceCreated hack', () {
1447 var called = false; 1450 var called = false;
1448 var sub = TemplateElement.instanceCreated.listen((node) { 1451 var sub = mdv.instanceCreated.listen((node) {
1449 called = true; 1452 called = true;
1450 expect(node.nodeType, Node.DOCUMENT_FRAGMENT_NODE); 1453 expect(node.nodeType, Node.DOCUMENT_FRAGMENT_NODE);
1451 }); 1454 });
1452 1455
1453 var div = createTestHtml('<template bind="{{}}">Foo</template>'); 1456 var div = createTestHtml('<template bind="{{}}">Foo</template>');
1454 expect(called, false); 1457 expect(called, false);
1455 1458
1456 recursivelySetTemplateModel(div, null); 1459 recursivelySetTemplateModel(div, null);
1457 deliverChangeRecords(); 1460 deliverChangeRecords();
1458 expect(called, true); 1461 expect(called, true);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 result[k] = _deepToSymbol(v); 1515 result[k] = _deepToSymbol(v);
1513 }); 1516 });
1514 return result; 1517 return result;
1515 } 1518 }
1516 if (value is Iterable) { 1519 if (value is Iterable) {
1517 return value.map(_deepToSymbol).toList(); 1520 return value.map(_deepToSymbol).toList();
1518 } 1521 }
1519 return value; 1522 return value;
1520 } 1523 }
1521 1524
OLDNEW
« no previous file with comments | « pkg/mdv/test/observe_utils.dart ('k') | pkg/mdv_observe/lib/mdv_observe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698