Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: samples/third_party/todomvc/test/markdone_test.dart

Issue 77373002: "Reverting 30388" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/model.dart'; 12 import '../web/elements/td_model.dart';
13 import 'utils.dart';
13 14
14 Node findWithText(Node node, String text) { 15 Node findWithText(Node node, String text) {
15 if (node.text == text) return node; 16 if (node.text == text) return node;
16 if (node is Element && (node as Element).localName == 'polymer-element') { 17 if (node is Element && (node as Element).localName == 'polymer-element') {
17 return null; 18 return null;
18 } 19 }
19 if (node is Element && (node as Element).shadowRoot != null) { 20 if (node is Element && (node as Element).shadowRoot != null) {
20 var r = findWithText((node as Element).shadowRoot, text); 21 var r = findWithText((node as Element).shadowRoot, text);
21 if (r != null) return r; 22 if (r != null) return r;
22 } 23 }
23 for (var n in node.nodes) { 24 for (var n in node.nodes) {
24 var r = findWithText(n, text); 25 var r = findWithText(n, text);
25 if (r != null) return r; 26 if (r != null) return r;
26 } 27 }
27 return null; 28 return null;
28 } 29 }
29 30
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
46 /** 31 /**
47 * This test runs the TodoMVC app, adds a few todos, marks some as done 32 * This test runs the TodoMVC app, adds a few todos, marks some as done
48 * programatically, and clicks on a checkbox to mark others via the UI. 33 * programatically, and clicks on a checkbox to mark others via the UI.
49 */ 34 */
50 main() { 35 main() {
51 initPolymer(); 36 initPolymer();
52 useHtmlConfiguration(); 37 useHtmlConfiguration();
53 38
54 setUp(() => Polymer.onReady); 39 TodoModel model;
40
41 setUp(() => Polymer.onReady.then((_) {
42 model = querySelector('td-model');
43 return onPropertyInit(model, 'items');
44 }));
55 45
56 test('mark done', () { 46 test('mark done', () {
57 appModel.todos.add(new Todo('one (unchecked)')); 47 model.items
58 appModel.todos.add(new Todo('two (unchecked)')); 48 ..add(new Todo('one (unchecked)'))
59 appModel.todos.add(new Todo('three (checked)')..done = true); 49 ..add(new Todo('two (unchecked)'))
60 appModel.todos.add(new Todo('four (checked)')); 50 ..add(new Todo('three (checked)')..completed = true)
51 ..add(new Todo('four (checked)'));
61 52
62 return new Future(() { 53 return new Future(() {
63 var body = querySelector('body'); 54 var body = querySelector('body');
64 55
65 var label = findWithText(body, 'four (checked)'); 56 var label = findWithText(body, 'four (checked)');
66 expect(label is LabelElement, true, reason: 'text is in a label: $label'); 57 expect(label is LabelElement, true, reason: 'text is in a label: $label');
67 58
68 var host = findShadowHost(body, label.parentNode); 59 ShadowRoot host = label.parentNode.parentNode;
69 var node = host.parent.querySelector('input'); 60 var node = host.querySelector('input');
70 expect(node is InputElement, true, reason: 'node is a checkbox'); 61 expect(node is InputElement, true, reason: 'node is a checkbox');
71 expect(node.type, 'checkbox', reason: 'node type is checkbox'); 62 expect(node.type, 'checkbox', reason: 'node type is checkbox');
72 expect(node.checked, isFalse, reason: 'element is unchecked'); 63 expect(node.checked, isFalse, reason: 'element is unchecked');
73 64
74 node.dispatchEvent(new MouseEvent('click', detail: 1)); 65 node.dispatchEvent(new MouseEvent('click', detail: 1));
75 expect(node.checked, true, reason: 'element is checked'); 66 expect(node.checked, true, reason: 'element is checked');
76 }); 67 });
77 }); 68 });
78 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698