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