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