Author: ygrego Date: 2015-07-08 16:23:13 +0200 (Wed, 08 Jul 2015) New Revision: 1785 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1785 Log: Global refactoring for test running. Modified: oipf/test/css/test.css oipf/test/js/RecordingSchedulerTest.js oipf/test/js/Test.js oipf/test/view/test.html Modified: oipf/test/css/test.css =================================================================== --- oipf/test/css/test.css 2015-07-08 14:21:14 UTC (rev 1784) +++ oipf/test/css/test.css 2015-07-08 14:23:13 UTC (rev 1785) @@ -87,3 +87,31 @@ background-color: #e66e33; color: white; } + +.errorTechnical { + background-color: #e64133; + color: whtite; +} + +.errorInvalidState { + background-color: #e69b33; + color: whtite; +} + +.errorUnexecutableTest { + background-color: #e6c833; + color: whtite; +} + +.errorNoTestResult { + background-color: #ee9e77; + color: whtite; +} + +.invisible { + display: none; +} + +visible { + display: block; +} Modified: oipf/test/js/RecordingSchedulerTest.js =================================================================== --- oipf/test/js/RecordingSchedulerTest.js 2015-07-08 14:21:14 UTC (rev 1784) +++ oipf/test/js/RecordingSchedulerTest.js 2015-07-08 14:23:13 UTC (rev 1785) @@ -43,7 +43,7 @@ this.vidBroadObj .addEventListener("PlayStateChange", this.onPlayStateChange, false); - this.deleteAndStopStartedRecording(); +// this.deleteAndStopStartedRecording(); this.searchManagerObj = oipfObjectFactory.createSearchManagerObject(); @@ -105,11 +105,14 @@ .then(this.findProgrammeFromStream.bind(this, resolve, reject)) .then(this.timeout.bind(this)) .then(function() { - console.log("Addtion of transition."); + console.log("Addition of transition."); self.resetTransitionVariables(); self.addTransition(null, self.SCHEDULED); self.addTransition(self.SCHEDULED, self.BEFORE_STARTED); - self.addTransition(self.BEFORE_STARTED, self.STARTED); + self.addTransition(self.BEFORE_STARTED, self.STARTED, function() { + var result = self.recordingSchedulerObject.update(self.recording.id, + undefined, 3000, undefined); + }); self.addTransition(self.STARTED, self.COMPLETED, resolve); self.recording = self.recordingSchedulerObject.record(self.programme); @@ -127,9 +130,10 @@ var randomIndex = OipfUtils .getRandomNumberBetweenMinMax(0, channelConfig.channelList.length); var channel = channelConfig.channelList[randomIndex]; - var currentTime = Math.round(this.dateUtils.nowInSeconds()); + var currentTime = this.dateUtils.nowInSeconds(); + console.log(currentTime); this.recording = this.recordingSchedulerObject.recordAt(currentTime, - 1 * 60, 0x00, channel.ccid); + 5, 0x00, channel.ccid); console.log(this.recording); } @@ -292,7 +296,7 @@ .then(function() { self.resetTransitionVariables(); self.addTransition(null, self.SCHEDULED, function() { - var twentyMinutes = 20 * 60; + var twentyMinutes = 5; self.recordingSchedulerObject.update(self.recording.id, undefined, self.recording.duration + twentyMinutes, undefined); @@ -317,7 +321,7 @@ self.addTransition(null, self.SCHEDULED); self.addTransition(self.SCHEDULED, self.BEFORE_STARTED); self.addTransition(self.BEFORE_STARTED, self.STARTED, function() { - var oneMinute = 1 * 60; + var oneMinute = 5; var result = self.recordingSchedulerObject.update(self.recording.id, undefined, self.recording.duration + oneMinute, undefined); Modified: oipf/test/js/Test.js =================================================================== --- oipf/test/js/Test.js 2015-07-08 14:21:14 UTC (rev 1784) +++ oipf/test/js/Test.js 2015-07-08 14:23:13 UTC (rev 1785) @@ -822,7 +822,7 @@ control status is deactivated.", method: "testGetParentalControlStatusWhenParentalControlStatusDeactivated" } - ]},{ + ]}/*,{ name: "ApplicationManagerTest", object: new ApplicationManagerTest(), tests: [ @@ -835,7 +835,7 @@ method: "testGetOwnerApplicationWithNull" } ] - }]; + }*/]; this.animation = { i: 1, @@ -852,6 +852,10 @@ succeeded: 0, failed: 0 }; + var style = document.getElementById("running").style; + style.display = (!style.display || style.display == "none") ? "block" : "none"; + var style = document.getElementById("globalTestResultsDiv").style; + style.display = (!style.display || style.display == "none") ? "block" : "none"; this.runLoop(0, 0).then(this.totalPercentage.bind(this)); } @@ -891,7 +895,7 @@ } }; - return this.updateTestResult(tests[indexTest], object) + return this.runTest(tests[indexTest], object) .then(loop).catch(loop); } @@ -899,8 +903,8 @@ percentageCalculating(currentResult) { this.round = Math.round.bind(Math); var testNumber = currentResult.failed + currentResult.succeeded; - currentResult.failed = this.round((currentResult.failed / testNumber) * 100); - currentResult.succeeded = this.round((currentResult.succeeded / testNumber) * 100); + currentResult.failed = this.round(currentResult.failed / testNumber * 100); + currentResult.succeeded = this.round(currentResult.succeeded / testNumber * 100); } totalPercentage() { @@ -914,8 +918,8 @@ this.resultsPercentageSucceeded += this.testsObjects[i].results.succeeded; this.results.push(this.testsObjects[i].results); } - this.resultsPercentageFailed = this.resultsPercentageFailed/this.testsObjects.length; - this.resultsPercentageSucceeded = this.resultsPercentageSucceeded/this.testsObjects.length; + this.resultsPercentageFailed = this.resultsPercentageFailed / this.testsObjects.length; + this.resultsPercentageSucceeded = this.resultsPercentageSucceeded / this.testsObjects.length; this.displayGlobalTestResults(); } @@ -949,7 +953,9 @@ tableResult.innerHTML = content; - var style = document.getElementById("globalTestResultsDiv").style; +// var style = document.getElementById("globalTestResultsDiv").style; +// style.display = (!style.display || style.display == "none") ? "block" : "none"; + var style = document.getElementById("running").style; style.display = (!style.display || style.display == "none") ? "block" : "none"; } @@ -965,25 +971,17 @@ } }; - this.updateTestResult(tests[indexTest], object) + this.runTest(tests[indexTest], object) .then(loop).catch(loop); } - run(indexObject, indexTest) { - var element = this.testsObjects[indexObject]; - var object = element.object; - var tests = element.tests; - - return this.updateTestResult(tests[indexTest], object); - } - displayInLineArray() { var content = "<div id='testControllerDiv'>"; content += "<div id='titleTestControllerDiv'><h4>All tests</h4></div>"; content += "<button id='runAllBtn'>Run All</button>"; content += "<button id='displayConfigBtn'>Hide/Show</button>"; - content += "<div id='globalTestResultsDiv'>"; - content += "<div id='titleGlobalTestResultsDiv'><h4>Test Results</h4></div>"; + content += "<div id='globalTestResultsDiv' class='invisible'>"; + content += "<div id='titleGlobalTestResultsDiv'><h4>Test Results</h4><img id='running' src='test/pictures/running.gif'></div>"; content += "<table id='globalTestResultsTable'></table>"; content += "</div>"; content += "</div>"; @@ -1035,7 +1033,7 @@ document.body.innerHTML += content; } - updateTestResult(currentTest, object) { + runTest(currentTest, object) { this.updateTestResultStart(currentTest); console.group(currentTest["label"]); @@ -1138,9 +1136,9 @@ colorManaging(errorMessage) { var map = { - "No result returned.": "error", - "Untestable case for the moment.": "error", - "Invalid state.": "error" + "No result returned.": "errorNoTestResult", + "Untestable case for the moment.": "errorUnexecutableTest", + "Invalid state.": "errorInvalidState" }; if (!errorMessage) { @@ -1150,7 +1148,7 @@ return map[errorMessage]; } else if (errorMessage instanceof Error) { - return "error"; + return "errorTechnical"; } } } Modified: oipf/test/view/test.html =================================================================== --- oipf/test/view/test.html 2015-07-08 14:21:14 UTC (rev 1784) +++ oipf/test/view/test.html 2015-07-08 14:23:13 UTC (rev 1785) @@ -16,12 +16,20 @@ <script src="./test/build/oipf-tests.js" type="text/javascript"></script> <script> - var tests = new Test(); var displayConfig = { show: true }; - function showOrHideAll() { + function initPage() { + var tests = new Test(); + tests.displayInLineArray(); + addListenerForButton(tests); + showOrHideAll(tests); + document.getElementById("runAllBtn").onclick = tests.runAll.bind(tests); + document.getElementById("displayConfigBtn").onclick = showOrHideAll.bind(null, tests); + } + + function showOrHideAll(tests) { console.log("Method showOrHideAll called."); for (var j = 0, l = tests.sectionsID.length; j < l; j++) { @@ -42,11 +50,23 @@ } function start() { - tests.displayInLineArray(); - addListenerForButton(tests); - showOrHideAll(); - document.getElementById("runAllBtn").onclick = tests.runAll.bind(tests); - document.getElementById("displayConfigBtn").onclick = showOrHideAll; +// var oipfFactory = oipfObjectFactory; +// +// if (oipfFactory._initPromise) { +// var initPromise = oipfFactory._initPromise; +// +// if (initPromise) { +// initPromise.then(initPage); +// initPromise.catch( +// window.alert.bind(window, "An error occurs in an file's creation.")); +// } else { +// window.alert("An error occurs in initialization of factory oipf."); +// } +// +// } else { + initPage(); +// } + } function hideOrShowTestSection(sectionId) { @@ -82,7 +102,7 @@ var testCase = currentTests[j]; document.getElementById(testCase.method + "Btn").onclick = - testClass.updateTestResult.bind(testClass, testCase, currentElement.object); + testClass.runTest.bind(testClass, testCase, currentElement.object); } } }