| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 import 'dart:html'; | |
| 7 | |
| 8 import 'package:observe/observe.dart'; | |
| 9 import 'package:observe/mirrors_used.dart'; // make test smaller. | |
| 10 import 'package:smoke/mirrors.dart' as smoke; | |
| 11 import 'package:polymer_expressions/polymer_expressions.dart'; | |
| 12 import 'package:template_binding/template_binding.dart'; | |
| 13 import 'package:unittest/unittest.dart'; | |
| 14 import 'package:unittest/html_config.dart'; | |
| 15 | |
| 16 main() { | |
| 17 useHtmlConfiguration(); | |
| 18 smoke.useMirrors(); | |
| 19 | |
| 20 var testDiv; | |
| 21 group('enumerate', () { | |
| 22 setUp(() { | |
| 23 testDiv = new Element.html(''' | |
| 24 <div id="test"> | |
| 25 <template bind> | |
| 26 <template repeat="{{entry in this | enumerate}}"> | |
| 27 <div>Item {{ entry.index }} is {{ entry.value }}</div> | |
| 28 </template> | |
| 29 </template> | |
| 30 </div>'''); | |
| 31 TemplateBindExtension.bootstrap(testDiv); | |
| 32 document.body.nodes.add(testDiv); | |
| 33 }); | |
| 34 | |
| 35 tearDown(() { | |
| 36 testDiv.remove(); | |
| 37 testDiv = null; | |
| 38 }); | |
| 39 | |
| 40 test('should enumerate item and index', () { | |
| 41 templateBind(testDiv.query('template')) | |
| 42 ..bindingDelegate = new PolymerExpressions() | |
| 43 ..model = toObservable( | |
| 44 ['hello', 'from', 'polymer', 'expressions']); | |
| 45 | |
| 46 return new Future(() { | |
| 47 expect(testDiv.queryAll('div').map((n) => n.text), [ | |
| 48 'Item 0 is hello', | |
| 49 'Item 1 is from', | |
| 50 'Item 2 is polymer', | |
| 51 'Item 3 is expressions', | |
| 52 ]); | |
| 53 }); | |
| 54 }); | |
| 55 | |
| 56 test('should update after changes', () { | |
| 57 var model = toObservable( | |
| 58 ['hello', 'from', 'polymer', 'expressions', 'a', 'b', 'c']); | |
| 59 | |
| 60 templateBind(testDiv.query('template')) | |
| 61 ..bindingDelegate = new PolymerExpressions() | |
| 62 ..model = model; | |
| 63 | |
| 64 return new Future(() { | |
| 65 expect(testDiv.queryAll('div').map((n) => n.text), [ | |
| 66 'Item 0 is hello', | |
| 67 'Item 1 is from', | |
| 68 'Item 2 is polymer', | |
| 69 'Item 3 is expressions', | |
| 70 'Item 4 is a', | |
| 71 'Item 5 is b', | |
| 72 'Item 6 is c', | |
| 73 ]); | |
| 74 | |
| 75 model.removeAt(1); | |
| 76 model[1] = 'world'; | |
| 77 model[2] = '!'; | |
| 78 model.insert(5, 'e'); | |
| 79 | |
| 80 return new Future(() { | |
| 81 expect(testDiv.queryAll('div').map((n) => n.text), [ | |
| 82 'Item 0 is hello', | |
| 83 'Item 1 is world', | |
| 84 'Item 2 is !', | |
| 85 'Item 3 is a', | |
| 86 'Item 4 is b', | |
| 87 'Item 5 is e', | |
| 88 'Item 6 is c', | |
| 89 ]); | |
| 90 }); | |
| 91 }); | |
| 92 }); | |
| 93 }); | |
| 94 } | |
| OLD | NEW |