1 <!-- A local source file that allows dygraph developers to test locally. --
>
4 <!-- Standard Dygraph scripts --
>
5 <meta http-equiv=
"X-UA-Compatible" content=
"IE=EmulateIE7; IE=EmulateIE9">
7 <script type=
"text/javascript" src=
"../../excanvas.js"></script>
9 <script type=
"text/javascript" src=
"../../dygraph-dev.js"></script>
11 <!-- Scripts for library support --
>
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>
20 <!-- Scripts for automated tests --
>
21 <script type=
"text/javascript" src=
"../tests/annotations.js"></script>
22 <script type=
"text/javascript" src=
"../tests/axis_labels.js"></script>
23 <script type=
"text/javascript" src=
"../tests/callback.js"></script>
24 <script type=
"text/javascript" src=
"../tests/css.js"></script>
25 <script type=
"text/javascript" src=
"../tests/custom_bars.js"></script>
26 <script type=
"text/javascript" src=
"../tests/date_formats.js"></script>
27 <script type=
"text/javascript" src=
"../tests/error_bars.js"></script>
28 <script type=
"text/javascript" src=
"../tests/formats.js"></script>
29 <script type=
"text/javascript" src=
"../tests/interaction_model.js"></script>
30 <script type=
"text/javascript" src=
"../tests/missing_points.js"></script>
31 <script type=
"text/javascript" src=
"../tests/multi_csv.js"></script>
32 <script type=
"text/javascript" src=
"../tests/multiple_axes.js"></script>
33 <script type=
"text/javascript" src=
"../tests/no_hours.js"></script>
34 <script type=
"text/javascript" src=
"../tests/parser.js"></script>
35 <script type=
"text/javascript" src=
"../tests/pathological_cases.js"></script>
36 <script type=
"text/javascript" src=
"../tests/per_series.js"></script>
37 <script type=
"text/javascript" src=
"../tests/range_selector.js"></script>
38 <script type=
"text/javascript" src=
"../tests/range_tests.js"></script>
39 <script type=
"text/javascript" src=
"../tests/rolling_average.js"></script>
40 <script type=
"text/javascript" src=
"../tests/sanity.js"></script>
41 <script type=
"text/javascript" src=
"../tests/scientific_notation.js"></script>
42 <script type=
"text/javascript" src=
"../tests/scrolling_div.js"></script>
43 <script type=
"text/javascript" src=
"../tests/selection.js"></script>
44 <script type=
"text/javascript" src=
"../tests/simple_drawing.js"></script>
45 <script type=
"text/javascript" src=
"../tests/stacked.js"></script>
47 <script type=
"text/javascript" src=
"../tests/tickers.js"></script>
49 <script type=
"text/javascript" src=
"../tests/to_dom_coords.js"></script>
50 <script type=
"text/javascript" src=
"../tests/update_options.js"></script>
51 <script type=
"text/javascript" src=
"../tests/update_while_panning.js"></script>
52 <script type=
"text/javascript" src=
"../tests/utils_test.js"></script>
54 <style type=
"text/css">
65 text-decoration: none;
68 <script type=
"text/javascript">
69 var tc = null; // Selected test case
74 function processVariables() {
75 var splitVariables = function() { // http://www.idealog.us/
2006/
06/javascript_to_p.html
76 var query = window.location.search.substring(
1);
78 var vars = query.split(
"&");
79 for (var i =
0; i < vars.length; i++) {
80 if (vars[i].length
> 0) {
81 var pair = vars[i].split(
"=");
82 args[pair[
0]] = pair[
1];
88 var args = splitVariables();
90 var command = args.command;
92 // args.testCaseName uses the string name of the test.
93 if (args.testCaseName) {
94 var testCases = getAllTestCases();
95 name = args.testCaseName;
96 for (var idx in testCases) {
97 var entry = testCases[idx];
98 if (entry.name == args.testCaseName) {
99 var prototype = entry.testCase;
100 tc = new entry.testCase();
104 } else if (args.testCase) { // The class name of the test.
105 name = args.testCase;
106 eval(
"tc = new " + args.testCase +
"()");
110 // If the test class is defined.
112 if (args.command ==
"runAllTests") {
113 console.log(
"Running all tests for " + args.testCase);
114 results = tc.runAllTests();
115 } else if (args.command ==
"runTest") {
116 console.log(
"Running test " + args.testCase +
"." + args.test);
117 results = tc.runTest(args.test);
120 if (args.command ==
"runAllTests") {
121 console.log(
"Running all tests for all test cases");
122 var testCases = getAllTestCases();
124 for (var idx in testCases) {
125 var entry = testCases[idx];
126 var prototype = entry.testCase;
127 tc = new entry.testCase();
128 results[entry.name] = tc.runAllTests();
132 resultsDiv = createResultsDiv();
133 var summary = { failed:
0, passed:
0 };
134 postResults(results, summary);
135 resultsDiv.appendChild(document.createElement(
"hr"));
136 document.getElementById('summary').innerHTML =
"(" + summary.failed +
" failed, " + summary.passed +
" passed)";
139 function createResultsDiv() {
140 var body = document.getElementsByTagName(
"body")[
0];
141 div = document.createElement(
"div");
143 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/>";
144 body.insertBefore(div, body.firstChild);
146 var setByClassName = function(name, displayStyle) {
147 var elements = div.getElementsByClassName(name);
148 for (var i =
0; i < elements.length; i++) {
149 elements[i].style.display = displayStyle;
153 var passedAnchor = document.getElementById('passed');
154 var failedAnchor = document.getElementById('failed');
155 var allAnchor = document.getElementById('all');
156 passedAnchor.onclick = function() {
157 setByClassName('fail', 'none');
158 setByClassName('pass', 'block');
160 passedAnchor.setAttribute(
"class", 'activeAnchor');
161 failedAnchor.setAttribute(
"class", '');
163 failedAnchor.onclick = function() {
164 setByClassName('fail', 'block');
165 setByClassName('pass', 'none');
166 passedAnchor.setAttribute(
"class", '');
167 failedAnchor.setAttribute(
"class", 'activeAnchor');
169 allAnchor.onclick = function() {
170 setByClassName('fail', 'block');
171 setByClassName('pass', 'block');
172 passedAnchor.setAttribute(
"class", '');
173 failedAnchor.setAttribute(
"class", '');
178 function postResults(results, summary, title) {
179 if (typeof(results) ==
"boolean") {
180 var elem = document.createElement(
"div");
181 elem.setAttribute(
"class", results ? 'pass' : 'fail');
183 var prefix = title ? (title +
": ") :
"";
184 elem.innerHTML = prefix + '
<span class=
\'outcome
\'>' + (results ? 'pass' : 'fail') + '
</span>';
185 resultsDiv.appendChild(elem);
194 for (var key in results) {
195 if (results.hasOwnProperty(key)) {
196 var elem = results[key];
197 if (typeof(elem) ==
"boolean" && title) {
198 postResults(results[key], summary, title +
"." + key);
200 postResults(results[key], summary, key);
210 <div id='graph'
></div>
211 <div id=
"selector"></div>
212 <p>This file is really nothing more than all the tests coalesced into a single
213 HTML file. To run a test, use the selector above, or
214 open a Javascript console and execute, for instance,
</p>
215 <code>testDrawSimpleRangePlusOne()
</code>
217 <p>Alternatively you can use query args:
<ul>
218 <li>testCase - for the name of the test case prototype
219 <li>testCaseName - for the name of the test case
220 <li>test - for the name of the test (use command=runTest)
221 <li>command - either runTest or runAllTests.
223 Example:
<code>local.html?testCase=ScrollingDivTestCase&test=testNestedDiv_Scrolled&command=runTest
</code>
228 addGlobalTestSymbols();
230 var selector = document.getElementById(
"selector");
232 if (selector != null) { // running a test
233 var createAttached = function(name, parent) {
234 var elem = document.createElement(name);
235 parent.appendChild(elem);
239 var description = createAttached(
"div", selector);
240 var list = createAttached(
"ul", selector);
241 var parent = list.parentElement;
242 var createLink = function(parent, text, url) {
243 var li = createAttached(
"li", parent);
244 var a = createAttached(
"a", li);
249 description.innerHTML =
"Test cases:";
250 var testCases = getAllTestCases();
251 createLink(list,
"(run all tests)", document.URL +
"?command=runAllTests");
252 for (var idx in testCases) {
253 var entryName = testCases[idx].name;
254 createLink(list, entryName, document.URL +
"?testCaseName=" + entryName);
257 description.innerHTML =
"Tests for " + name;
258 var names = tc.getTestNames();
259 createLink(list,
"Run All Tests", document.URL +
"&command=runAllTests");
260 for (var idx in names) {
261 var name = names[idx];
262 createLink(list, name, document.URL +
"&test=" + name +
"&command=runTest");