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