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();
}
};
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

@ -7,7 +7,7 @@ describe ('Interpreter', 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

@ -7,7 +7,7 @@ describe ('LooksPrims', function() {
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

@ -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

@ -7,7 +7,7 @@ describe ('Runtime', 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 - Load Project', function(){
var request, scratch;
var callBack = jasmine.createSpy('onSuccess');
var TestResponses = { status: 200, responseText: returnData};
var scratch;
beforeEach(function() {
jasmine.Ajax.useMock();
spyOn(IO.prototype, "loadProject");
spyOn(Runtime.prototype, "init");
spyOn(Interpreter.prototype, "initPrims");
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();
describe('Scratch - Load Project', function(){
beforeEach(function() {
scratch(project_id);
});
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

@ -7,7 +7,7 @@ describe ('Sprite', 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

@ -7,7 +7,7 @@ describe ('Stage', function() {
stage = Stage;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initStage, lineCanvas;
beforeEach(function() {
spyOn(Sprite, "call");

View file

@ -7,7 +7,7 @@ describe ('Thread', function() {
thread = Thread;
});
describe('Instantization variables', function() {
describe('Initialized variables', function() {
var initThread;
beforeEach(function() {
initThread = new thread('block', 'target');