Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another rgb pulse revision, fix unit tests, update package version #26

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/led/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class RGB {
}
},
update: {
writable: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for testing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - within this test in test/rgb.js

value(colors) {
const state = priv.get(this);

Expand Down Expand Up @@ -282,6 +283,9 @@ class RGB {
if (!this.isOn) {
/* istanbul ignore next */
this.update(state.prev);
} else if (state.isRunning) {
this.stop();
this.update(state.prev);
}

return this;
Expand Down Expand Up @@ -486,7 +490,9 @@ class RGB {
*/

[Animation.render](frames) {
return this.update(frames[0]);
const state = priv.get(this);
state.value = frames[0];
return this.update(state.value);
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@code-dot-org/johnny-five",
"description": "Code.org fork of rwaldron/johnny-five: The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, pcDuino3, Raspberry Pi, Particle/Spark Core & Photon, Tessel 2, TI Launchpad and more!",
"version": "2.1.0-cdo.1",
"version": "2.1.0-cdo.2",
"homepage": "https://johnny-five.io",
"author": "Rick Waldron <[email protected]>",
"keywords": [
Expand Down
16 changes: 6 additions & 10 deletions test/rgb.collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,18 @@ exports["RGB.Collection"] = {


"Animation.render": function(test) {
test.expect(1);

const rgbs = new RGB.Collection([
[1, 2, 3],
[4, 5, 6],
]);

this.color = this.sandbox.stub(RGB.prototype, "color");
test.expect(3);

this.render = this.sandbox.stub(RGB.prototype, "@@render");
const rgbs = new RGB.Collection([ this.a, this.b ]);
rgbs[Animation.render]([
{ red: 0xff, green: 0x00, blue: 0x00 },
{ red: 0x00, green: 0xff, blue: 0x00 },
]);

test.equal(this.color.callCount, 2);
test.equal(this.render.callCount, 2);
test.deepEqual(this.render.firstCall.args[0], [ { red: 255, green: 0, blue: 0 } ]);
test.deepEqual(this.render.secondCall.args[0], [ { red: 0, green: 255, blue: 0 } ]);
test.done();
},
};

81 changes: 76 additions & 5 deletions test/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const rgbProtoProperties = [{
name: "strobe"
}, {
name: "blink"
}, {
name: "pulse"
}, {
name: "stop"
}];
Expand Down Expand Up @@ -44,7 +46,7 @@ exports["RGB"] = {
});

this.write = this.sandbox.spy(this.rgb, "write");

this.enqueue = this.sandbox.stub(Animation.prototype, "enqueue");
done();
},

Expand Down Expand Up @@ -469,6 +471,72 @@ exports["RGB"] = {
test.done();
},

pulse(test) {
test.expect(1);
this.rgb.color("#0000ff");
this.rgb.pulse();
test.equal(this.enqueue.callCount, 1);
test.done();
},

pulseDuration(test) {
test.expect(2);

this.rgb.pulse(1010);

test.equal(this.enqueue.callCount, 1);

const duration = this.enqueue.lastCall.args[0].duration;

test.equal(duration, 1010);
test.done();
},

pulseCallback(test) {
test.expect(2);

const spy = this.sandbox.spy();

this.rgb.pulse(spy);

test.equal(this.enqueue.callCount, 1);

const onloop = this.enqueue.lastCall.args[0].onloop;

onloop();

test.equal(spy.callCount, 1);
test.done();
},

pulseDurationCallback(test) {
test.expect(3);

const spy = this.sandbox.spy();

this.rgb.pulse(1010, spy);

test.equal(this.enqueue.callCount, 1);

const duration = this.enqueue.lastCall.args[0].duration;
const onloop = this.enqueue.lastCall.args[0].onloop;

onloop();

test.equal(duration, 1010);
test.equal(spy.callCount, 1);
test.done();
},

pulseObject(test) {
test.expect(1);

this.rgb.color("#0000ff");
this.rgb.pulse({});
test.equal(this.enqueue.callCount, 1);
test.done();
},

toggle(test) {
test.expect(7);

Expand Down Expand Up @@ -749,9 +817,9 @@ exports["RGB"] = {

"Animation.render"(test) {
test.expect(1);
this.color = this.sandbox.stub(this.rgb, "color");
this.update = this.sandbox.stub(this.rgb, "update");
this.rgb[Animation.render]([0]);
test.equal(this.color.callCount, 1);
test.equal(this.update.callCount, 1);
test.done();
},

Expand Down Expand Up @@ -876,11 +944,14 @@ exports["RGB - Cycling Operations"] = {
},

rgbCallsStopBeforeNextCyclingOperation(test) {
test.expect(1);
test.expect(2);

this.rgb.blink();
this.rgb.pulse();

test.equal(this.stop.callCount, 1);
test.equal(this.stop.callCount, 2);
// pulse is an animation
test.equal(this.enqueue.callCount, 1);

// Ensure that the interval is cleared.
this.rgb.stop();
Expand Down