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