<script type="text/javascript" src="../tests/update_options.js"></script>
<script type="text/javascript" src="../tests/utils_test.js"></script>
+<style type="text/css">
+ .pass .outcome {
+ color: green;
+ }
+
+ .fail .outcome {
+ color: red;
+ }
+ .activeAnchor {
+ color: black;
+ text-decoration: none;
+ }
+</style>
<script type="text/javascript">
var tc = null;
var name = null;
+
+ var resultDiv = null;
+
function processVariables() {
var splitVariables = function() { // http://www.idealog.us/2006/06/javascript_to_p.html
var query = window.location.search.substring(1);
eval("tc = new " + args.testCase + "()");
}
+ var results = null;
// If the test class is defined.
if (tc != null) {
if (args.command == "runAllTests") {
console.log("Running all tests for " + args.testCase);
- postResults(tc.runAllTests());
- }
- if (args.command == "runTest") {
+ results = tc.runAllTests();
+ } else if (args.command == "runTest") {
console.log("Running test " + args.testCase + "." + args.test);
- postResults(tc.runTest(args.test));
+ results = tc.runTest(args.test);
}
} else {
if (args.command == "runAllTests") {
console.log("Running all tests for all test cases");
var testCases = getAllTestCases();
- var results = {};
+ results = {};
for (var idx in testCases) {
var entry = testCases[idx];
var prototype = entry.testCase;
tc = new entry.testCase();
results[entry.name] = tc.runAllTests();
}
- postResults(results);
}
}
+ resultsDiv = createResultsDiv();
+ postResults(results);
+ resultsDiv.appendChild(document.createElement("hr"));
}
- function postResults(results, title, div) {
- var first = false;
- if (div == null) {
- var body = document.getElementsByTagName("body")[0];
- div = document.createElement("div");
- div.innerHTML = "Test results:";
- if (typeof(results) != "boolean"); {
- div.innerHTML = "Test results:<br/>";
+ function createResultsDiv() {
+ var body = document.getElementsByTagName("body")[0];
+ div = document.createElement("div");
+ div.id='results';
+ div.innerHTML = "Test results: <a href='#' id='passed'>passed</a> <a href='#' id='failed'>failed</a> <a href='#' id='all'>all</a><br/>";
+ body.insertBefore(div, body.firstChild);
+
+ var setByClassName = function(name, displayStyle) {
+ var elements = div.getElementsByClassName(name);
+ for (var i = 0; i < elements.length; i++) {
+ elements[i].style.display = displayStyle;
}
- body.insertBefore(div, body.firstChild);
- first = true;
}
- var resultToHtml = function(result) {
- return result ?
- "<span style='color:green;'>pass</span>" :
- "<span style='color:red;'>fail</span>";
- }
+ var passedAnchor = document.getElementById('passed');
+ var failedAnchor = document.getElementById('failed');
+ var allAnchor = document.getElementById('all');
+ passedAnchor.onclick = function() {
+ setByClassName('fail', 'none');
+ setByClassName('pass', 'block');
+
+ passedAnchor.setAttribute("class", 'activeAnchor');
+ failedAnchor.setAttribute("class", '');
+ };
+ failedAnchor.onclick = function() {
+ setByClassName('fail', 'block');
+ setByClassName('pass', 'none');
+ passedAnchor.setAttribute("class", '');
+ failedAnchor.setAttribute("class", 'activeAnchor');
+ };
+ allAnchor.onclick = function() {
+ setByClassName('fail', 'block');
+ setByClassName('pass', 'block');
+ passedAnchor.setAttribute("class", '');
+ failedAnchor.setAttribute("class", '');
+ };
+ return div;
+ }
+ function postResults(results, title) {
if (typeof(results) == "boolean") {
var elem = document.createElement("div");
- if (title) {
- elem.innerHTML = title + ": " + resultToHtml(results);
- } else {
- elem.innerHTML = resultToHtml(results);
- }
- div.appendChild(elem);
+ elem.setAttribute("class", results ? 'pass' : 'fail');
+
+ var prefix = title ? (title + ": ") : "";
+ elem.innerHTML = prefix + '<span class=\'outcome\'>' + (results ? 'pass' : 'fail') + '</span>';
+ resultsDiv.appendChild(elem);
} else { // hash
var html = "";
for (var key in results) {
if (results.hasOwnProperty(key)) {
var elem = results[key];
if (typeof(elem) == "boolean" && title) {
- postResults(results[key], title + "." + key, div);
+ postResults(results[key], title + "." + key);
} else {
- postResults(results[key], key, div);
+ postResults(results[key], key);
}
}
}
}
- if (first) {
- div.appendChild(document.createElement("hr"));
- }
}
+
</script>
</head>
<body>
var list = createAttached("ul", selector);
var parent = list.parentElement;
var createLink = function(parent, text, url) {
- var li = createAttached("li", parent);
- var a = createAttached("a", li);
- a.innerText = text;
- a.href = url;
+ var li = createAttached("li", parent);
+ var a = createAttached("a", li);
+ a.innerText = text;
+ a.href = url;
}
if (tc == null) {
description.innerHTML = "Test cases:";