OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2013, 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 <!-- | 9 <!-- |
10 This test runs the TodoMVC app, adds a few todos, marks some as done | 10 This test runs the TodoMVC app, adds a few todos, marks some as done |
11 programatically, and clicks on a checkbox to mark others via the UI. | 11 programatically, and clicks on a checkbox to mark others via the UI. |
12 --> | 12 --> |
13 <meta charset="utf-8"> | 13 <meta charset="utf-8"> |
14 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | 14 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
15 <link rel="import" href="../web/app.html"> | 15 <link rel="import" href="../web/app.html"> |
16 <link rel="stylesheet" href="../web/base.css"> | 16 <link rel="stylesheet" href="../web/base.css"> |
17 <script src="packages/polymer/testing/testing.js"></script> | 17 <script src="packages/polymer/testing/testing.js"></script> |
18 <title>Dart • TodoMVC</title> | 18 <title>Dart • TodoMVC</title> |
19 </head><body> | 19 </head><body> |
20 <todo-app></todo-app> | 20 <todo-app></todo-app> |
21 <script type="application/dart"> | 21 <script type="application/dart"> |
22 import 'dart:async'; | |
23 import 'dart:html'; | 22 import 'dart:html'; |
24 import 'package:mdv/mdv.dart' as mdv; | |
25 import 'package:observe/observe.dart'; | |
26 import 'package:unittest/unittest.dart'; | 23 import 'package:unittest/unittest.dart'; |
27 import 'package:polymer/polymer.dart'; | 24 import 'package:polymer/polymer.dart'; |
28 import '../web/model.dart'; | 25 import '../web/model.dart'; |
29 | 26 |
30 Node findWithText(Node node, String text) { | 27 Node findWithText(Node node, String text) { |
31 if (node.text == text) return node; | 28 if (node.text == text) return node; |
32 if (node is Element && (node as Element).localName == 'polymer-element') { | 29 if (node is Element && (node as Element).localName == 'polymer-element') { |
33 return null; | 30 return null; |
34 } | 31 } |
35 if (node is Element && (node as Element).shadowRoot != null) { | 32 if (node is Element && (node as Element).shadowRoot != null) { |
(...skipping 17 matching lines...) Expand all Loading... |
53 } | 50 } |
54 } | 51 } |
55 for (var n in node.nodes) { | 52 for (var n in node.nodes) { |
56 var r = findShadowHost(n, root); | 53 var r = findShadowHost(n, root); |
57 if (r != null) return r; | 54 if (r != null) return r; |
58 } | 55 } |
59 return null; | 56 return null; |
60 } | 57 } |
61 | 58 |
62 main() { | 59 main() { |
63 mdv.initialize(); | 60 appModel.todos.add(new Todo('one (unchecked)')); |
| 61 appModel.todos.add(new Todo('two (unchecked)')); |
| 62 appModel.todos.add(new Todo('three (checked)')..done = true); |
| 63 appModel.todos.add(new Todo('four (checked)')); |
64 | 64 |
65 Timer.run(() { | 65 performMicrotaskCheckpoint(); |
66 appModel.todos.add(new Todo('one (unchecked)')); | 66 var body = query('body'); |
67 appModel.todos.add(new Todo('two (unchecked)')); | |
68 appModel.todos.add(new Todo('three (checked)')..done = true); | |
69 appModel.todos.add(new Todo('four (checked)')); | |
70 | 67 |
71 // TODO(sigmund): investigate why is not enough to do Timer.run | 68 var label = findWithText(body, 'four (checked)'); |
72 new Timer(new Duration(milliseconds: 200), () { | 69 expect(label is LabelElement, isTrue, reason: 'text is in a label'); |
73 // Note: use query because "document" is unwrapped in ShadowDOM polyfill. | |
74 var body = query('body'); | |
75 | 70 |
76 var label = findWithText(body, 'four (checked)'); | 71 var host = findShadowHost(body, label.parentNode); |
77 expect(label is LabelElement, isTrue, reason: 'text is in a label'); | 72 var node = host.parent.query('input'); |
| 73 expect(node is InputElement, isTrue, reason: 'node is a checkbox'); |
| 74 expect(node.type, 'checkbox', reason: 'node type is checkbox'); |
| 75 expect(node.checked, isFalse, reason: 'element is unchecked'); |
78 | 76 |
79 var host = findShadowHost(body, label.parentNode); | 77 node.dispatchEvent(new MouseEvent('click', detail: 1)); |
80 var node = host.parent.query('input'); | 78 expect(node.checked, isTrue, reason: 'element is checked'); |
81 expect(node is InputElement, isTrue, reason: 'node is a checkbox'); | 79 performMicrotaskCheckpoint(); |
82 expect(node.type, 'checkbox', reason: 'node type is checkbox'); | |
83 expect(node.checked, isFalse, reason: 'element is unchecked'); | |
84 | 80 |
85 node.dispatchEvent(new MouseEvent('click', detail: 1)); | 81 window.postMessage('done', '*'); |
86 expect(node.checked, isTrue, reason: 'element is checked'); | |
87 | |
88 Timer.run(() { | |
89 window.postMessage('done', '*'); | |
90 }); | |
91 }); | |
92 }); | |
93 } | 82 } |
94 | 83 |
95 </script> | 84 </script> |
96 </body> | 85 </body> |
97 </html> | 86 </html> |
OLD | NEW |