updates to elevate my code to scratch standards

This commit is contained in:
Brian Pilati 2014-03-10 21:04:56 -06:00
parent 365e93f16a
commit 6e6524e481
14 changed files with 68 additions and 122 deletions

View file

@ -47,13 +47,12 @@ In your local scratch directory
$ npm install $ npm install
``` ```
Local copy of jQuery and mock-ajax Local copy of jQuery
---------------------------------- --------------------
``` ```
$ cd test/lib $ cd test/lib
$ curl http://code.jquery.com/jquery-1.11.0.min.js > jquery-1.11.0.min.js $ curl http://code.jquery.com/jquery-1.11.0.min.js > jquery-1.11.0.min.js
$ curl http://cloud.github.com/downloads/pivotal/jasmine-ajax/mock-ajax.js > mock-ajax.js
``` ```
To Run the tests To Run the tests

View file

@ -9,7 +9,7 @@
<script src=//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js></script> <script src=//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js></script>
<script type="text/javascript"> <script>
$(document).ready(function() { $(document).ready(function() {
var project_id = location.hash && parseInt(location.hash.substr(1)) || 10000160; var project_id = location.hash && parseInt(location.hash.substr(1)) || 10000160;
var scratch = new Scratch(project_id); var scratch = new Scratch(project_id);

View file

@ -273,15 +273,13 @@ Sprite.prototype.onClick = function(evt) {
}; };
Sprite.prototype.setVisible = function(v) { Sprite.prototype.setVisible = function(v) {
if (v === true || v === false) { this.visible = v;
this.visible = v; this.updateVisible();
this.updateVisible();
}
}; };
Sprite.prototype.updateLayer = function() { Sprite.prototype.updateLayer = function() {
$(this.mesh).css('z-index', this.z); $(this.mesh).css('z-index', this.z);
if (this.talkBubble) $(this.talkBubble).css('z-index', this.z); if (this.talkBubble) this.talkBubble.css('z-index', this.z);
if (this.askInput) this.askInput.css('z-index', this.z); if (this.askInput) this.askInput.css('z-index', this.z);
}; };

View file

@ -20,72 +20,28 @@ var ReporterValues = function() {
} }
}; };
/* /*
cmd Additional Reporter examples
"getVar:" cmd : "getVar:"
color : 15629590
isDiscrete : true
mode : 1
param : "myAnswer2"
sliderMax : 100
sliderMin : 0
target : "Sprite1"
visible : true
x : 5
y : 32
color cmd : "getVar:"
15629590 color : 15629590
isDiscrete : true
isDiscrete mode : 1
true param : "answer"
sliderMax : 100
mode sliderMin : 0
1 target : "Sprite1"
visible : true
param x : 5
"myAnswer2" y : 59
sliderMax
100
sliderMin
0
target
"Sprite1"
visible
true
x
5
y
32
*/
/*
cmd
"getVar:"
color
15629590
isDiscrete
true
mode
1
param
"answer"
sliderMax
100
sliderMin
0
target
"Sprite1"
visible
true
x
5
y
59
*/ */

View file

@ -1,13 +1,13 @@
/* jasmine specs for Interpreter.js go here */ /* jasmine specs for Interpreter.js go here */
describe ('Interpreter', function() { describe('Interpreter', function() {
var interp; var interp;
beforeEach(function() { beforeEach(function() {
interp = Interpreter; interp = Interpreter;
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initInterp, realThread, realTimer; var initInterp, realThread, realTimer;
beforeEach(function() { beforeEach(function() {
realThread = Thread; realThread = Thread;

View file

@ -13,10 +13,6 @@ describe('IO', function(){
expect(io.data).toBe(null); expect(io.data).toBe(null);
}); });
it('should have "null" data', function() {
expect(io.data).toBe(null);
});
it('should have a base', function() { it('should have a base', function() {
expect(io.base).toBe(io_base); expect(io.base).toBe(io_base);
}); });

View file

@ -1,13 +1,13 @@
/* jasmine specs for primitives/LooksPrims.js go here */ /* jasmine specs for primitives/LooksPrims.js go here */
describe ('LooksPrims', function() { describe('LooksPrims', function() {
var looksPrims, targetSpriteMock; var looksPrims, targetSpriteMock;
beforeEach(function() { beforeEach(function() {
looksPrims = LooksPrims; looksPrims = LooksPrims;
targetSpriteMock = targetMock(); targetSpriteMock = targetMock();
}); });
describe('showBubble for Say', function(){ describe('showBubble for say', function(){
var sayBlock; var sayBlock;
beforeEach(function() { beforeEach(function() {
sayBlock = {'args': ['what to say']}; sayBlock = {'args': ['what to say']};
@ -21,7 +21,7 @@ describe ('LooksPrims', function() {
}); });
}); });
describe('showBubble for Think', function(){ describe('showBubble for think', function(){
var thinkBlock; var thinkBlock;
beforeEach(function() { beforeEach(function() {
thinkBlock = {'args': ['what to think']}; thinkBlock = {'args': ['what to think']};
@ -35,7 +35,7 @@ describe ('LooksPrims', function() {
}); });
}); });
describe('showBubble for Ask', function(){ describe('showBubble for ask', function(){
var askBlock; var askBlock;
beforeEach(function() { beforeEach(function() {
askBlock = {'args': ['what to ask']}; askBlock = {'args': ['what to ask']};

View file

@ -1,6 +1,6 @@
/* jasmine specs for Reporter.js go here */ /* jasmine specs for Reporter.js go here */
describe ('Reporter', function() { describe('Reporter', function() {
var reporter, reporterValues; var reporter, reporterValues;
beforeEach(function() { beforeEach(function() {
@ -8,7 +8,7 @@ describe ('Reporter', function() {
reporterValues = new ReporterValues(); reporterValues = new ReporterValues();
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initReporter; var initReporter;
beforeEach(function() { beforeEach(function() {
io = new ioMock({'getCount': 4}); io = new ioMock({'getCount': 4});

View file

@ -1,13 +1,13 @@
/* jasmine specs for Runtime.js go here */ /* jasmine specs for Runtime.js go here */
describe ('Runtime', function() { describe('Runtime', function() {
var runtimeObj; var runtimeObj;
beforeEach(function() { beforeEach(function() {
runtimeObj = Runtime; runtimeObj = Runtime;
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initRuntime, lineCanvas; var initRuntime, lineCanvas;
beforeEach(function() { beforeEach(function() {
initRuntime = new runtimeObj(); initRuntime = new runtimeObj();
@ -83,9 +83,9 @@ describe ('Runtime', function() {
expect(interp.activeThread).toEqual(new threadMock()); expect(interp.activeThread).toEqual(new threadMock());
}); });
it('should call a blank thread array ', function() { it('should intitialize an empty threads array', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(interp.activeThread).toEqual(new threadMock()); expect(interp.threads).toEqual([]);
}); });
it('should call stopAllSounds', function() { it('should call stopAllSounds', function() {

View file

@ -1,30 +1,36 @@
/* jasmine specs for Scratch.js go here */ /* jasmine specs for Scratch.js go here */
describe ('Scratch', function() { describe('Scratch', function() {
var scratch;
beforeEach(function() {
spyOn(IO.prototype, "loadProject");
spyOn(Runtime.prototype, "init");
spyOn(Interpreter.prototype, "initPrims");
scratch = Scratch;
});
describe('Scratch - Load Project', function(){ describe('Scratch - Load Project', function(){
var request, scratch;
var callBack = jasmine.createSpy('onSuccess');
var TestResponses = { status: 200, responseText: returnData};
beforeEach(function() { beforeEach(function() {
jasmine.Ajax.useMock();
scratch = Scratch;
scratch(project_id); scratch(project_id);
request = mostRecentAjaxRequest();
request.promise(TestResponses, callBack);
}); });
it('should call the internalapi project', function() { it('should call the IO loadProject Method', function() {
expect(request.url).toBe("proxy.php?resource=internalapi/project/" + project_id + "/get/"); expect(IO.prototype.loadProject).toHaveBeenCalled();
expect(callBack).toHaveBeenCalled(); });
it('should call the Runtime init method', function() {
expect(Runtime.prototype.init).toHaveBeenCalled();
});
it('should call the Interpreter initPrims method', function() {
expect(Interpreter.prototype.initPrims).toHaveBeenCalled();
}); });
}); });
describe('Scratch - Click Green Flag', function(){ describe('Scratch - Click Green Flag', function(){
beforeEach(function() { beforeEach(function() {
setFixtures('<button id=trigger-green-flag tabindex=2></button><div id="overlay"></div>'); setFixtures('<button id=trigger-green-flag tabindex=2></button><div id="overlay"></div>');
scratch = Scratch;
scratch(project_id); scratch(project_id);
}); });
@ -48,7 +54,6 @@ describe ('Scratch', function() {
describe('Scratch - Click Stop', function(){ describe('Scratch - Click Stop', function(){
beforeEach(function() { beforeEach(function() {
setFixtures('<button id=trigger-stop tabindex=3></button>'); setFixtures('<button id=trigger-stop tabindex=3></button>');
scratch = Scratch;
scratch(project_id); scratch(project_id);
}); });

View file

@ -1,6 +1,6 @@
/* jasmine specs for primitives/SensingPrims.js go here */ /* jasmine specs for primitives/SensingPrims.js go here */
describe ('SensingPrims', function() { describe('SensingPrims', function() {
var sensingPrims; var sensingPrims;
beforeEach(function() { beforeEach(function() {
sensingPrims = SensingPrims; sensingPrims = SensingPrims;

View file

@ -1,13 +1,13 @@
/* jasmine specs for Sprite.js go here */ /* jasmine specs for Sprite.js go here */
describe ('Sprite', function() { describe('Sprite', function() {
var sprite; var sprite;
beforeEach(function() { beforeEach(function() {
sprite = Sprite; sprite = Sprite;
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initSprite; var initSprite;
beforeEach(function() { beforeEach(function() {
var spriteObject = sensingData.children[0]; var spriteObject = sensingData.children[0];
@ -386,13 +386,5 @@ describe ('Sprite', function() {
expect(spriteProto.visible).toBe(false); expect(spriteProto.visible).toBe(false);
expect(spriteProto.updateVisible).toHaveBeenCalled(); expect(spriteProto.updateVisible).toHaveBeenCalled();
}); });
it('should set take no action on an invalid character', function() {
spriteProto.visible = true;
spriteProto.setVisible('hello');
expect(spriteProto.visible).toBe(true);
expect(spriteProto.updateVisible).not.toHaveBeenCalled();
});
}); });
}); });

View file

@ -1,13 +1,13 @@
/* jasmine specs for Stage.js go here */ /* jasmine specs for Stage.js go here */
describe ('Stage', function() { describe('Stage', function() {
var stage; var stage;
beforeEach(function() { beforeEach(function() {
stage = Stage; stage = Stage;
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initStage, lineCanvas; var initStage, lineCanvas;
beforeEach(function() { beforeEach(function() {
spyOn(Sprite, "call"); spyOn(Sprite, "call");

View file

@ -1,13 +1,13 @@
/* jasmine specs for Interpreter.js -> Thread go here */ /* jasmine specs for Interpreter.js -> Thread go here */
describe ('Thread', function() { describe('Thread', function() {
var thread; var thread;
beforeEach(function() { beforeEach(function() {
thread = Thread; thread = Thread;
}); });
describe('Instantization variables', function() { describe('Initialized variables', function() {
var initThread; var initThread;
beforeEach(function() { beforeEach(function() {
initThread = new thread('block', 'target'); initThread = new thread('block', 'target');