1
0
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:
dceejay 2015-07-12 20:14:24 +01:00
parent c98d8a4baa
commit 50c9a5f1e1
3 changed files with 35 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"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.",
"dependencies" : {
},

View File

@ -20,7 +20,7 @@ module.exports = function(RED) {
function RbeNode(n) {
RED.nodes.createNode(this,n);
this.func = n.func || "rbe";
this.gap = n.gap || 0;
this.gap = n.gap || "0";
this.pc = false;
if (this.gap.substr(-1) === "%") {
this.pc = true;

View File

@ -37,13 +37,13 @@ describe('rbe node', function() {
var n1 = helper.getNode("n1");
n1.should.have.property("name", "rbe1");
n1.should.have.property("func", "rbe");
n1.should.have.property("gap", 0);
n1.should.have.property("gap", "0");
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"} ];
helper.load(testNode, flow, function() {
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) {
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"} ];
helper.load(testNode, flow, function() {
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) {
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"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");