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