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