mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Fix RBE node to pass tests (and add % diff) test
This commit is contained in:
parent
c98d8a4baa
commit
50c9a5f1e1
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-rbe",
|
"name" : "node-red-node-rbe",
|
||||||
"version" : "0.0.6",
|
"version" : "0.0.7",
|
||||||
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
|
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ module.exports = function(RED) {
|
|||||||
function RbeNode(n) {
|
function RbeNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.func = n.func || "rbe";
|
this.func = n.func || "rbe";
|
||||||
this.gap = n.gap || 0;
|
this.gap = n.gap || "0";
|
||||||
this.pc = false;
|
this.pc = false;
|
||||||
if (this.gap.substr(-1) === "%") {
|
if (this.gap.substr(-1) === "%") {
|
||||||
this.pc = true;
|
this.pc = true;
|
||||||
|
@ -37,13 +37,13 @@ describe('rbe node', function() {
|
|||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
n1.should.have.property("name", "rbe1");
|
n1.should.have.property("name", "rbe1");
|
||||||
n1.should.have.property("func", "rbe");
|
n1.should.have.property("func", "rbe");
|
||||||
n1.should.have.property("gap", 0);
|
n1.should.have.property("gap", "0");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should only send output if payload changes', function(done) {
|
it('should only send output if payload changes', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:0, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:"0", wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(testNode, flow, function() {
|
helper.load(testNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -70,7 +70,7 @@ describe('rbe node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should only send output if more than x away from original value', function(done) {
|
it('should only send output if more than x away from original value', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10", wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(testNode, flow, function() {
|
helper.load(testNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -100,8 +100,37 @@ describe('rbe node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should only send output if more than x% away from original value', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10%", 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("payload", 100);
|
||||||
|
}
|
||||||
|
else if (c === 1) {
|
||||||
|
msg.should.have.a.property("payload", 120);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg.should.have.a.property("payload", 132);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
c += 1;
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:100});
|
||||||
|
n1.emit("input", {payload:95});
|
||||||
|
n1.emit("input", {payload:105});
|
||||||
|
n1.emit("input", {payload:120});
|
||||||
|
n1.emit("input", {payload:130});
|
||||||
|
n1.emit("input", {payload:132});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should warn if no number found in gap mode', function(done) {
|
it('should warn if no number found in gap mode', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10", wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(testNode, flow, function() {
|
helper.load(testNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user