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