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