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