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