mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Fix RBE node to pass tests (and add % diff) test
This commit is contained in:
		@@ -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"  : {
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user