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