Author: ygrego Date: 2015-03-18 10:44:54 +0000 (Wed, 18 Mar 2015) New Revision: 954 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/954 Log: -Deletion of field relevantless in object "testObject" but addition of field "before" to know if a method must be called before the test. -In method "runAll" deletion of condition on implementation of a test in order to run current test. -Deletion of method "display" and "displayArrayLayout". -In method "displayInLineArray" deletion of variable not used and use of test method name as identifier for each row of table created in DOM element of "test.html". -In method "updateTestResult" make logs display in console more legible thank to instructions "console.group()" and "console.groupEnd()" added and restructuration of code which must achieve the update in internal method then(), catch() and setTimeout(). Modified: oipf/js/test/Test.js Modified: oipf/js/test/Test.js =================================================================== --- oipf/js/test/Test.js 2015-03-18 09:18:57 UTC (rev 953) +++ oipf/js/test/Test.js 2015-03-18 10:44:54 UTC (rev 954) @@ -9,44 +9,48 @@ object: new VideoBroadcastTest(), tests: [ { - id: "vbTestInstanceCreation", - label: "Object creation.", - method: "testInstanceCreation", - impl: true + label: "Video broadcast creation.", + before: false, + method: "testVideoBroadcastInit" }, { - id: "vbTestBindToCurrentChannel", label: "Bind the current channel stream with a video broadcast object.", - method: "testBindToCurrentChannel", - impl: true + before: true, + method: "testBindToCurrentChannel" }, { - id: "vbTestPrevChannel", label: "Switch to precedent channel in channel list.", - method: "testPrevChannel", - impl: true + before: true, + method: "testPrevChannel" }, { - id: "vbTestNextChannel", label: "Switch to next channel in channel list.", - method:"testNextChannel", - impl: true + before: true, + method:"testNextChannel" + }, + { + label: "Release any tuner and/or ressources held by a video broadcast object.", + before: true, + method: "testRelease" + }, + { + label: "Stop the video and audio presentation of video broadcast object.", + before: true, + method: "testStop" } ]},{ name: "SearchManagerTest", object: new SearchManagerTest(), tests: [ { - id: "smTestInstanceCreation", - label: "Object creation.", - method: "testInstanceCreation", - impl: true + label: "Search manager creation.", + before: false, + method: "testSearchManagerInit" }, { - id: "smTestGetCurrentProgram", label: "Obtain current program according to oipf norm.", - method: "testGetCurrentProgram", - impl: true + before: true, + method: "testGetCurrentProgram" } ] }], @@ -65,89 +69,12 @@ for (var j = 0; j < tests.length; j++) { var currentTest = tests[j]; - if (currentTest["impl"]) { - this.updateTestResult(currentTest, object); - } + this.updateTestResult(currentTest, object); + } } }, - //Use the innerHTML property to achieve display - display: function() { - var content = "<div id='testsDisplay'>Test Page <button id='runAllBtn'>Run All</button>"; - var testsObjects = this.testsObjects; - for (var i = 0; i < testsObjects.length; i++) { - - var currentObject = testsObjects[i]; - var sectionName = currentObject["name"]; - content += "<div id='" + sectionName + "'>"; - var tests = currentObject["tests"]; - for (var j = 0; j < tests.length; j++) { - - var currentTest = tests[j]; - content += "<div id='" + currentTest["id"] + "'>"; - content += "<div>Label: " + currentTest["label"] + "</div>"; - content += "<div>Tested method: " + currentTest["method"] + "</div>"; - var impl = currentTest["impl"]; - content += "<div>Implementation State: " + impl + "</div>"; - - if (impl) { - content += "<div id='" + currentTest["id"] + "Res" + "'>Result: Test has not been launch. Click on button \"Run\" below.</div>"; - content += "<div><button id='" + currentTest["id"] + "Btn" + "'>Run</button></div>"; - } else { - content += "<div id='" + currentTest["id"] + "Res" + "'>Result: Any result will be available for the moment, test has not been implemented.</div>"; - content += "<div><button id='" + currentTest["id"] + "Btn" + "' disabled>Run</button></div>"; - } - content += "</div>"; - } - content += "</div>"; - } - content += "</div>"; - document.body.innerHTML = content; - }, - - //Use the innerHTML property to achieve display - displayArrayLayout: function() { - var content = "<div id='testsDisplay'>Test Page <button id='runAllBtn'>Run All</button>"; - var testsObjects = this.testsObjects; - for (var i = 0; i < testsObjects.length; i++) { - - var currentObject = testsObjects[i]; - var sectionName = currentObject["name"]; - content += "<div id='" + sectionName + "SectionTitle" + "'>" + sectionName + " <button id='" + sectionName + "Btn' onclick='hideOrShowTestSection(\"" + sectionName + "\")'>Hide/Show</button>"; - content += "<div id='" + sectionName + "'>"; - var tests = currentObject["tests"]; - for (var j = 0; j < tests.length; j++) { - - var currentTest = tests[j]; - //content += "<div id='" + currentTest["id"] + "'>"; - content += "<table id='" + currentTest["id"] + "Table'>"; - content += "<caption>" + currentTest["id"] + "<caption/>"; - content += "<tbody>"; - content += "<tr><th>Tested method</th><td>" + currentTest["method"] + "</td></tr>"; - content += "<tr><th>Label</th><td>" + currentTest["label"] + "</td></tr>"; - var impl = currentTest["impl"]; - content += "<tr><th>Implementation State</th><td>" + impl + "</td></tr>"; - content += "</tbody>"; - ////TFOOT - content += "<tfoot>"; - if (impl) { - content += "<tr><th>Result</th><td id='" + currentTest["id"] + "Res'>Test has not been launch. Click on button \"Run\" below.</td></tr>"; - content += "<tr><th>Test launching</th><td><button id='" + currentTest["id"] + "Btn" + "'>Run</button></td></tr>"; - } else { - content += "<tr><th>Result</th><td id='" + currentTest["id"] + "Res'>Any result will be available for the moment, test has not been implemented.</td></tr>"; - content += "<tr><th>Test launching</th><td><button id='" + currentTest["id"] + "Btn" + "' disabled>Run</button></td></tr>"; - } - content += "</tfoot>"; - content += "</table>"; - } - - content += "</div>"; - } - content += "</div>"; - document.body.innerHTML = content; - }, - displayInLineArray: function() { var content = "<div id='testsDisplay'>Test Page <button id='runAllBtn'>Run All</button>"; var testsObjects = this.testsObjects; @@ -169,21 +96,18 @@ for (var i = 0; i < testsObjects.length; i++) { var currentObject = testsObjects[i]; - var sectionName = currentObject["name"]; - //content += "<div id='" + sectionName + "SectionTitle" + "'>" + sectionName + " <button id='" + sectionName + "Btn' onclick='hideOrShowTestSection(\"" + sectionName + "\")'>Hide/Show</button>"; var tests = currentObject["tests"]; for (var j = 0; j < tests.length; j++) { var currentTest = tests[j]; - content += "<tr id='" + currentTest["id"] + "'>"; + content += "<tr id='" + currentTest["method"] + "'>"; 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 += "<td id='" + currentTest["method"] + "Duration'>None</td>"; + content += "<td id='" + currentTest["method"] + "Result'>None</td>"; + content += "<td><button id='" + currentTest["method"] + "Btn" + "'>Run</button></td>"; } content += "</tr>"; - 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>"; @@ -194,28 +118,28 @@ }, updateTestResult: function(currentTest, object) { - + console.group(currentTest["label"]); var timeStart = performance.now(); var promise = new Promise(object[currentTest["method"]].bind(object)); var result = false; promise.then(function(val) { + console.groupEnd(currentTest["label"]); 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"; - + document.getElementById(currentTest["method"] + "Result").textContent = val; + document.getElementById(currentTest["method"] + "Result").style.backgroundColor = "limegreen"; + document.getElementById(currentTest["method"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; + }); promise.catch(function(val) { + console.groupEnd(currentTest["label"]); 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"; + document.getElementById(currentTest["method"] + "Result").textContent = val; + document.getElementById(currentTest["method"] + "Result").style.backgroundColor = "red"; + document.getElementById(currentTest["method"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; }); @@ -224,13 +148,13 @@ try { var message = "Any result have been return."; var timeEnd = performance.now(); - 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"; + document.getElementById(currentTest["method"] + "Result").textContent = message; + document.getElementById(currentTest["method"] + "Result").style.backgroundColor = "red"; + document.getElementById(currentTest["method"] + "Duration").textContent = (timeEnd - timeStart).toFixed(2) + " ms"; throw new Error(message); } catch (error) { console.log("[INFO]", error.message); + console.groupEnd(currentTest["label"]); } } }, 10000);