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

Side by Side Diff: client/tests/client/samples/swarm/swarm_tests.dart

Issue 8345023: Clean up swarm tests to new API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('swarm_tests'); 5 #library('swarm_tests');
6 6
7 #import('../../../../base/base.dart'); 7 #import('../../../../base/base.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 #import('../../../../samples/swarm/swarmlib.dart'); 9 #import('../../../../samples/swarm/swarmlib.dart');
10 #import('../../../../testing/unittest/unittest.dart'); 10 #import('../../../../testing/unittest/unittest.dart');
11 #import('../../../../view/view.dart'); 11 #import('../../../../view/view.dart');
12 #import('../../../../util/utilslib.dart'); 12 #import('../../../../util/utilslib.dart');
13 13
14 void main() {
15 new SwarmTests().run();
Siggi Cherem (dart-lang) 2011/10/18 22:26:50 it's so nice to get rid of this...
Bob Nystrom 2011/10/18 23:10:50 Yes!
16 }
17
18 // TODO(jmesserly): these would probably be easier to debug if they were written 14 // TODO(jmesserly): these would probably be easier to debug if they were written
19 // in the WebKit layout test style, so we could easy compare that the DOM is 15 // in the WebKit layout test style, so we could easy compare that the DOM is
20 // what we expect it to be after performing some simulated user actions. 16 // what we expect it to be after performing some simulated user actions.
21 17
22 class SwarmTests extends UnitTestSuite { 18 void main() {
23 Swarm swarm; 19 Swarm swarm = new Swarm();
24 UIStateProxy state; 20 UIStateProxy state = new UIStateProxy(swarm.sections);
21 swarm.state = state;
22 swarm.run();
25 23
26 SwarmTests() : super() { 24 // TODO(jmesserly): should be adding the full stylesheet here
27 swarm = new Swarm(); 25 Dom.addStyle('''
28 swarm.state = state = new UIStateProxy(swarm.sections); 26 .story-content {
29 swarm.run(); 27 -webkit-column-width: 300px;
30 } 28 -webkit-column-gap: 26px; /* 2em */
29 }''');
31 30
32 Element get storyNode() => swarm.frontView.storyView.node; 31 getStoryNode() => swarm.frontView.storyView.node;
33 32
34 View getView(Section section) { 33 getView(Section section) {
35 return CollectionUtils.find(swarm.frontView.sections.childViews, 34 return CollectionUtils.find(swarm.frontView.sections.childViews,
36 (view) => view.section == section); 35 (view) => view.section == section);
37 } 36 }
38 37
39 Map<String, String> getHistory(Article article) { 38 getHistory(Article article) {
40 final feed = article.dataSource; 39 final feed = article.dataSource;
41 return { 40 return {
42 'section': CollectionUtils.find(swarm.sections, 41 'section': CollectionUtils.find(swarm.sections,
43 (s) => s.feeds.indexOf(feed, 0) >= 0).id, 42 (s) => s.feeds.indexOf(feed, 0) >= 0).id,
44 'feed': feed.id, 43 'feed': feed.id,
45 'article': article.id 44 'article': article.id
46 }; 45 };
47 } 46 }
48 47
49 void setUpTestSuite() { 48 test('BackButton', () {
50 // TODO(jmesserly): should be adding the full stylesheet here
51 Dom.addStyle('''
52 .story-content {
53 -webkit-column-width: 300px;
54 -webkit-column-gap: 26px; /* 2em */
55 }''');
56 addTest(testBackButton);
57 addTest(testStoryView);
58 addTest(testSliderMenu);
59 }
60
61 /** Triggers the click event, like [http://api.jquery.com/click/] */
62 _click(Element element) {
63 // TODO(rnystrom): This should be on the DOM API somewhere.
64 MouseEvent event = document.createEvent('MouseEvents');
65 event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0,
66 false, false, false, false, 0, null);
67 element.on.click.dispatch(event);
68 }
69
70 void testBackButton() {
71 Expect.equals(null, swarm.frontView.storyView); // verify initial state 49 Expect.equals(null, swarm.frontView.storyView); // verify initial state
72 50
73 // Make sure we've transitioned to the section 51 // Make sure we've transitioned to the section
74 // In the real app, this isn't needed because ConveyorView fires the 52 // In the real app, this isn't needed because ConveyorView fires the
75 // transition end event before we can click a story. 53 // transition end event before we can click a story.
76 SectionView section = getView(swarm.sections[0]); 54 SectionView section = getView(swarm.sections[0]);
77 section.showSources(); 55 section.showSources();
78 56
79 final item = swarm.sections[0].feeds[2].articles[1]; 57 final item = swarm.sections[0].feeds[2].articles[1];
80 state.loadFromHistory(getHistory(item)); 58 state.loadFromHistory(getHistory(item));
81 59
82 Expect.equals(item, state.currentArticle.value); 60 Expect.equals(item, state.currentArticle.value);
83 61
84 Expect.isFalse(storyNode.classes.contains(CSS.HIDDEN_STORY)); 62 Expect.isFalse(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
85 63
86 state.loadFromHistory({}); 64 state.loadFromHistory({});
87 65
88 Expect.equals(null, state.currentArticle.value); 66 Expect.equals(null, state.currentArticle.value);
89 Expect.isTrue(storyNode.classes.contains(CSS.HIDDEN_STORY)); 67 Expect.isTrue(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
90 } 68 });
91 69
92 void testStoryView() { 70 test('StoryView', () {
93 state.clearHistory(); 71 state.clearHistory();
94 72
95 Expect.isTrue(storyNode.classes.contains(CSS.HIDDEN_STORY)); 73 Expect.isTrue(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
96 74
97 final dataSourceView = 75 final dataSourceView =
98 swarm.frontView.currentSection.dataSourceView.getSubview(0); 76 swarm.frontView.currentSection.dataSourceView.getSubview(0);
99 final itemView = dataSourceView.itemsView.getSubview(0); 77 final itemView = dataSourceView.itemsView.getSubview(0);
100 // TODO(jacobr): remove this null check. This is likely due to tests 78 // TODO(jacobr): remove this null check. This is likely due to tests
101 // running without the correct CSS to size the window so that some items 79 // running without the correct CSS to size the window so that some items
102 // are visible. 80 // are visible.
103 if (itemView != null) { 81 if (itemView != null) {
104 _click(itemView.node); 82 click(itemView.node);
105 state.expectHistory([getHistory(itemView.item)]); 83 state.expectHistory([getHistory(itemView.item)]);
106 } 84 }
107 } 85 });
108 86
109 void testSliderMenu() { 87 test('SliderMenu', () {
110 Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection); 88 Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection);
111 89
112 // Find the first slider menu item, and click on the one next after it. 90 // Find the first slider menu item, and click on the one next after it.
113 _click(document.queryAll('.${CSS.SM_ITEM}')[1]); 91 click(document.queryAll('.${CSS.SM_ITEM}')[1]);
114 92
115 Expect.equals(getView(swarm.sections[1]), swarm.frontView.currentSection); 93 Expect.equals(getView(swarm.sections[1]), swarm.frontView.currentSection);
116 94
117 // Find the first menu item again and click on it. 95 // Find the first menu item again and click on it.
118 _click(document.query('.${CSS.SM_ITEM}')); 96 click(document.query('.${CSS.SM_ITEM}'));
119 97
120 Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection); 98 Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection);
121 } 99 });
122 } 100 }
123 101
102 /** Triggers the click event, like [http://api.jquery.com/click/] */
103 click(Element element) {
Siggi Cherem (dart-lang) 2011/10/18 22:26:50 any reason to make this public (_click seemed ok)?
Jennifer Messerly 2011/10/18 22:46:01 Agree. But even better would be to have this in t
Bob Nystrom 2011/10/18 23:10:50 I made it public just because most of the other te
104 // TODO(rnystrom): This should be on the DOM API somewhere.
105 MouseEvent event = document.createEvent('MouseEvents');
106 event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0,
107 false, false, false, false, 0, null);
108 element.on.click.dispatch(event);
109 }
110
111
124 /** A proxy so we can intercept history calls */ 112 /** A proxy so we can intercept history calls */
125 class UIStateProxy extends SwarmState { 113 class UIStateProxy extends SwarmState {
126 List<Map<String, String>> history; 114 List<Map<String, String>> history;
127 115
128 UIStateProxy(Sections dataModel) : super(dataModel) { 116 UIStateProxy(Sections dataModel) : super(dataModel) {
129 clearHistory(); 117 clearHistory();
130 } 118 }
131 119
132 void pushToHistory() { 120 void pushToHistory() {
133 history.add(toHistory()); 121 history.add(toHistory());
134 super.pushToHistory(); 122 super.pushToHistory();
135 } 123 }
136 124
137 void clearHistory() { 125 void clearHistory() {
138 history = new List<Map<String, String>>(); 126 history = new List<Map<String, String>>();
139 } 127 }
140 128
141 void expectHistory(List<Map<String, String>> entries) { 129 void expectHistory(List<Map<String, String>> entries) {
142 Expect.equals(entries.length, history.length); 130 Expect.equals(entries.length, history.length);
143 for (int i = 0; i < entries.length; i++) { 131 for (int i = 0; i < entries.length; i++) {
144 Map e = entries[i]; 132 Map e = entries[i];
145 Map h = history[i]; 133 Map h = history[i];
146 Expect.equals(e['article'], h['article']); 134 Expect.equals(e['article'], h['article']);
147 } 135 }
148 clearHistory(); 136 clearHistory();
149 } 137 }
150 } 138 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698