Skip to content
This repository was archived by the owner on Jun 19, 2018. It is now read-only.

Commit 3842832

Browse files
committed
additional tests in preparation to adding the "ask" functionality
1 parent 23cc21b commit 3842832

8 files changed

+204
-11
lines changed

Diff for: config/karma.conf.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = function(config){
1010
'js/sound/**/*.js',
1111
'js/util/**/*.js',
1212
'js/**/*.js',
13-
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
13+
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
14+
'node_modules/underscore/underscore.js'
1415
],
1516

1617
exclude : [
@@ -27,10 +28,10 @@ module.exports = function(config){
2728
browsers : ['Chrome'],
2829

2930
plugins : [
30-
'karma-jasmine',
31-
'jasmine-jquery',
32-
'karma-html2js-preprocessor',
33-
'karma-chrome-launcher',
34-
'karma-firefox-launcher'
35-
]
31+
'karma-jasmine',
32+
'jasmine-jquery',
33+
'karma-html2js-preprocessor',
34+
'karma-chrome-launcher',
35+
'karma-firefox-launcher'
36+
]
3637
})}

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"devDependencies": {
66
"karma" : "~0.10",
77
"jasmine-jquery" : "1.3.3",
8-
"karma-html2js-preprocessor" : "~0.1.0"
8+
"karma-html2js-preprocessor" : "~0.1.0",
9+
"underscore" : "~1.6.0"
910
}
1011
}

Diff for: test/artifacts/InterpreterMock.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
var interpreterMock = function() {
4+
var args = createArgs(arguments);
5+
6+
function getArgs(argKey) {
7+
return ((argKey in args) ? args[argKey] : null);
8+
}
9+
10+
function createArgs(methodArgs) {
11+
var args = {};
12+
if (methodArgs.length) {
13+
_.each(methodArgs, function(newObject) {
14+
_.each(newObject, function(value, key) {
15+
args[key] = value;
16+
});
17+
});
18+
}
19+
return args;
20+
}
21+
22+
return {
23+
'targetSprite' : function() { return getArgs('targetSprite'); },
24+
'arg': function(block, index) { return getArgs('arg');}
25+
}
26+
};

Diff for: test/artifacts/TargetMock.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
var targetMock = function() {
4+
return {
5+
'showBubble' : function() {}
6+
};
7+
8+
}

Diff for: test/artifacts/ask-artifact.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
var sensingData = {
4+
"objName": "Stage",
5+
"costumes": [{
6+
"costumeName": "backdrop1",
7+
"baseLayerID": -1,
8+
"baseLayerMD5": "b61b1077b0ea1931abee9dbbfa7903ff.png",
9+
"bitmapResolution": 2,
10+
"rotationCenterX": 480,
11+
"rotationCenterY": 360
12+
}],
13+
"currentCostumeIndex": 0,
14+
"penLayerMD5": "5c81a336fab8be57adc039a8a2b33ca9.png",
15+
"tempoBPM": 60,
16+
"videoAlpha": 0.5,
17+
"children": [{
18+
"objName": "Sprite1",
19+
"scripts": [[42, 40.5, [["whenGreenFlag"], ["doAsk", "What's your name?"]]],
20+
[44.5,
21+
155.5,
22+
[["whenGreenFlag"],
23+
["say:", "Hello!"],
24+
["doIf", ["=", ["timeAndDate", "minute"], "60"], [["say:", ["timestamp"]]]]]]],
25+
"costumes": [{
26+
"costumeName": "costume1",
27+
"baseLayerID": -1,
28+
"baseLayerMD5": "f9a1c175dbe2e5dee472858dd30d16bb.svg",
29+
"bitmapResolution": 1,
30+
"rotationCenterX": 47,
31+
"rotationCenterY": 55
32+
}],
33+
"currentCostumeIndex": 0,
34+
"scratchX": 0,
35+
"scratchY": 0,
36+
"scale": 1,
37+
"direction": 90,
38+
"rotationStyle": "normal",
39+
"isDraggable": false,
40+
"indexInLibrary": 1,
41+
"visible": true,
42+
"spriteInfo": {
43+
}
44+
}],
45+
"info": {
46+
"projectID": "18926654",
47+
"spriteCount": 1,
48+
"flashVersion": "MAC 12,0,0,70",
49+
"swfVersion": "v396",
50+
"userAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko\/20100101 Firefox\/27.0",
51+
"videoOn": false,
52+
"scriptCount": 2,
53+
"hasCloudData": false
54+
}
55+
};

Diff for: test/unit/looksPrimitiveSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* jasmine specs for primitives/LooksPrims.js go here */
2+
3+
describe ('LooksPrims', function() {
4+
var looksPrims;
5+
beforeEach(function() {
6+
looksPrims = LooksPrims;
7+
});
8+
9+
describe('showBubble', function(){
10+
var sayBlock, targetSpriteMock;
11+
beforeEach(function() {
12+
sayBlock = {'args': ['what to say']};
13+
targetSpriteMock = targetMock();
14+
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': sayBlock});
15+
16+
});
17+
it('should return do something', function() {
18+
spyOn(targetSpriteMock, "showBubble");
19+
showBubble(sayBlock, "say");
20+
expect(targetSpriteMock.showBubble).toHaveBeenCalled;
21+
});
22+
});
23+
});

Diff for: test/unit/scratchSpec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
describe ('Scratch', function() {
44
describe('Scratch - Load Project', function(){
5-
var getScript, request, scratch;
6-
var uri = "http://getScript.example.com";
5+
var request, scratch;
76
var callBack = jasmine.createSpy('onSuccess');
8-
var testResponseText = 'This is a script';
97

108
var TestResponses = { status: 200, responseText: returnData};
119

Diff for: test/unit/sensingPrimitiveSpec.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* jasmine specs for primitives/SensingPrims.js go here */
2+
3+
describe ('SensingPrims', function() {
4+
var sensingPrims;
5+
beforeEach(function() {
6+
sensingPrims = SensingPrims;
7+
realDate = Date;
8+
});
9+
10+
afterEach(function () {
11+
Date = realDate;
12+
});
13+
14+
describe('primTimestamp', function(){
15+
beforeEach(function() {
16+
/* MonkeyPatching the built-in Javascript Date */
17+
var epochDate = new Date(2000, 0, 1);
18+
var nowDate = new Date(2014, 5, 16);
19+
Date = function () {
20+
return (arguments.length ? epochDate : nowDate);
21+
};
22+
});
23+
24+
it('should return the days since 2000', function() {
25+
expect(sensingPrims.prototype.primTimestamp()).toEqual(5280.25);
26+
});
27+
});
28+
29+
describe('primTimeDate', function(){
30+
beforeEach(function() {
31+
/* MonkeyPatching the built-in Javascript Date */
32+
Date = function () {
33+
return {
34+
'getFullYear' : function() { return 2014;},
35+
'getMonth' : function() { return 4;},
36+
'getDate' : function() { return 16;},
37+
'getDay' : function() { return 4;},
38+
'getHours' : function() { return 9;},
39+
'getMinutes' : function() { return 18;},
40+
'getSeconds' : function() { return 36;},
41+
'getTime' : function() {}
42+
};
43+
};
44+
});
45+
46+
it('should return the year', function() {
47+
var block = {'args' : ['year']};
48+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(2014);
49+
});
50+
51+
it('should return the month of the year', function() {
52+
var block = {'args' : ['month']};
53+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
54+
});
55+
56+
it('should return the day of the week', function() {
57+
var block = {'args' : ['day of week']};
58+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
59+
});
60+
61+
it('should return the hour of the day', function() {
62+
var block = {'args' : ['hour']};
63+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(9);
64+
});
65+
66+
it('should return the minute of the hour', function() {
67+
var block = {'args' : ['minute']};
68+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(18);
69+
});
70+
71+
it('should return the second of the minute', function() {
72+
var block = {'args' : ['second']};
73+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(36);
74+
});
75+
76+
it('should return the 0 on year', function() {
77+
var block = {'args' : ['anythingElse']};
78+
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(0);
79+
});
80+
});
81+
});

0 commit comments

Comments
 (0)