Author: ygrego Date: 2015-03-11 15:05:24 +0000 (Wed, 11 Mar 2015) New Revision: 938 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/938 Log: Modification of method "displayInLineArray" in order to display tests in line(test page), one line = one test. Modification of method "updateTestResult" in order to change color of test result field(in test page) according to test result and take account the lack of result from test execution because it can come from asynchronous methods. Modified: oipf/js/test/Test.js Modified: oipf/js/test/Test.js =================================================================== --- oipf/js/test/Test.js 2015-03-11 14:48:12 UTC (rev 937) +++ oipf/js/test/Test.js 2015-03-11 15:05:24 UTC (rev 938) @@ -153,7 +153,19 @@ var testsObjects = this.testsObjects; content += "<div id=AllTestDiv>"; content += "<table id=AllTestTable>"; + content += "<tbody>"; + + content += "<thead>"; + content += "<tr>"; + content += "<th>Tested Method</th>"; + content += "<th>Label</th>"; + content += "<th>Test duration</th>"; + content += "<th>Result</th>"; + content += "<th>Lauching</th>"; + content += "</tr>"; + content += "</thead>"; + for (var i = 0; i < testsObjects.length; i++) { var currentObject = testsObjects[i]; @@ -164,15 +176,17 @@ var currentTest = tests[j]; content += "<tr id='" + currentTest["id"] + "'>"; - content += "<td>Tested method: " + currentTest["method"] + "</td>"; - content += "<td>Label: " + currentTest["label"] + "</td>"; - content += "<td id='" + currentTest["id"] + "Res'>Result: Test has not been launch.</td>"; + content += "<td>" + currentTest["method"] + "</td>"; + content += "<td>" + currentTest["label"] + "</td>"; + content += "<td id='" + currentTest["id"] + "Duration'>None</td>"; + content += "<td id='" + currentTest["id"] + "Result'>None</td>"; content += "<td><button id='" + currentTest["id"] + "Btn" + "'>Run</button></td>"; } content += "</tr>"; - content += "<tr><td></td><td></td><td></td><td></td></tr>"; //Make a seperation between 2 test section (VideoBroadcast and SearchManager for example) + content += "<tr><td></td><td></td><td></td><td></td><td></td></tr>"; //Make a seperation between 2 test section (VideoBroadcast and SearchManager for example) } content += "</tbody>"; + content += "</table>"; content += "</div>"; content += "</div>"; @@ -180,40 +194,47 @@ }, updateTestResult: function(currentTest, object) { - try { - var timeStart = performance.now(); - var promise = new Promise(object[currentTest["method"]].bind(object)); - var result = false; - - promise.then(function (val) { - result = true; - var timeEnd = performance.now(); - document.getElementById(currentTest["id"] + "Res").textContent = "Result: " + val + " Test-duration: " + (timeEnd - timeStart).toFixed(2) +" ms"; - }); - - promise.catch(function (val) { - result = true; - var timeEnd = performance.now(); - document.getElementById(currentTest["id"] + "Res").textContent = "Result: " + val + " Test-duration: " + (timeEnd - timeStart).toFixed(2) +" ms"; + var timeStart = performance.now(); + var promise = new Promise(object[currentTest["method"]].bind(object)); + var result = false; + + promise.then(function(val) { + result = true; + var timeEnd = performance.now(); + document.getElementById(currentTest["id"] + "Result").textContent = val; + var style = document.getElementById(currentTest["id"] + "Result").style; + style.backgroundColor = "limegreen"; + document.getElementById(currentTest["id"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; - }); - - setTimeout(function () { - console.log("HERE", timeStart); - if (!result) { + }); + + promise.catch(function(val) { + result = true; + var timeEnd = performance.now(); + document.getElementById(currentTest["id"] + "Result").textContent = val; + var style = document.getElementById(currentTest["id"] + "Result").style; + style.backgroundColor = "red"; + document.getElementById(currentTest["id"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; + + }); + + setTimeout(function() { + if (!result) { + try { var message = "Any result have been return."; var timeEnd = performance.now(); - document.getElementById(currentTest["id"] + "Res").textContent = "Result: " + message + " Test-duration: " + (timeEnd - timeStart).toFixed(2) +" ms"; + document.getElementById(currentTest["id"] + "Result").textContent = message; + var style = document.getElementById(currentTest["id"] + "Result").style; + style.backgroundColor = "red"; + document.getElementById(currentTest["id"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; throw new Error(message); - - } - }, 10000); - - } catch (error) { - console.log("[INFO]", error.message); - - } + } catch (error) { + console.log("[INFO]", error.message); + } + } + }, 10000); + } });