| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 for details. All rights reserved. Use of this source code is governed by a | 4 for details. All rights reserved. Use of this source code is governed by a |
| 5 BSD-style license that can be found in the LICENSE file. | 5 BSD-style license that can be found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 <html lang="en"> | 7 <html lang="en"> |
| 8 <head> | 8 <head> |
| 9 <meta charset="utf-8"> | 9 <meta charset="utf-8"> |
| 10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | 10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 11 <script src="packages/web_ui/testing/testing.js"></script> | 11 <script src="packages/web_ui/testing/testing.js"></script> |
| 12 </head> | 12 </head> |
| 13 <body> | 13 <body> |
| 14 <!-- Tests the correct interaction of iteration and conditionals. --> | 14 <!-- Tests that repeat and template attribute work. --> |
| 15 <table> | 15 <table> |
| 16 <tbody id='test' template iterate="row in table"> | 16 <tbody id='test'> |
| 17 <tr template iterate="cell in row"> | 17 <tr template repeat="row in table"> |
| 18 <td template if="cell != 0">{{cell}}</td> | 18 <td template repeat="cell in row.where((c) => c != 0)">{{cell}}</td> |
| 19 </tr> | 19 </tr> |
| 20 </tbody></table> | 20 </tbody> |
| 21 </table> |
| 21 <script type="application/dart"> | 22 <script type="application/dart"> |
| 22 import 'dart:async'; | 23 import 'dart:async'; |
| 23 import 'dart:html'; | 24 import 'dart:html'; |
| 24 import 'package:unittest/unittest.dart'; | 25 import 'package:unittest/unittest.dart'; |
| 25 import 'package:web_ui/observe.dart'; | 26 import 'package:web_ui/observe.dart'; |
| 26 | 27 |
| 27 @observable | 28 @observable |
| 28 List<List> table = toObservable([ | 29 List<List> table = toObservable([ |
| 29 toObservable([1, 2, 3]), | 30 toObservable([1, 2, 3]), |
| 30 toObservable([4, 0, 5]), | 31 toObservable([4, 0, 5]), |
| 31 toObservable([0, 2, 4]) | 32 toObservable([0, 2, 4]) |
| 32 ]); | 33 ]); |
| 33 | 34 |
| 34 main() { | 35 main() { |
| 35 Timer.run(() { | 36 Timer.run(() { |
| 36 table[1][1] = 9; | 37 table[1][1] = 9; |
| 37 Timer.run(() { | 38 Timer.run(() { |
| 38 var test = document.query('#test'); | 39 var test = document.query('#test'); |
| 39 expect(test.children.length, table.length); | 40 expect(test.children.length, table.length + 1); |
| 41 expect(test.children[0].style.display, 'none'); |
| 40 for (int row = 0; row < table.length; row++) { | 42 for (int row = 0; row < table.length; row++) { |
| 41 var tr = test.children[row]; | 43 var tr = test.children[row + 1]; |
| 42 expect(tr.tagName, 'TR'); | 44 expect(tr.tagName, 'TR'); |
| 43 int column = -1; | 45 |
| 44 for (var td in tr.children) { | 46 var filtered = table[row].where((c) => c != 0).toList(); |
| 47 expect(tr.children.length, filtered.length + 1); |
| 48 expect(tr.children[0].style.display, 'none'); |
| 49 |
| 50 for (int col = 0; col < filtered.length; col++) { |
| 51 var td = tr.children[col + 1]; |
| 45 expect(td.tagName, 'TD'); | 52 expect(td.tagName, 'TD'); |
| 46 if (td.style.display == 'none') { | 53 expect(td.innerHtml, filtered[col].toString()); |
| 47 column++; | |
| 48 continue; | |
| 49 } | |
| 50 | |
| 51 var value = table[row][column]; | |
| 52 expect(value, greaterThan(0)); | |
| 53 expect(td.innerHtml, value.toString()); | |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 window.postMessage('done', '*'); | 56 window.postMessage('done', '*'); |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 </script> | 60 </script> |
| 61 </body> | 61 </body> |
| 62 </html> | 62 </html> |
| OLD | NEW |