Skip to content

Commit

Permalink
Merge pull request #20922 from code-dot-org/staging
Browse files Browse the repository at this point in the history
DTT (Staging > Test) [robo-dtt]
  • Loading branch information
deploy-code-org committed Feb 27, 2018
2 parents 6b10894 + 33895ba commit 0a203be
Show file tree
Hide file tree
Showing 30 changed files with 305 additions and 131 deletions.
37 changes: 20 additions & 17 deletions apps/src/gamelab/AnimationPicker/animationPickerModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,33 @@ export function beginUpload(filename) {
*/
export function handleUploadComplete(result) {
return function (dispatch, getState) {
const { goal, uploadFilename } = getState().animationPicker;
const key = result.filename.replace(/\.png$/i, '');
const sourceUrl = animationsApi.basePath(key + '.png');

loadImageMetadata(sourceUrl, metadata => {
const animation = _.assign({}, metadata, {
name: uploadFilename,
sourceUrl: sourceUrl,
size: result.size,
version: result.versionId
});

if (goal === Goal.NEW_ANIMATION) {
dispatch(addAnimation(key, animation));
} else if (goal === Goal.NEW_FRAME) {
dispatch(appendCustomFrames(animation));
}
dispatch(hide());
}, () => {
const onImageMetadataLoaded = buildOnImageMetadataLoaded(key, result, dispatch, getState);
loadImageMetadata(sourceUrl, onImageMetadataLoaded, () => {
dispatch(handleUploadError(gamelabMsg.animationPicker_failedToParseImage()));
});
};
}

export function buildOnImageMetadataLoaded(key, result, dispatch, getState) {
return (metadata) => {
const { goal, uploadFilename } = getState().animationPicker;
const animation = _.assign({}, metadata, {
name: uploadFilename,
sourceUrl: null,
size: result.size,
version: result.versionId
});
if (goal === Goal.NEW_ANIMATION) {
dispatch(addAnimation(key, animation));
} else if (goal === Goal.NEW_FRAME) {
dispatch(appendCustomFrames(animation));
}
dispatch(hide());
};
}

/**
* Asynchronously loads an image file as an Image, then derives appropriate
* animation metadata from that Image and returns the metadata to a callback.
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/kits/maker/Button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Wrapper around Johnny-Five Button component */
import five from '@code-dot-org/johnny-five';
import '../../../utils'; // For Function.prototype.inherits
import {TOUCH_PINS} from "./PlaygroundConstants";
import {EXTERNAL_PINS} from "./PlaygroundConstants";

/**
* Wrap Johnny-Five's Button component to add attributes and customize behavior.
Expand All @@ -11,7 +11,7 @@ import {TOUCH_PINS} from "./PlaygroundConstants";
*/
export default function Button(opts) {
// For Circuit Playground, treat touch pin buttons as pullups.
opts.pullup = TOUCH_PINS.includes(opts.pin);
opts.pullup = EXTERNAL_PINS.includes(opts.pin);
five.Button.call(this, opts);

// Add a read-only `isPressed` property
Expand Down
3 changes: 2 additions & 1 deletion apps/src/lib/kits/maker/PlaygroundConstants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import experiments from '../../../util/experiments';
export const N_COLOR_LEDS = 10;
export const TOUCH_PINS = [0, 1, 2, 3, 6, 9, 10, 12];
export const EXTERNAL_PINS = [0, 1, 2, 3, 6, 9, 10, 12];
export const TOUCH_PINS = [0, 2, 3, 6, 9, 10, 12];
export const J5_CONSTANTS = {
INPUT: 0,
OUTPUT: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import sinon from 'sinon';
import reducer, * as animationPickerModule from '@cdo/apps/gamelab/AnimationPicker/animationPickerModule';
import listReducer from '@cdo/apps/gamelab/animationListModule';
import {combineReducers} from 'redux';
import {createStore} from '../../../util/redux';
import {expect} from '../../../util/configuredChai';
var Goal = animationPickerModule.Goal;

Expand Down Expand Up @@ -102,5 +106,46 @@ describe('animationPickerModule', function () {
expect(newState.uploadError).to.equal(status);
});
});

describe('action: handleUploadComplete', function () {

it('sets sourceUrl to null', function () {
const fakeDispatch = sinon.spy();
const newState = {animationPicker: { uploadFilename: "filename.jpg", goal: Goal.NEW_ANIMATION }};
var store = createStore(combineReducers({animationList: listReducer, animationPicker: reducer}), newState);

var onMetadataLoaded = animationPickerModule.buildOnImageMetadataLoaded(
"filename.jpg",
{
filename: "filename.jpg",
result: 0,
versionId: "string"
},
fakeDispatch,
store.getState
);
onMetadataLoaded({});
expect(fakeDispatch).to.have.been.calledTwice;

const addAnimation = fakeDispatch.firstCall.args[0];
expect(addAnimation).to.be.a('function');
expect(fakeDispatch.secondCall.args[0]).to.deep.equal(animationPickerModule.hide());
fakeDispatch.reset();

addAnimation(fakeDispatch, store.getState);
expect(fakeDispatch.firstCall.args[0]).to.deep.equal({
type: 'AnimationList/ADD_ANIMATION',
key: 'filename.jpg',
props:
{
name: 'filename.jpg',
sourceUrl: null,
size: undefined,
version: 'string',
looping: true
}
});
});
});
});
});
10 changes: 5 additions & 5 deletions apps/test/unit/lib/kits/maker/ButtonTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {expect} from '../../../../util/configuredChai';
import five from '@code-dot-org/johnny-five';
import makeStubBoard from './makeStubBoard';
import Button from '@cdo/apps/lib/kits/maker/Button';
import {TOUCH_PINS} from '@cdo/apps/lib/kits/maker/PlaygroundConstants';
import {EXTERNAL_PINS} from '@cdo/apps/lib/kits/maker/PlaygroundConstants';

describe('Button', function () {
it('is a johnny-five Button component', function () {
Expand Down Expand Up @@ -35,8 +35,8 @@ describe('Button', function () {
});
});

it('becomes a pullup when assigned to a touch pin', () => {
TOUCH_PINS.forEach((pin) => {
it('becomes a pullup when assigned to an external pin', () => {
EXTERNAL_PINS.forEach((pin) => {
const button = new Button({
board: makeStubBoard(),
pin
Expand All @@ -45,9 +45,9 @@ describe('Button', function () {
});
});

it('does not become a pullup when assigned to a non-touch pin', () => {
it('does not become a pullup when assigned to a non-external pin', () => {
_.range(21)
.filter(pin => !TOUCH_PINS.includes(pin))
.filter(pin => !EXTERNAL_PINS.includes(pin))
.forEach((pin) => {
const button = new Button({
board: makeStubBoard(),
Expand Down
13 changes: 6 additions & 7 deletions apps/test/unit/lib/kits/maker/CircuitPlaygroundBoardTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {EventEmitter} from 'events'; // see node-libs-browser
import Playground from 'playground-io';
import five from '@code-dot-org/johnny-five';
import CircuitPlaygroundBoard from '@cdo/apps/lib/kits/maker/CircuitPlaygroundBoard';
import {SONG_CHARGE, TOUCH_PINS} from '@cdo/apps/lib/kits/maker/PlaygroundConstants';
import {SONG_CHARGE, EXTERNAL_PINS} from '@cdo/apps/lib/kits/maker/PlaygroundConstants';
import Led from '@cdo/apps/lib/kits/maker/Led';
import {itImplementsTheMakerBoardInterface} from './MakerBoardTest';
import experiments from '@cdo/apps/util/experiments';
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('CircuitPlaygroundBoard', () => {

it('initializes a set of components', () => {
return board.connect().then(() => {
expect(Object.keys(board.prewiredComponents_)).to.have.length(24);
expect(Object.keys(board.prewiredComponents_)).to.have.length(23);
expect(board.prewiredComponents_.board).to.be.a('object');
expect(board.prewiredComponents_.colorLeds).to.be.a('array');
expect(board.prewiredComponents_.led).to.be.a('object');
Expand All @@ -83,7 +83,6 @@ describe('CircuitPlaygroundBoard', () => {
expect(board.prewiredComponents_.buttonL).to.be.a('object');
expect(board.prewiredComponents_.buttonR).to.be.a('object');
expect(board.prewiredComponents_.touchPad0).to.be.a('object');
expect(board.prewiredComponents_.touchPad1).to.be.a('object');
expect(board.prewiredComponents_.touchPad2).to.be.a('object');
expect(board.prewiredComponents_.touchPad3).to.be.a('object');
expect(board.prewiredComponents_.touchPad6).to.be.a('object');
Expand Down Expand Up @@ -361,19 +360,19 @@ describe('CircuitPlaygroundBoard', () => {
});
});

it('configures the controller as a pullup if passed a touch pin', () => {
it('configures the controller as a pullup if passed an external pin', () => {
return board.connect().then(() => {
TOUCH_PINS.forEach((pin) => {
EXTERNAL_PINS.forEach((pin) => {
const newButton = board.createButton(pin);
expect(newButton.pullup).to.be.true;
});
});
});

it('does not configure the controller as a pullup if passed a non-touch pin', () => {
it('does not configure the controller as a pullup if passed a non-external pin', () => {
return board.connect().then(() => {
_.range(21)
.filter(pin => !TOUCH_PINS.includes(pin))
.filter(pin => !EXTERNAL_PINS.includes(pin))
.forEach((pin) => {
const newButton = board.createButton(pin);
expect(newButton.pullup).to.be.false;
Expand Down
5 changes: 2 additions & 3 deletions apps/test/unit/lib/kits/maker/PlaygroundComponentsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe('Circuit Playground Components', () => {
'buttonL',
'buttonR',
'touchPad0',
'touchPad1',
'touchPad2',
'touchPad3',
'touchPad6',
Expand Down Expand Up @@ -616,14 +615,14 @@ describe('Circuit Playground Components', () => {
});

it('destroys everything that createCircuitPlaygroundComponents creates', () => {
expect(Object.keys(components)).to.have.length(18);
expect(Object.keys(components)).to.have.length(17);
destroyCircuitPlaygroundComponents(components);
expect(Object.keys(components)).to.have.length(0);
});

it('does not destroy components not created by createCircuitPlaygroundComponents', () => {
components.someOtherComponent = {};
expect(Object.keys(components)).to.have.length(19);
expect(Object.keys(components)).to.have.length(18);
destroyCircuitPlaygroundComponents(components);
expect(Object.keys(components)).to.have.length(1);
expect(components).to.haveOwnProperty('someOtherComponent');
Expand Down
8 changes: 6 additions & 2 deletions dashboard/config/scripts/levels/CSD U3 - car template.level
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
"top_level_procedure_autopopulate": "false",
"disable_if_else_editing": "false",
"expand_debugger": "false",
"contained_level_names": null
"contained_level_names": null,
"encrypted_examples": [

],
"start_blocks": "var finishLine = createSprite(40, 200);\r\nfinishLine.setAnimation(\"finish_line\");\r\n\r\nvar raceCar = createSprite(400, 200);\r\nraceCar.setAnimation(\"race_car\");\r\n\r\nfunction draw() {\r\n // Draw Background\r\n background(\"white\");\r\n \r\n // Update\r\n raceCar.x = raceCar.x - 2;\r\n \r\n // Draw Animations\r\n drawSprites();\r\n}"
},
"published": true,
"notes": "",
"audit_log": "[{\"changed_at\":\"2018-02-26 22:22:15 +0000\",\"changed\":[\"start_animations\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"audit_log": "[{\"changed_at\":\"2018-02-26 22:22:15 +0000\",\"changed\":[\"start_animations\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-27 19:12:24 +0000\",\"changed\":[\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"level_concept_difficulty": {
}
}]]></config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@
"disable_if_else_editing": "false",
"expand_debugger": "false",
"top_level_procedure_autopopulate": "false",
"contained_level_names": null
"contained_level_names": null,
"start_blocks": "var salt = createSprite (200, 200);\r\nsalt.setAnimation(\"salt\");\r\nsalt.rotation = 150;\r\n\r\nfunction draw() {\r\n background(\"skyblue\");\r\n \r\n // If mouseDidMove, rotate the present randomly to the left or right\r\n \r\n drawSprites();\r\n}"
},
"published": true,
"notes": "",
"audit_log": "[{\"changed_at\":\"2017-11-02 16:56:44 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":568,\"changed_by_email\":\"meilani.eyre@code.org\"},{\"changed_at\":\"2018-02-23 21:03:55 +0000\",\"changed\":[\"code_functions\",\"start_animations\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"audit_log": "[{\"changed_at\":\"2017-11-02 16:56:44 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":568,\"changed_by_email\":\"meilani.eyre@code.org\"},{\"changed_at\":\"2018-02-23 21:03:55 +0000\",\"changed\":[\"code_functions\",\"start_animations\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-27 19:13:39 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"level_concept_difficulty": {
}
}]]></config>
Expand Down
5 changes: 3 additions & 2 deletions dashboard/config/scripts/levels/CSD U3 If Else.level
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@
"expand_debugger": "false",
"disable_procedure_autopopulate": "false",
"top_level_procedure_autopopulate": "false",
"contained_level_names": null
"contained_level_names": null,
"start_blocks": "var flower = createSprite(100, 200);\r\nflower.setAnimation(\"flower\");\r\n\r\nvar bee1 = createSprite(randomNumber(0, 400), randomNumber(0, 400));\r\nbee1.setAnimation(\"bee\");\r\nvar bee2 = createSprite(randomNumber(0, 400), randomNumber(0, 400));\r\nbee2.setAnimation(\"bee\");\r\nvar bee3 = createSprite(randomNumber(0, 400), randomNumber(0, 400));\r\nbee3.setAnimation(\"bee\");\r\n\r\nWorld.frameRate = 20;\r\n\r\nfunction draw() {\r\n background('lightgreen');\r\n \r\n bee1.x = mouseX + randomNumber(-50, 50);\r\n bee1.y = mouseY + randomNumber(-50, 50);\r\n \r\n bee2.x = mouseX + randomNumber(-50, 50);\r\n bee2.y = mouseY + randomNumber(-50, 50);\r\n \r\n bee3.x = mouseX + randomNumber(-50, 50);\r\n bee3.y = mouseY + randomNumber(-50, 50);\r\n \r\n drawSprites();\r\n}"
},
"published": true,
"notes": "",
"audit_log": "[{\"changed_at\":\"2017-06-22 17:41:01 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-23 20:57:50 +0000\",\"changed\":[\"code_functions\",\"start_animations\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"audit_log": "[{\"changed_at\":\"2017-06-22 17:41:01 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-23 20:57:50 +0000\",\"changed\":[\"code_functions\",\"start_animations\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-27 18:21:33 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"level_concept_difficulty": {
}
}]]></config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
"expand_debugger": "false",
"disable_procedure_autopopulate": "false",
"top_level_procedure_autopopulate": "false",
"contained_level_names": null
"contained_level_names": null,
"encrypted_examples": [

],
"start_blocks": "function draw(){\r\n \r\n}"
},
"published": true,
"notes": "",
"audit_log": "[{\"changed_at\":\"2018-02-26 22:23:45 +0000\",\"changed\":[\"start_animations\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"audit_log": "[{\"changed_at\":\"2018-02-26 22:23:45 +0000\",\"changed\":[\"start_animations\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-27 19:16:44 +0000\",\"changed\":[\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"level_concept_difficulty": {
}
}]]></config>
Expand Down
5 changes: 3 additions & 2 deletions dashboard/config/scripts/levels/CSD U3 Movement Fish.level
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@
"encrypted_examples": "anMQPIUd+WRm37Dyx7COPPHROWqZ58g9d0j7QKZevdphBmrQjmJhFG3Ouyil\nTlEhpfhOnD4C39C8gkjF8UyxGg==\n",
"disable_procedure_autopopulate": "false",
"top_level_procedure_autopopulate": "false",
"contained_level_names": null
"contained_level_names": null,
"start_blocks": "var orangeFish = createSprite(400, randomNumber(0, 100));\r\norangeFish.setAnimation(\"orange_fish\");\r\nvar blueFish = createSprite(250, randomNumber(0, 200));\r\nblueFish.setAnimation(\"blue_fish\");\r\nvar greenFish = createSprite(300, randomNumber(200, 300));\r\ngreenFish.setAnimation(\"green_fish\");\r\n\r\nfunction draw() {\r\n // Draw Background\r\n background(\"navy\");\r\n \r\n // Update Values\r\n orangeFish.x = orangeFish.x - 2;\r\n \r\n // Draw Animations\r\n drawSprites();\r\n}"
},
"published": true,
"notes": "",
"audit_log": "[{\"changed_at\":\"2017-06-26 17:57:26 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2017-06-26 18:00:56 +0000\",\"changed\":[\"code_functions\",\"contained_level_names\",\"encrypted_examples\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2017-08-21 16:00:57 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":177,\"changed_by_email\":\"josh.schulte@code.org\"},{\"changed_at\":\"2017-12-12 22:35:20 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":106,\"changed_by_email\":\"gtwrobel@gmail.com\"},{\"changed_at\":\"2018-02-22 23:46:15 +0000\",\"changed\":[\"start_animations\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"audit_log": "[{\"changed_at\":\"2017-06-26 17:57:26 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2017-06-26 18:00:56 +0000\",\"changed\":[\"code_functions\",\"contained_level_names\",\"encrypted_examples\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2017-08-21 16:00:57 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":177,\"changed_by_email\":\"josh.schulte@code.org\"},{\"changed_at\":\"2017-12-12 22:35:20 +0000\",\"changed\":[\"markdown_instructions\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":106,\"changed_by_email\":\"gtwrobel@gmail.com\"},{\"changed_at\":\"2018-02-22 23:46:15 +0000\",\"changed\":[\"start_animations\",\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"},{\"changed_at\":\"2018-02-27 19:18:11 +0000\",\"changed\":[\"code_functions\",\"encrypted_examples\",\"contained_level_names\"],\"changed_by_id\":324,\"changed_by_email\":\"elizabeth@code.org\"}]",
"level_concept_difficulty": {
}
}]]></config>
Expand Down

0 comments on commit 0a203be

Please sign in to comment.