Merge branch 'per-axis-grid' of https://github.com/sauter-hq/dygraphs into per-axis...
[dygraphs.git] / auto_tests / misc / local.html
CommitLineData
7165f97b 1<!-- A local source file that allows dygraph developers to test locally. -->
644eff8b
RK
2<html>
3<head>
7165f97b
RK
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]-->
8d3d15af 9 <script type="text/javascript" src="../../dygraph-dev.js"></script>
7165f97b 10
6c8003d8 11 <!-- Scripts for library support -->
7165f97b
RK
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>
72a74f04 17 <script type="text/javascript" src="../tests/DygraphOps.js"></script>
9f636500 18 <script type="text/javascript" src="../tests/PixelSampler.js"></script>
fa607ffb 19 <script type="text/javascript" src="../tests/Util.js"></script>
6c8003d8
RK
20
21 <!-- Scripts for automated tests -->
6a4587ac 22 <script type="text/javascript" src="../tests/annotations.js"></script>
6d6c60b6 23 <script type="text/javascript" src="../tests/axis_labels.js"></script>
3d3001cf 24 <script type="text/javascript" src="../tests/axis_labels-deprecated.js"></script>
6a4587ac
RK
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>
cd872296 29 <script type="text/javascript" src="../tests/dygraph-options-tests.js"></script>
6a4587ac
RK
30 <script type="text/javascript" src="../tests/error_bars.js"></script>
31 <script type="text/javascript" src="../tests/formats.js"></script>
4a0567da 32 <script type="text/javascript" src="../tests/grid_per_axis.js"></script>
9c831431 33 <script type="text/javascript" src="../tests/interaction_model.js"></script>
cea0fb70 34 <script type="text/javascript" src="../tests/missing_points.js"></script>
6a4587ac 35 <script type="text/javascript" src="../tests/multi_csv.js"></script>
71e72c82 36 <script type="text/javascript" src="../tests/multiple_axes.js"></script>
08c74b2d 37 <script type="text/javascript" src="../tests/multiple_axes-old.js"></script>
8e19509a 38 <script type="text/javascript" src="../tests/numeric-labels.js"></script>
6a4587ac 39 <script type="text/javascript" src="../tests/no_hours.js"></script>
6c8003d8 40 <script type="text/javascript" src="../tests/parser.js"></script>
6a4587ac 41 <script type="text/javascript" src="../tests/pathological_cases.js"></script>
f112135d 42 <script type="text/javascript" src="../tests/per_series.js"></script>
63623c70 43 <script type="text/javascript" src="../tests/plugins.js"></script>
6c8003d8 44 <script type="text/javascript" src="../tests/range_selector.js"></script>
6a4587ac
RK
45 <script type="text/javascript" src="../tests/range_tests.js"></script>
46 <script type="text/javascript" src="../tests/rolling_average.js"></script>
47 <script type="text/javascript" src="../tests/sanity.js"></script>
6a4587ac
RK
48 <script type="text/javascript" src="../tests/scientific_notation.js"></script>
49 <script type="text/javascript" src="../tests/scrolling_div.js"></script>
6c8003d8 50 <script type="text/javascript" src="../tests/selection.js"></script>
6a4587ac 51 <script type="text/javascript" src="../tests/simple_drawing.js"></script>
5546c2e3 52 <script type="text/javascript" src="../tests/step_plot_per_series.js"></script>
6c8003d8 53 <script type="text/javascript" src="../tests/stacked.js"></script>
0842b24b 54 <!--
48e614ac 55 <script type="text/javascript" src="../tests/tickers.js"></script>
0842b24b 56 -->
6a4587ac 57 <script type="text/javascript" src="../tests/to_dom_coords.js"></script>
24f7710b 58 <script type="text/javascript" src="../tests/resize.js"></script>
9ca829f2 59 <script type="text/javascript" src="../tests/update_options.js"></script>
6c8003d8 60 <script type="text/javascript" src="../tests/update_while_panning.js"></script>
48e614ac 61 <script type="text/javascript" src="../tests/utils_test.js"></script>
87bbdb4d 62
5cfed8c5
RK
63<style type="text/css">
64 .pass .outcome {
65 color: green;
66 }
67
68 .fail .outcome {
69 color: red;
70 }
87bbdb4d 71
5cfed8c5
RK
72 .activeAnchor {
73 color: black;
74 text-decoration: none;
75 }
76</style>
6788e30b 77 <script type="text/javascript">
fa607ffb
RK
78
79 // save Dygraph.warn so we can catch warnings.
7db3d60b
RK
80 if (false) { // Set true if you want warnings to cause failures.
81 var originalDygraphWarn = Dygraph.warn;
82 Dygraph.warn = function(msg) {
83 if (msg == "Using default labels. Set labels explicitly via 'labels' in the options parameter") {
84 originalDygraphWarn(msg);
85 return;
86 }
87 throw "Warnings not permitted: " + msg;
88 }
89 Dygraph.prototype.warn = Dygraph.warn;
90 }
fa607ffb 91
b43b50fe
RK
92 var tc = null; // Selected test case
93 var name = null;
5cfed8c5
RK
94
95 var resultDiv = null;
96
6788e30b
RK
97 function processVariables() {
98 var splitVariables = function() { // http://www.idealog.us/2006/06/javascript_to_p.html
99 var query = window.location.search.substring(1);
100 var args = {};
101 var vars = query.split("&");
3d8093fa
RK
102 for (var i = 0; i < vars.length; i++) {
103 if (vars[i].length > 0) {
104 var pair = vars[i].split("=");
105 args[pair[0]] = pair[1];
106 }
6788e30b
RK
107 }
108 return args;
109 }
110
111 var args = splitVariables();
112 var test = args.test;
113 var command = args.command;
114
ef13835b 115 // args.testCaseName uses the string name of the test.
357f7a8a
RK
116 if (args.testCaseName) {
117 var testCases = getAllTestCases();
0c393397 118 name = args.testCaseName;
357f7a8a
RK
119 for (var idx in testCases) {
120 var entry = testCases[idx];
121 if (entry.name == args.testCaseName) {
122 var prototype = entry.testCase;
123 tc = new entry.testCase();
124 break;
125 }
126 }
ef13835b 127 } else if (args.testCase) { // The class name of the test.
0c393397 128 name = args.testCase;
6788e30b 129 eval("tc = new " + args.testCase + "()");
357f7a8a 130 }
ef13835b 131
5cfed8c5 132 var results = null;
ef13835b 133 // If the test class is defined.
357f7a8a 134 if (tc != null) {
ef13835b
RK
135 if (args.command == "runAllTests") {
136 console.log("Running all tests for " + args.testCase);
5cfed8c5
RK
137 results = tc.runAllTests();
138 } else if (args.command == "runTest") {
ef13835b 139 console.log("Running test " + args.testCase + "." + args.test);
5cfed8c5 140 results = tc.runTest(args.test);
ef13835b
RK
141 }
142 } else {
143 if (args.command == "runAllTests") {
144 console.log("Running all tests for all test cases");
145 var testCases = getAllTestCases();
5cfed8c5 146 results = {};
ef13835b
RK
147 for (var idx in testCases) {
148 var entry = testCases[idx];
149 var prototype = entry.testCase;
150 tc = new entry.testCase();
151 results[entry.name] = tc.runAllTests();
6788e30b
RK
152 }
153 }
154 }
5cfed8c5 155 resultsDiv = createResultsDiv();
b43b50fe
RK
156 var summary = { failed: 0, passed: 0 };
157 postResults(results, summary);
5cfed8c5 158 resultsDiv.appendChild(document.createElement("hr"));
0bdbfaf3 159 document.getElementById('summary').innerHTML = "(" + summary.failed + " failed, " + summary.passed + " passed)";
6788e30b 160 }
da11a9a7 161
5cfed8c5
RK
162 function createResultsDiv() {
163 var body = document.getElementsByTagName("body")[0];
164 div = document.createElement("div");
165 div.id='results';
825a47fc 166 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/>";
5cfed8c5
RK
167 body.insertBefore(div, body.firstChild);
168
169 var setByClassName = function(name, displayStyle) {
170 var elements = div.getElementsByClassName(name);
171 for (var i = 0; i < elements.length; i++) {
172 elements[i].style.display = displayStyle;
ef13835b 173 }
ef13835b 174 }
da11a9a7 175
5cfed8c5
RK
176 var passedAnchor = document.getElementById('passed');
177 var failedAnchor = document.getElementById('failed');
178 var allAnchor = document.getElementById('all');
179 passedAnchor.onclick = function() {
180 setByClassName('fail', 'none');
181 setByClassName('pass', 'block');
182
183 passedAnchor.setAttribute("class", 'activeAnchor');
184 failedAnchor.setAttribute("class", '');
185 };
186 failedAnchor.onclick = function() {
187 setByClassName('fail', 'block');
188 setByClassName('pass', 'none');
189 passedAnchor.setAttribute("class", '');
190 failedAnchor.setAttribute("class", 'activeAnchor');
191 };
192 allAnchor.onclick = function() {
193 setByClassName('fail', 'block');
194 setByClassName('pass', 'block');
195 passedAnchor.setAttribute("class", '');
196 failedAnchor.setAttribute("class", '');
197 };
198 return div;
199 }
da11a9a7 200
b43b50fe 201 function postResults(results, summary, title) {
da11a9a7 202 if (typeof(results) == "boolean") {
ef13835b 203 var elem = document.createElement("div");
5cfed8c5
RK
204 elem.setAttribute("class", results ? 'pass' : 'fail');
205
206 var prefix = title ? (title + ": ") : "";
207 elem.innerHTML = prefix + '<span class=\'outcome\'>' + (results ? 'pass' : 'fail') + '</span>';
208 resultsDiv.appendChild(elem);
b43b50fe
RK
209 if (results) {
210 summary.passed++;
211 } else {
212 summary.failed++;
213 }
da11a9a7 214 } else { // hash
825a47fc 215 var failed = 0;
da11a9a7
RK
216 var html = "";
217 for (var key in results) {
218 if (results.hasOwnProperty(key)) {
ef13835b
RK
219 var elem = results[key];
220 if (typeof(elem) == "boolean" && title) {
b43b50fe 221 postResults(results[key], summary, title + "." + key);
ef13835b 222 } else {
b43b50fe 223 postResults(results[key], summary, key);
ef13835b 224 }
da11a9a7
RK
225 }
226 }
da11a9a7 227 }
da11a9a7 228 }
5cfed8c5 229
6788e30b 230 </script>
644eff8b
RK
231</head>
232<body>
233 <div id='graph'></div>
33933283 234 <div id="selector"></div>
3914c8e1 235 <p>This file is really nothing more than all the tests coalesced into a single
33933283
RK
236 HTML file. To run a test, use the selector above, or
237 open a Javascript console and execute, for instance,</p>
3914c8e1 238 <code>testDrawSimpleRangePlusOne()</code>
6788e30b
RK
239
240 <p>Alternatively you can use query args: <ul>
33933283
RK
241 <li>testCase - for the name of the test case prototype
242 <li>testCaseName - for the name of the test case
6788e30b
RK
243 <li>test - for the name of the test (use command=runTest)
244 <li>command - either runTest or runAllTests.
245 </ul>
246 Example: <code>local.html?testCase=ScrollingDivTestCase&test=testNestedDiv_Scrolled&command=runTest</code>
357f7a8a 247 <p/>
644eff8b 248</body>
6788e30b
RK
249<script>
250processVariables();
3914c8e1 251addGlobalTestSymbols();
357f7a8a 252
357f7a8a 253var selector = document.getElementById("selector");
0c393397 254
357f7a8a 255if (selector != null) { // running a test
da11a9a7
RK
256 var createAttached = function(name, parent) {
257 var elem = document.createElement(name);
258 parent.appendChild(elem);
259 return elem;
260 }
261
357f7a8a
RK
262 var description = createAttached("div", selector);
263 var list = createAttached("ul", selector);
264 var parent = list.parentElement;
da11a9a7 265 var createLink = function(parent, text, url) {
5cfed8c5
RK
266 var li = createAttached("li", parent);
267 var a = createAttached("a", li);
0bdbfaf3 268 a.innerHTML = text;
5cfed8c5 269 a.href = url;
da11a9a7 270 }
357f7a8a
RK
271 if (tc == null) {
272 description.innerHTML = "Test cases:";
273 var testCases = getAllTestCases();
ef13835b 274 createLink(list, "(run all tests)", document.URL + "?command=runAllTests");
357f7a8a 275 for (var idx in testCases) {
da11a9a7
RK
276 var entryName = testCases[idx].name;
277 createLink(list, entryName, document.URL + "?testCaseName=" + entryName);
357f7a8a
RK
278 }
279 } else {
280 description.innerHTML = "Tests for " + name;
281 var names = tc.getTestNames();
da11a9a7 282 createLink(list, "Run All Tests", document.URL + "&command=runAllTests");
357f7a8a
RK
283 for (var idx in names) {
284 var name = names[idx];
da11a9a7 285 createLink(list, name, document.URL + "&test=" + name + "&command=runTest");
357f7a8a
RK
286 }
287 }
288}
6788e30b 289</script>
644eff8b 290</html>