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

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

Issue 17770006: [mdv] implement full DOM stability (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged 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
« no previous file with comments | « pkg/mdv/pubspec.yaml ('k') | no next file » | 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;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 recursivelySetTemplateModel(element, model) { 66 recursivelySetTemplateModel(element, model) {
67 for (var node in element.queryAll('*')) { 67 for (var node in element.queryAll('*')) {
68 if (node.isTemplate) node.model = model; 68 if (node.isTemplate) node.model = model;
69 } 69 }
70 } 70 }
71 71
72 dispatchEvent(type, target) { 72 dispatchEvent(type, target) {
73 target.dispatchEvent(new Event(type, cancelable: false)); 73 target.dispatchEvent(new Event(type, cancelable: false));
74 } 74 }
75 75
76 var expando = new Expando('test');
77 void addExpandos(node) {
78 while (node != null) {
79 expando[node] = node.text;
80 node = node.nextNode;
81 }
82 }
83
84 void checkExpandos(node) {
85 expect(node, isNotNull);
86 while (node != null) {
87 expect(expando[node], node.text);
88 node = node.nextNode;
89 }
90 }
91
76 test('Template', () { 92 test('Template', () {
77 var div = createTestHtml('<template bind={{}}>text</template>'); 93 var div = createTestHtml('<template bind={{}}>text</template>');
78 recursivelySetTemplateModel(div, null); 94 recursivelySetTemplateModel(div, null);
79 deliverChangeRecords(); 95 deliverChangeRecords();
80 expect(div.nodes.length, 2); 96 expect(div.nodes.length, 2);
81 expect(div.nodes.last.text, 'text'); 97 expect(div.nodes.last.text, 'text');
82 }); 98 });
83 99
84 test('Template bind, no parent', () { 100 test('Template bind, no parent', () {
85 var div = createTestHtml('<template bind>text</template>'); 101 var div = createTestHtml('<template bind>text</template>');
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 276
261 model.addAll(toSymbols([3, 4])); 277 model.addAll(toSymbols([3, 4]));
262 deliverChanges(model); 278 deliverChanges(model);
263 expect(div.nodes.length, 4); 279 expect(div.nodes.length, 4);
264 280
265 model.removeRange(1, 2); 281 model.removeRange(1, 2);
266 deliverChanges(model); 282 deliverChanges(model);
267 expect(div.nodes.length, 3); 283 expect(div.nodes.length, 3);
268 }); 284 });
269 285
286 test('Repeat - Reuse Instances', () {
287 var div = createTestHtml('<template repeat>{{ val }}</template>');
288
289 var model = toSymbols([
290 {'val': 10},
291 {'val': 5},
292 {'val': 2},
293 {'val': 8},
294 {'val': 1}
295 ]);
296 recursivelySetTemplateModel(div, model);
297
298 deliverChanges(model);
299 expect(div.nodes.length, 6);
300 var template = div.firstChild;
301
302 addExpandos(template.nextNode);
303 checkExpandos(template.nextNode);
304
305 final VAL = const Symbol('val');
306 model.sort((a, b) => a[VAL] - b[VAL]);
307 deliverChanges(model);
308 checkExpandos(template.nextNode);
309
310 model = toObservable(model.reversed);
311 recursivelySetTemplateModel(div, model);
312 deliverChanges(model);
313 checkExpandos(template.nextNode);
314
315 for (var item in model) {
316 item[VAL] += 1;
317 }
318
319 deliverChanges(model);
320 expect(div.nodes[1].text, "11");
321 expect(div.nodes[2].text, "9");
322 expect(div.nodes[3].text, "6");
323 expect(div.nodes[4].text, "3");
324 expect(div.nodes[5].text, "2");
325 });
326
327 test('Bind - Reuse Instance', () {
328 var div = createTestHtml(
329 '<template bind="{{ foo }}">{{ bar }}</template>');
330
331 var model = toObservable({ 'foo': { 'bar': 5 }});
332 recursivelySetTemplateModel(div, model);
333
334 deliverChanges(model);
335 expect(div.nodes.length, 2);
336 var template = div.firstChild;
337
338 addExpandos(template.nextNode);
339 checkExpandos(template.nextNode);
340
341 model = toObservable({'foo': model['foo']});
342 recursivelySetTemplateModel(div, model);
343 deliverChanges(model);
344 checkExpandos(template.nextNode);
345 });
346
270 test('Repeat-Empty', () { 347 test('Repeat-Empty', () {
271 var div = createTestHtml( 348 var div = createTestHtml(
272 '<template repeat>text</template>'); 349 '<template repeat>text</template>');
273 350
274 var model = toSymbols([0, 1, 2]); 351 var model = toSymbols([0, 1, 2]);
275 recursivelySetTemplateModel(div, model); 352 recursivelySetTemplateModel(div, model);
276 353
277 deliverChanges(model); 354 deliverChanges(model);
278 expect(div.nodes.length, 4); 355 expect(div.nodes.length, 4);
279 356
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 result[k] = _deepToSymbol(v); 1640 result[k] = _deepToSymbol(v);
1564 }); 1641 });
1565 return result; 1642 return result;
1566 } 1643 }
1567 if (value is Iterable) { 1644 if (value is Iterable) {
1568 return value.map(_deepToSymbol).toList(); 1645 return value.map(_deepToSymbol).toList();
1569 } 1646 }
1570 return value; 1647 return value;
1571 } 1648 }
1572 1649
OLDNEW
« no previous file with comments | « pkg/mdv/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698