1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

pi nodes - increase test coverage slightly

This commit is contained in:
Dave Conway-Jones 2018-08-30 20:54:03 +01:00
parent 8e9815fb91
commit 69448c7329
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4

View File

@ -15,7 +15,8 @@
**/ **/
var should = require("should"); var should = require("should");
var rpi = require("../../../../nodes/core/hardware/36-rpi-gpio.js"); var rpiNode = require("../../../../nodes/core/hardware/36-rpi-gpio.js");
var statusNode = require("../../../../nodes/core/core/25-status.js");
var helper = require("node-red-node-test-helper"); var helper = require("node-red-node-test-helper");
var fs = require("fs"); var fs = require("fs");
@ -50,7 +51,7 @@ describe('RPI GPIO Node', function() {
it('should load Input node', function(done) { it('should load Input node', function(done) {
var flow = [{id:"n1", type:"rpi-gpio in", name:"rpi-gpio in" }]; var flow = [{id:"n1", type:"rpi-gpio in", name:"rpi-gpio in" }];
helper.load(rpi, flow, function() { helper.load(rpiNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.should.have.property('name', 'rpi-gpio in'); n1.should.have.property('name', 'rpi-gpio in');
try { try {
@ -69,7 +70,7 @@ describe('RPI GPIO Node', function() {
it('should load Output node', function(done) { it('should load Output node', function(done) {
var flow = [{id:"n1", type:"rpi-gpio out", name:"rpi-gpio out" }]; var flow = [{id:"n1", type:"rpi-gpio out", name:"rpi-gpio out" }];
helper.load(rpi, flow, function() { helper.load(rpiNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.should.have.property('name', 'rpi-gpio out'); n1.should.have.property('name', 'rpi-gpio out');
try { try {
@ -86,4 +87,62 @@ describe('RPI GPIO Node', function() {
}); });
}); });
it('should read a dummy value high (not on Pi)', function(done) {
var flow = [{id:"n1", type:"rpi-gpio in", pin:"7", intype:"up", debounce:"25", read:true, wires:[["n2"]] },
{id:"n2", type:"helper"}];
helper.load(rpiNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('topic', 'pi/7');
msg.should.have.property('payload', 1);
done();
} catch(err) {
done(err);
}
});
});
});
it('should read a dummy value low (not on Pi)', function(done) {
var flow = [{id:"n1", type:"rpi-gpio in", pin:"11", intype:"down", debounce:"25", read:true, wires:[["n2"]] },
{id:"n2", type:"helper"}];
helper.load(rpiNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('topic', 'pi/11');
msg.should.have.property('payload', 0);
done();
} catch(err) {
done(err);
}
});
});
});
it('should be able preset out to a dummy value (not on Pi)', function(done) {
var flow = [{id:"n1", type:"rpi-gpio out", pin:"7", out:"out", level:"0", set:true, freq:"", wires:[], z:"1"},
{id:"n2", type:"status", scope:null, wires:[["n3"]], z:"1"},
{id:"n3", type:"helper", z:"1"}];
helper.load([rpiNode,statusNode], flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
n3.on("input", function(msg) {
try {
msg.should.have.property('status');
msg.status.should.have.property('text', "rpi-gpio.status.na");
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"1"});
});
});
}); });