| 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 library todomvc.test.markdone_test; | 5 library todomvc.test.markdone_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'package:polymer/polymer.dart'; | 9 import 'package:polymer/polymer.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:unittest/html_config.dart'; | 11 import 'package:unittest/html_config.dart'; |
| 12 import '../web/elements/td_model.dart'; | 12 import '../web/model.dart'; |
| 13 import 'utils.dart'; | |
| 14 | 13 |
| 15 Node findWithText(Node node, String text) { | 14 Node findWithText(Node node, String text) { |
| 16 if (node.text == text) return node; | 15 if (node.text == text) return node; |
| 17 if (node is Element && (node as Element).localName == 'polymer-element') { | 16 if (node is Element && (node as Element).localName == 'polymer-element') { |
| 18 return null; | 17 return null; |
| 19 } | 18 } |
| 20 if (node is Element && (node as Element).shadowRoot != null) { | 19 if (node is Element && (node as Element).shadowRoot != null) { |
| 21 var r = findWithText((node as Element).shadowRoot, text); | 20 var r = findWithText((node as Element).shadowRoot, text); |
| 22 if (r != null) return r; | 21 if (r != null) return r; |
| 23 } | 22 } |
| 24 for (var n in node.nodes) { | 23 for (var n in node.nodes) { |
| 25 var r = findWithText(n, text); | 24 var r = findWithText(n, text); |
| 26 if (r != null) return r; | 25 if (r != null) return r; |
| 27 } | 26 } |
| 28 return null; | 27 return null; |
| 29 } | 28 } |
| 30 | 29 |
| 30 Node findShadowHost(Node node, ShadowRoot root) { |
| 31 if (node is Element) { |
| 32 var shadowRoot = (node as Element).shadowRoot; |
| 33 if (shadowRoot == root) return node; |
| 34 if (shadowRoot != null) { |
| 35 var r = findShadowHost(shadowRoot, root); |
| 36 if (r != null) return r; |
| 37 } |
| 38 } |
| 39 for (var n in node.nodes) { |
| 40 var r = findShadowHost(n, root); |
| 41 if (r != null) return r; |
| 42 } |
| 43 return null; |
| 44 } |
| 45 |
| 31 /** | 46 /** |
| 32 * This test runs the TodoMVC app, adds a few todos, marks some as done | 47 * This test runs the TodoMVC app, adds a few todos, marks some as done |
| 33 * programatically, and clicks on a checkbox to mark others via the UI. | 48 * programatically, and clicks on a checkbox to mark others via the UI. |
| 34 */ | 49 */ |
| 35 main() { | 50 main() { |
| 36 initPolymer(); | 51 initPolymer(); |
| 37 useHtmlConfiguration(); | 52 useHtmlConfiguration(); |
| 38 | 53 |
| 39 TodoModel model; | 54 setUp(() => Polymer.onReady); |
| 40 | |
| 41 setUp(() => Polymer.onReady.then((_) { | |
| 42 model = querySelector('td-model'); | |
| 43 return onPropertyInit(model, 'items'); | |
| 44 })); | |
| 45 | 55 |
| 46 test('mark done', () { | 56 test('mark done', () { |
| 47 model.items | 57 appModel.todos.add(new Todo('one (unchecked)')); |
| 48 ..add(new Todo('one (unchecked)')) | 58 appModel.todos.add(new Todo('two (unchecked)')); |
| 49 ..add(new Todo('two (unchecked)')) | 59 appModel.todos.add(new Todo('three (checked)')..done = true); |
| 50 ..add(new Todo('three (checked)')..completed = true) | 60 appModel.todos.add(new Todo('four (checked)')); |
| 51 ..add(new Todo('four (checked)')); | |
| 52 | 61 |
| 53 return new Future(() { | 62 return new Future(() { |
| 54 var body = querySelector('body'); | 63 var body = querySelector('body'); |
| 55 | 64 |
| 56 var label = findWithText(body, 'four (checked)'); | 65 var label = findWithText(body, 'four (checked)'); |
| 57 expect(label is LabelElement, true, reason: 'text is in a label: $label'); | 66 expect(label is LabelElement, true, reason: 'text is in a label: $label'); |
| 58 | 67 |
| 59 ShadowRoot host = label.parentNode.parentNode; | 68 var host = findShadowHost(body, label.parentNode); |
| 60 var node = host.querySelector('input'); | 69 var node = host.parent.querySelector('input'); |
| 61 expect(node is InputElement, true, reason: 'node is a checkbox'); | 70 expect(node is InputElement, true, reason: 'node is a checkbox'); |
| 62 expect(node.type, 'checkbox', reason: 'node type is checkbox'); | 71 expect(node.type, 'checkbox', reason: 'node type is checkbox'); |
| 63 expect(node.checked, isFalse, reason: 'element is unchecked'); | 72 expect(node.checked, isFalse, reason: 'element is unchecked'); |
| 64 | 73 |
| 65 node.dispatchEvent(new MouseEvent('click', detail: 1)); | 74 node.dispatchEvent(new MouseEvent('click', detail: 1)); |
| 66 expect(node.checked, true, reason: 'element is checked'); | 75 expect(node.checked, true, reason: 'element is checked'); |
| 67 }); | 76 }); |
| 68 }); | 77 }); |
| 69 } | 78 } |
| OLD | NEW |