Author: ygrego Date: 2015-06-18 13:18:45 +0000 (Thu, 18 Jun 2015) New Revision: 1749 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1749 Log: The class TestCase isn't accesible in emulator environment. Modified: oipf/emulator/js/utils/Service.js Modified: oipf/emulator/js/utils/Service.js =================================================================== --- oipf/emulator/js/utils/Service.js 2015-06-18 12:58:53 UTC (rev 1748) +++ oipf/emulator/js/utils/Service.js 2015-06-18 13:18:45 UTC (rev 1749) @@ -1,17 +1,42 @@ var Service = Class.extend({ init: function() { + this.transitions = [] - this.currentTransition = {}; this.currentIndex = 0; - var testCase = new TestCase(); + this.onChangeState = function(resolve, reject, newState, errorCode) { + var currentTransition = this.transitions[this.currentIndex]; + var begin = currentTransition.begin; + var end = currentTransition.end; + var error = currentTransition.error; - if (testCase) { - this.onChangeState = testCase.onChangeState.bind(this); - this.addTransition = testCase.addTransition.bind(this); - this.addTransitionWithError = testCase.addTransitionWithError.bind(this); - } + if (begin == this.previousState && end == newState && error == errorCode) { + currentTransition.callback && currentTransition.callback(); + this.previousState = newState; + this.currentIndex++; + } else { + if (begin == this.CONNECTING && this.transitions.length == this.currentIndex + 1) { + reject("Untestable case for the moment."); + } else { + reject("Invalid state."); + } + } + }; + + this.addTransition = function(begin, end, callback) { + this.addTransitionWithError(begin, end, null, callback); + }; + + this.addTransitionWithError = function(begin, end, error, callback) { + this.transitions.push({ + begin: begin, + end: end, + error: error, + callback: callback + }); + }; + } });