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