Move common code to Util.js, reducing multiple-axes tests.
[dygraphs.git] / auto_tests / misc / local.html
... / ...
CommitLineData
1<!-- A local source file that allows dygraph developers to test locally. -->
2<html>
3<head>
4 <!-- Standard Dygraph scripts -->
5 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
6 <!--[if IE]>
7 <script type="text/javascript" src="../../excanvas.js"></script>
8 <![endif]-->
9 <script type="text/javascript" src="../../dygraph-dev.js"></script>
10
11 <!-- Scripts for library support -->
12 <script type="text/javascript" src="../lib/jquery-1.4.2.js"></script>
13 <script type="text/javascript" src="../lib/Asserts.js"></script>
14 <script type="text/javascript" src="fake-jstestdriver.js"></script>
15 <script type="text/javascript" src="../tests/Proxy.js"></script>
16 <script type="text/javascript" src="../tests/CanvasAssertions.js"></script>
17 <script type="text/javascript" src="../tests/DygraphOps.js"></script>
18 <script type="text/javascript" src="../tests/PixelSampler.js"></script>
19 <script type="text/javascript" src="../tests/Util.js"></script>
20
21 <!-- Scripts for automated tests -->
22 <script type="text/javascript" src="../tests/annotations.js"></script>
23 <script type="text/javascript" src="../tests/axis_labels.js"></script>
24 <script type="text/javascript" src="../tests/axis_labels-deprecated.js"></script>
25 <script type="text/javascript" src="../tests/callback.js"></script>
26 <script type="text/javascript" src="../tests/css.js"></script>
27 <script type="text/javascript" src="../tests/custom_bars.js"></script>
28 <script type="text/javascript" src="../tests/date_formats.js"></script>
29 <script type="text/javascript" src="../tests/error_bars.js"></script>
30 <script type="text/javascript" src="../tests/formats.js"></script>
31 <script type="text/javascript" src="../tests/interaction_model.js"></script>
32 <script type="text/javascript" src="../tests/labels.js"></script>
33 <script type="text/javascript" src="../tests/missing_points.js"></script>
34 <script type="text/javascript" src="../tests/multi_csv.js"></script>
35 <script type="text/javascript" src="../tests/multiple_axes.js"></script>
36 <script type="text/javascript" src="../tests/multiple_axes-old.js"></script>
37 <script type="text/javascript" src="../tests/no_hours.js"></script>
38 <script type="text/javascript" src="../tests/parser.js"></script>
39 <script type="text/javascript" src="../tests/pathological_cases.js"></script>
40 <script type="text/javascript" src="../tests/per_series.js"></script>
41 <script type="text/javascript" src="../tests/range_selector.js"></script>
42 <script type="text/javascript" src="../tests/range_tests.js"></script>
43 <script type="text/javascript" src="../tests/rolling_average.js"></script>
44 <script type="text/javascript" src="../tests/sanity.js"></script>
45 <script type="text/javascript" src="../tests/scientific_notation.js"></script>
46 <script type="text/javascript" src="../tests/scrolling_div.js"></script>
47 <script type="text/javascript" src="../tests/selection.js"></script>
48 <script type="text/javascript" src="../tests/simple_drawing.js"></script>
49 <script type="text/javascript" src="../tests/stacked.js"></script>
50 <!--
51 <script type="text/javascript" src="../tests/tickers.js"></script>
52 -->
53 <script type="text/javascript" src="../tests/to_dom_coords.js"></script>
54 <script type="text/javascript" src="../tests/update_options.js"></script>
55 <script type="text/javascript" src="../tests/update_while_panning.js"></script>
56 <script type="text/javascript" src="../tests/utils_test.js"></script>
57
58<style type="text/css">
59 .pass .outcome {
60 color: green;
61 }
62
63 .fail .outcome {
64 color: red;
65 }
66
67 .activeAnchor {
68 color: black;
69 text-decoration: none;
70 }
71</style>
72 <script type="text/javascript">
73
74 // save Dygraph.warn so we can catch warnings.
75 var originalDygraphWarn = Dygraph.warn;
76 Dygraph.warn = function(msg) {
77 if (msg == "Using default labels. Set labels explicitly via 'labels' in the options parameter") {
78 originalDygraphWarn(msg);
79 return;
80 }
81 throw "Warnings not permitted: " + msg;
82 }
83 Dygraph.prototype.warn = Dygraph.warn;
84
85 var tc = null; // Selected test case
86 var name = null;
87
88 var resultDiv = null;
89
90 function processVariables() {
91 var splitVariables = function() { // http://www.idealog.us/2006/06/javascript_to_p.html
92 var query = window.location.search.substring(1);
93 var args = {};
94 var vars = query.split("&");
95 for (var i = 0; i < vars.length; i++) {
96 if (vars[i].length > 0) {
97 var pair = vars[i].split("=");
98 args[pair[0]] = pair[1];
99 }
100 }
101 return args;
102 }
103
104 var args = splitVariables();
105 var test = args.test;
106 var command = args.command;
107
108 // args.testCaseName uses the string name of the test.
109 if (args.testCaseName) {
110 var testCases = getAllTestCases();
111 name = args.testCaseName;
112 for (var idx in testCases) {
113 var entry = testCases[idx];
114 if (entry.name == args.testCaseName) {
115 var prototype = entry.testCase;
116 tc = new entry.testCase();
117 break;
118 }
119 }
120 } else if (args.testCase) { // The class name of the test.
121 name = args.testCase;
122 eval("tc = new " + args.testCase + "()");
123 }
124
125 var results = null;
126 // If the test class is defined.
127 if (tc != null) {
128 if (args.command == "runAllTests") {
129 console.log("Running all tests for " + args.testCase);
130 results = tc.runAllTests();
131 } else if (args.command == "runTest") {
132 console.log("Running test " + args.testCase + "." + args.test);
133 results = tc.runTest(args.test);
134 }
135 } else {
136 if (args.command == "runAllTests") {
137 console.log("Running all tests for all test cases");
138 var testCases = getAllTestCases();
139 results = {};
140 for (var idx in testCases) {
141 var entry = testCases[idx];
142 var prototype = entry.testCase;
143 tc = new entry.testCase();
144 results[entry.name] = tc.runAllTests();
145 }
146 }
147 }
148 resultsDiv = createResultsDiv();
149 var summary = { failed: 0, passed: 0 };
150 postResults(results, summary);
151 resultsDiv.appendChild(document.createElement("hr"));
152 document.getElementById('summary').innerHTML = "(" + summary.failed + " failed, " + summary.passed + " passed)";
153 }
154
155 function createResultsDiv() {
156 var body = document.getElementsByTagName("body")[0];
157 div = document.createElement("div");
158 div.id='results';
159 div.innerHTML = "Test results: <span id='summary'></span> <a href='#' id='passed'>passed</a> <a href='#' id='failed'>failed</a> <a href='#' id='all'>all</a><br/>";
160 body.insertBefore(div, body.firstChild);
161
162 var setByClassName = function(name, displayStyle) {
163 var elements = div.getElementsByClassName(name);
164 for (var i = 0; i < elements.length; i++) {
165 elements[i].style.display = displayStyle;
166 }
167 }
168
169 var passedAnchor = document.getElementById('passed');
170 var failedAnchor = document.getElementById('failed');
171 var allAnchor = document.getElementById('all');
172 passedAnchor.onclick = function() {
173 setByClassName('fail', 'none');
174 setByClassName('pass', 'block');
175
176 passedAnchor.setAttribute("class", 'activeAnchor');
177 failedAnchor.setAttribute("class", '');
178 };
179 failedAnchor.onclick = function() {
180 setByClassName('fail', 'block');
181 setByClassName('pass', 'none');
182 passedAnchor.setAttribute("class", '');
183 failedAnchor.setAttribute("class", 'activeAnchor');
184 };
185 allAnchor.onclick = function() {
186 setByClassName('fail', 'block');
187 setByClassName('pass', 'block');
188 passedAnchor.setAttribute("class", '');
189 failedAnchor.setAttribute("class", '');
190 };
191 return div;
192 }
193
194 function postResults(results, summary, title) {
195 if (typeof(results) == "boolean") {
196 var elem = document.createElement("div");
197 elem.setAttribute("class", results ? 'pass' : 'fail');
198
199 var prefix = title ? (title + ": ") : "";
200 elem.innerHTML = prefix + '<span class=\'outcome\'>' + (results ? 'pass' : 'fail') + '</span>';
201 resultsDiv.appendChild(elem);
202 if (results) {
203 summary.passed++;
204 } else {
205 summary.failed++;
206 }
207 } else { // hash
208 var failed = 0;
209 var html = "";
210 for (var key in results) {
211 if (results.hasOwnProperty(key)) {
212 var elem = results[key];
213 if (typeof(elem) == "boolean" && title) {
214 postResults(results[key], summary, title + "." + key);
215 } else {
216 postResults(results[key], summary, key);
217 }
218 }
219 }
220 }
221 }
222
223 </script>
224</head>
225<body>
226 <div id='graph'></div>
227 <div id="selector"></div>
228 <p>This file is really nothing more than all the tests coalesced into a single
229 HTML file. To run a test, use the selector above, or
230 open a Javascript console and execute, for instance,</p>
231 <code>testDrawSimpleRangePlusOne()</code>
232
233 <p>Alternatively you can use query args: <ul>
234 <li>testCase - for the name of the test case prototype
235 <li>testCaseName - for the name of the test case
236 <li>test - for the name of the test (use command=runTest)
237 <li>command - either runTest or runAllTests.
238 </ul>
239 Example: <code>local.html?testCase=ScrollingDivTestCase&test=testNestedDiv_Scrolled&command=runTest</code>
240 <p/>
241</body>
242<script>
243processVariables();
244addGlobalTestSymbols();
245
246var selector = document.getElementById("selector");
247
248if (selector != null) { // running a test
249 var createAttached = function(name, parent) {
250 var elem = document.createElement(name);
251 parent.appendChild(elem);
252 return elem;
253 }
254
255 var description = createAttached("div", selector);
256 var list = createAttached("ul", selector);
257 var parent = list.parentElement;
258 var createLink = function(parent, text, url) {
259 var li = createAttached("li", parent);
260 var a = createAttached("a", li);
261 a.innerHTML = text;
262 a.href = url;
263 }
264 if (tc == null) {
265 description.innerHTML = "Test cases:";
266 var testCases = getAllTestCases();
267 createLink(list, "(run all tests)", document.URL + "?command=runAllTests");
268 for (var idx in testCases) {
269 var entryName = testCases[idx].name;
270 createLink(list, entryName, document.URL + "?testCaseName=" + entryName);
271 }
272 } else {
273 description.innerHTML = "Tests for " + name;
274 var names = tc.getTestNames();
275 createLink(list, "Run All Tests", document.URL + "&command=runAllTests");
276 for (var idx in names) {
277 var name = names[idx];
278 createLink(list, name, document.URL + "&test=" + name + "&command=runTest");
279 }
280 }
281}
282</script>
283</html>