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