mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
add msg.property option to rbe, randon, smooth and base64 nodes
This commit is contained in:
@@ -66,4 +66,23 @@ describe('random node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should output an integer between -3 and 3 on chosen property - foo', function(done) {
|
||||
var flow = [{"id":"n1", "type":"random", property:"foo", low:-3, high:3, inte:true, wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
if (c === 0) {
|
||||
msg.should.have.a.property("foo");
|
||||
msg.foo.should.be.approximately(0,3);
|
||||
msg.foo.toString().indexOf(".").should.equal(-1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
n1.emit("input", {payload:"a"});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -62,6 +62,41 @@ describe('rbe node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should only send output if another chosen property changes - foo (rbe)', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:"0", property:"foo", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
if (c === 0) {
|
||||
msg.should.have.a.property("foo", "a");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 1) {
|
||||
msg.should.have.a.property("foo", "b");
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("foo");
|
||||
msg.foo.should.have.a.property("b",1);
|
||||
msg.foo.should.have.a.property("c",2);
|
||||
done();
|
||||
}
|
||||
});
|
||||
n1.emit("input", {foo:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {foo:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {foo:"a"});
|
||||
n1.emit("input", {foo:"b"});
|
||||
n1.emit("input", {foo:{b:1,c:2}});
|
||||
n1.emit("input", {foo:{c:2,b:1}});
|
||||
n1.emit("input", {payload:{c:2,b:1}});
|
||||
});
|
||||
});
|
||||
|
||||
it('should only send output if payload changes - ignoring first value (rbei)', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"rbei", gap:"0", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
|
@@ -48,6 +48,29 @@ describe('smooth node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should average over a number of inputs - another property - foo', function(done) {
|
||||
var flow = [{"id":"n1", "type":"smooth", action:"mean", count:"5", round:"true", property:"foo", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
c += 1;
|
||||
if (c === 4) { msg.should.have.a.property("foo", 1.8); }
|
||||
if (c === 6) { msg.should.have.a.property("foo", 3); done(); }
|
||||
});
|
||||
n1.emit("input", {foo:1});
|
||||
n1.emit("input", {foo:1});
|
||||
n1.emit("input", {foo:2});
|
||||
n1.emit("input", {payload:2});
|
||||
n1.emit("input", {payload:2});
|
||||
n1.emit("input", {foo:3});
|
||||
n1.emit("input", {foo:4});
|
||||
n1.emit("input", {foo:4.786});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to be reset', function(done) {
|
||||
var flow = [{"id":"n1", "type":"smooth", action:"mean", count:"5", round:"true", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
@@ -69,6 +92,29 @@ describe('smooth node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to be reset - while using another property - foo', function(done) {
|
||||
var flow = [{"id":"n1", "type":"smooth", action:"mean", count:"5", round:"true", property:"foo", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
c += 1;
|
||||
if (c === 3) { msg.should.have.a.property("foo", 2); }
|
||||
if (c === 6) { msg.should.have.a.property("foo", 5); done(); }
|
||||
});
|
||||
n1.emit("input", {foo:1});
|
||||
n1.emit("input", {foo:2});
|
||||
n1.emit("input", {payload:2});
|
||||
n1.emit("input", {foo:3});
|
||||
n1.emit("input", {reset:true, foo:4});
|
||||
n1.emit("input", {foo:5});
|
||||
n1.emit("input", {payload:2});
|
||||
n1.emit("input", {foo:6});
|
||||
});
|
||||
});
|
||||
|
||||
it('should output max over a number of inputs', function(done) {
|
||||
var flow = [{"id":"n1", "type":"smooth", action:"max", count:"5", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
|
Reference in New Issue
Block a user