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
```
Local copy of jQuery and mock-ajax
----------------------------------
Local copy of jQuery
--------------------
```
$ cd test/lib
$ 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

View file

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

View file

@ -273,15 +273,13 @@ Sprite.prototype.onClick = function(evt) {
};
Sprite.prototype.setVisible = function(v) {
if (v === true || v === false) {
this.visible = v;
this.updateVisible();
}
this.visible = v;
this.updateVisible();
};
Sprite.prototype.updateLayer = function() {
$(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);
};

View file

@ -20,72 +20,28 @@ var ReporterValues = function() {
}
};
/*
cmd
"getVar:"
Additional Reporter examples
cmd : "getVar:"
color : 15629590
isDiscrete : true
mode : 1
param : "myAnswer2"
sliderMax : 100
sliderMin : 0
target : "Sprite1"
visible : true
x : 5
y : 32
color
15629590
isDiscrete
true
mode
1
param
"myAnswer2"
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
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 */
describe ('Interpreter', function() {
describe('Interpreter', function() {
var interp;
beforeEach(function() {
interp = Interpreter;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initInterp, realThread, realTimer;
beforeEach(function() {
realThread = Thread;

View file

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

View file

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

View file

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

View file

@ -1,13 +1,13 @@
/* jasmine specs for Runtime.js go here */
describe ('Runtime', function() {
describe('Runtime', function() {
var runtimeObj;
beforeEach(function() {
runtimeObj = Runtime;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initRuntime, lineCanvas;
beforeEach(function() {
initRuntime = new runtimeObj();
@ -83,9 +83,9 @@ describe ('Runtime', function() {
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();
expect(interp.activeThread).toEqual(new threadMock());
expect(interp.threads).toEqual([]);
});
it('should call stopAllSounds', function() {

View file

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

View file

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

View file

@ -1,13 +1,13 @@
/* jasmine specs for Sprite.js go here */
describe ('Sprite', function() {
describe('Sprite', function() {
var sprite;
beforeEach(function() {
sprite = Sprite;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initSprite;
beforeEach(function() {
var spriteObject = sensingData.children[0];
@ -386,13 +386,5 @@ describe ('Sprite', function() {
expect(spriteProto.visible).toBe(false);
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 */
describe ('Stage', function() {
describe('Stage', function() {
var stage;
beforeEach(function() {
stage = Stage;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initStage, lineCanvas;
beforeEach(function() {
spyOn(Sprite, "call");

View file

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