mirror of
https://github.com/scratchfoundation/scratch-html5.git
synced 2024-12-01 03:16:59 -05:00
additional tests in preparation to adding the "ask" functionality
This commit is contained in:
parent
23cc21b7d9
commit
3842832e52
8 changed files with 204 additions and 11 deletions
|
@ -10,7 +10,8 @@ module.exports = function(config){
|
|||
'js/sound/**/*.js',
|
||||
'js/util/**/*.js',
|
||||
'js/**/*.js',
|
||||
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
|
||||
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
|
||||
'node_modules/underscore/underscore.js'
|
||||
],
|
||||
|
||||
exclude : [
|
||||
|
@ -27,10 +28,10 @@ module.exports = function(config){
|
|||
browsers : ['Chrome'],
|
||||
|
||||
plugins : [
|
||||
'karma-jasmine',
|
||||
'jasmine-jquery',
|
||||
'karma-html2js-preprocessor',
|
||||
'karma-chrome-launcher',
|
||||
'karma-firefox-launcher'
|
||||
]
|
||||
'karma-jasmine',
|
||||
'jasmine-jquery',
|
||||
'karma-html2js-preprocessor',
|
||||
'karma-chrome-launcher',
|
||||
'karma-firefox-launcher'
|
||||
]
|
||||
})}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"devDependencies": {
|
||||
"karma" : "~0.10",
|
||||
"jasmine-jquery" : "1.3.3",
|
||||
"karma-html2js-preprocessor" : "~0.1.0"
|
||||
"karma-html2js-preprocessor" : "~0.1.0",
|
||||
"underscore" : "~1.6.0"
|
||||
}
|
||||
}
|
||||
|
|
26
test/artifacts/InterpreterMock.js
Normal file
26
test/artifacts/InterpreterMock.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
var interpreterMock = 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 {
|
||||
'targetSprite' : function() { return getArgs('targetSprite'); },
|
||||
'arg': function(block, index) { return getArgs('arg');}
|
||||
}
|
||||
};
|
8
test/artifacts/TargetMock.js
Normal file
8
test/artifacts/TargetMock.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
var targetMock = function() {
|
||||
return {
|
||||
'showBubble' : function() {}
|
||||
};
|
||||
|
||||
}
|
55
test/artifacts/ask-artifact.js
Normal file
55
test/artifacts/ask-artifact.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
var sensingData = {
|
||||
"objName": "Stage",
|
||||
"costumes": [{
|
||||
"costumeName": "backdrop1",
|
||||
"baseLayerID": -1,
|
||||
"baseLayerMD5": "b61b1077b0ea1931abee9dbbfa7903ff.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 480,
|
||||
"rotationCenterY": 360
|
||||
}],
|
||||
"currentCostumeIndex": 0,
|
||||
"penLayerMD5": "5c81a336fab8be57adc039a8a2b33ca9.png",
|
||||
"tempoBPM": 60,
|
||||
"videoAlpha": 0.5,
|
||||
"children": [{
|
||||
"objName": "Sprite1",
|
||||
"scripts": [[42, 40.5, [["whenGreenFlag"], ["doAsk", "What's your name?"]]],
|
||||
[44.5,
|
||||
155.5,
|
||||
[["whenGreenFlag"],
|
||||
["say:", "Hello!"],
|
||||
["doIf", ["=", ["timeAndDate", "minute"], "60"], [["say:", ["timestamp"]]]]]]],
|
||||
"costumes": [{
|
||||
"costumeName": "costume1",
|
||||
"baseLayerID": -1,
|
||||
"baseLayerMD5": "f9a1c175dbe2e5dee472858dd30d16bb.svg",
|
||||
"bitmapResolution": 1,
|
||||
"rotationCenterX": 47,
|
||||
"rotationCenterY": 55
|
||||
}],
|
||||
"currentCostumeIndex": 0,
|
||||
"scratchX": 0,
|
||||
"scratchY": 0,
|
||||
"scale": 1,
|
||||
"direction": 90,
|
||||
"rotationStyle": "normal",
|
||||
"isDraggable": false,
|
||||
"indexInLibrary": 1,
|
||||
"visible": true,
|
||||
"spriteInfo": {
|
||||
}
|
||||
}],
|
||||
"info": {
|
||||
"projectID": "18926654",
|
||||
"spriteCount": 1,
|
||||
"flashVersion": "MAC 12,0,0,70",
|
||||
"swfVersion": "v396",
|
||||
"userAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko\/20100101 Firefox\/27.0",
|
||||
"videoOn": false,
|
||||
"scriptCount": 2,
|
||||
"hasCloudData": false
|
||||
}
|
||||
};
|
23
test/unit/looksPrimitiveSpec.js
Normal file
23
test/unit/looksPrimitiveSpec.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* jasmine specs for primitives/LooksPrims.js go here */
|
||||
|
||||
describe ('LooksPrims', function() {
|
||||
var looksPrims;
|
||||
beforeEach(function() {
|
||||
looksPrims = LooksPrims;
|
||||
});
|
||||
|
||||
describe('showBubble', function(){
|
||||
var sayBlock, targetSpriteMock;
|
||||
beforeEach(function() {
|
||||
sayBlock = {'args': ['what to say']};
|
||||
targetSpriteMock = targetMock();
|
||||
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': sayBlock});
|
||||
|
||||
});
|
||||
it('should return do something', function() {
|
||||
spyOn(targetSpriteMock, "showBubble");
|
||||
showBubble(sayBlock, "say");
|
||||
expect(targetSpriteMock.showBubble).toHaveBeenCalled;
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
describe ('Scratch', function() {
|
||||
describe('Scratch - Load Project', function(){
|
||||
var getScript, request, scratch;
|
||||
var uri = "http://getScript.example.com";
|
||||
var request, scratch;
|
||||
var callBack = jasmine.createSpy('onSuccess');
|
||||
var testResponseText = 'This is a script';
|
||||
|
||||
var TestResponses = { status: 200, responseText: returnData};
|
||||
|
||||
|
|
81
test/unit/sensingPrimitiveSpec.js
Normal file
81
test/unit/sensingPrimitiveSpec.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* jasmine specs for primitives/SensingPrims.js go here */
|
||||
|
||||
describe ('SensingPrims', function() {
|
||||
var sensingPrims;
|
||||
beforeEach(function() {
|
||||
sensingPrims = SensingPrims;
|
||||
realDate = Date;
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Date = realDate;
|
||||
});
|
||||
|
||||
describe('primTimestamp', function(){
|
||||
beforeEach(function() {
|
||||
/* MonkeyPatching the built-in Javascript Date */
|
||||
var epochDate = new Date(2000, 0, 1);
|
||||
var nowDate = new Date(2014, 5, 16);
|
||||
Date = function () {
|
||||
return (arguments.length ? epochDate : nowDate);
|
||||
};
|
||||
});
|
||||
|
||||
it('should return the days since 2000', function() {
|
||||
expect(sensingPrims.prototype.primTimestamp()).toEqual(5280.25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('primTimeDate', function(){
|
||||
beforeEach(function() {
|
||||
/* MonkeyPatching the built-in Javascript Date */
|
||||
Date = function () {
|
||||
return {
|
||||
'getFullYear' : function() { return 2014;},
|
||||
'getMonth' : function() { return 4;},
|
||||
'getDate' : function() { return 16;},
|
||||
'getDay' : function() { return 4;},
|
||||
'getHours' : function() { return 9;},
|
||||
'getMinutes' : function() { return 18;},
|
||||
'getSeconds' : function() { return 36;},
|
||||
'getTime' : function() {}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
it('should return the year', function() {
|
||||
var block = {'args' : ['year']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(2014);
|
||||
});
|
||||
|
||||
it('should return the month of the year', function() {
|
||||
var block = {'args' : ['month']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
|
||||
});
|
||||
|
||||
it('should return the day of the week', function() {
|
||||
var block = {'args' : ['day of week']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
|
||||
});
|
||||
|
||||
it('should return the hour of the day', function() {
|
||||
var block = {'args' : ['hour']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(9);
|
||||
});
|
||||
|
||||
it('should return the minute of the hour', function() {
|
||||
var block = {'args' : ['minute']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(18);
|
||||
});
|
||||
|
||||
it('should return the second of the minute', function() {
|
||||
var block = {'args' : ['second']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(36);
|
||||
});
|
||||
|
||||
it('should return the 0 on year', function() {
|
||||
var block = {'args' : ['anythingElse']};
|
||||
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue