Added functionality to hide the doAsk prompt on a stopAll call with tests

This commit is contained in:
Brian Pilati 2014-03-08 09:41:01 -07:00
parent 1beed456cc
commit 6f54f52f3c
7 changed files with 218 additions and 10 deletions

View file

@ -88,19 +88,14 @@ Runtime.prototype.stopAll = function() {
interp.activeThread = new Thread(null);
interp.threads = [];
stopAllSounds();
// Hide reporters
// Hide sprite bubbles, resetFilters and doAsk prompts
for (var s = 0; s < runtime.sprites.length; s++) {
if (runtime.sprites[s].hideBubble) {
runtime.sprites[s].hideBubble();
}
if (runtime.sprites[s].hideBubble) runtime.sprites[s].hideBubble();
if (runtime.sprites[s].resetFilters) runtime.sprites[s].resetFilters();
if (runtime.sprites[s].hideAsk) runtime.sprites[s].hideAsk();
}
// Reset graphic effects
runtime.stage.resetFilters();
for (var s = 0; s < runtime.sprites.length; s++) {
if (runtime.sprites[s].resetFilters) {
runtime.sprites[s].resetFilters();
}
}
};
// Step method for execution - called every 33 milliseconds

View file

@ -21,6 +21,7 @@ var interpreterMock = function() {
return {
'targetSprite' : function() { return getArgs('targetSprite'); },
'arg': function(block, index) { return getArgs('arg');}
'arg': function(block, index) { return getArgs('arg');},
'activeThread': undefined
}
};

View file

@ -0,0 +1,29 @@
'use strict';
var runtimeMock = function() {
var args = createArgs(arguments);
function getArgs(argKey) {
return ((argKey in args) ? args[argKey] : null);
}
function createArgs(methodArgs) {
var args = {};
if (methodArgs.length) {
_.each(methodArgs, function(newObject) {
_.each(newObject, function(value, key) {
args[key] = value;
});
});
}
return args;
}
return {
'sprites' : [
new spriteMock()
],
'stage': new stageMock()
}
};

View file

@ -0,0 +1,27 @@
'use strict';
var spriteMock = function() {
var args = createArgs(arguments);
function getArgs(argKey) {
return ((argKey in args) ? args[argKey] : null);
}
function createArgs(methodArgs) {
var args = {};
if (methodArgs.length) {
_.each(methodArgs, function(newObject) {
_.each(newObject, function(value, key) {
args[key] = value;
});
});
}
return args;
}
return {
'hideBubble' : function() { return getArgs('hideBubble'); },
'hideAsk': function() { return getArgs('hideAsk');},
'resetFilters': function() { return getArgs('resetFilters');}
}
};

View file

@ -0,0 +1,25 @@
'use strict';
var stageMock = function() {
var args = createArgs(arguments);
function getArgs(argKey) {
return ((argKey in args) ? args[argKey] : null);
}
function createArgs(methodArgs) {
var args = {};
if (methodArgs.length) {
_.each(methodArgs, function(newObject) {
_.each(newObject, function(value, key) {
args[key] = value;
});
});
}
return args;
}
return {
'resetFilters' : function() { return getArgs('resetFilters'); }
}
};

View file

@ -0,0 +1,24 @@
'use strict';
var threadMock = function() {
var args = createArgs(arguments);
function getArgs(argKey) {
return ((argKey in args) ? args[argKey] : null);
}
function createArgs(methodArgs) {
var args = {};
if (methodArgs.length) {
_.each(methodArgs, function(newObject) {
_.each(newObject, function(value, key) {
args[key] = value;
});
});
}
return args;
}
return {
}
};

107
test/unit/runTimeSpec.js Normal file
View file

@ -0,0 +1,107 @@
/* jasmine specs for Runtime.js go here */
describe ('Runtime', function() {
var runtimeObj;
beforeEach(function() {
runtimeObj = Runtime;
});
describe('Instantization variables', function() {
var initRuntime, lineCanvas;
beforeEach(function() {
initRuntime = new runtimeObj();
});
describe('Runtime Variables', function() {
it('should have a scene variable', function() {
expect(initRuntime.scene).toBe(null);
});
it('should have a sprites array', function() {
expect(initRuntime.sprites).toEqual([]);
});
it('should have a reporters array', function() {
expect(initRuntime.reporters).toEqual([]);
});
it('should have a keysDown array', function() {
expect(initRuntime.keysDown).toEqual([]);
});
it('should have a mouseDown variable', function() {
expect(initRuntime.mouseDown).toBe(false);
});
it('should have a mousePos array', function() {
expect(initRuntime.mousePos).toEqual([0,0]);
});
it('should have an audioContext variable', function() {
expect(initRuntime.audioContext).toBe(null);
});
it('should have an audoGain variable', function() {
expect(initRuntime.audioGain).toBe(null);
});
it('should have an audioPlaying array', function() {
expect(initRuntime.audioPlaying).toEqual([]);
});
it('should have a notesPlaying array', function() {
expect(initRuntime.notesPlaying).toEqual([]);
});
it('should have a projectLoaded variable', function() {
expect(initRuntime.projectLoaded).toBe(false);
});
});
});
describe('Stop All', function() {
beforeEach(function() {
runtime = new runtimeMock
spyOn(window, "stopAllSounds");
spyOn(runtime.stage, "resetFilters");
spyOn(runtime.sprites[0], "hideBubble");
spyOn(runtime.sprites[0], "resetFilters");
spyOn(runtime.sprites[0], "hideAsk");
Thread = threadMock;
interp = new interpreterMock();
});
it('should call a new Thread Object', function() {
runtimeObj.prototype.stopAll();
expect(interp.activeThread).toEqual({});
});
it('should call a blank thread array ', function() {
runtimeObj.prototype.stopAll();
expect(interp.activeThread).toEqual([]);
});
it('should call stopAllSounds', function() {
runtimeObj.prototype.stopAll();
expect(window.stopAllSounds).toHaveBeenCalled();
});
it('should call sprites.hideBubble', function() {
runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].hideBubble).toHaveBeenCalled();
});
it('should call sprites.resetFilters', function() {
runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].resetFilters).toHaveBeenCalled();
});
it('should call sprites.hideAsk', function() {
runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].hideAsk).toHaveBeenCalled();
});
});
});