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

tests for defaults in switch, change and range nodes.

This commit is contained in:
dceejay 2015-03-24 17:35:54 +00:00
parent 8748be28b7
commit 72a9de058d
4 changed files with 49 additions and 20 deletions

View File

@ -35,10 +35,10 @@ module.exports = function(RED) {
function SwitchNode(n) { function SwitchNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.rules = n.rules; this.rules = n.rules || [];
this.property = n.property; this.property = n.property;
this.checkall = n.checkall || "true"; this.checkall = n.checkall || "true";
var propertyParts = n.property.split("."); var propertyParts = (n.property || "payload").split(".");
var node = this; var node = this;
for (var i=0; i<this.rules.length; i+=1) { for (var i=0; i<this.rules.length; i+=1) {

View File

@ -19,7 +19,7 @@ var should = require("should");
var switchNode = require("../../../../nodes/core/logic/10-switch.js"); var switchNode = require("../../../../nodes/core/logic/10-switch.js");
var helper = require("../../helper.js"); var helper = require("../../helper.js");
describe('SwitchNode', function() { describe('switch Node', function() {
beforeEach(function(done) { beforeEach(function(done) {
helper.startServer(done); helper.startServer(done);
@ -30,11 +30,13 @@ describe('SwitchNode', function() {
helper.stopServer(done); helper.stopServer(done);
}); });
it('should be loaded', function(done) { it('should be loaded with some defaults', function(done) {
var flow = [{"id":"switchNode1","type":"switch","name":"switchNode","property":"payload","rules":[{"t":"eq","v":""}],"checkall":"true","outputs":1,"wires":[[]]}]; var flow = [{"id":"switchNode1","type":"switch","name":"switchNode"}];
helper.load(switchNode, flow, function() { helper.load(switchNode, flow, function() {
var switchNode1 = helper.getNode("switchNode1"); var switchNode1 = helper.getNode("switchNode1");
switchNode1.should.have.property('name', 'switchNode'); switchNode1.should.have.property('name', 'switchNode');
switchNode1.should.have.property('checkall', "true");
switchNode1.should.have.property('rules', []);
done(); done();
}); });
}); });

View File

@ -22,7 +22,7 @@ var helper = require("../../helper.js");
var Log = require("../../../../red/log.js"); var Log = require("../../../../red/log.js");
describe('ChangeNode', function() { describe('change Node', function() {
beforeEach(function(done) { beforeEach(function(done) {
helper.startServer(done); helper.startServer(done);
@ -33,7 +33,34 @@ describe('ChangeNode', function() {
helper.stopServer(done); helper.stopServer(done);
}); });
it('should load node with defaults', function(done) {
var flow = [{ id: "c1", type: "change", name:"change1" }];
helper.load(changeNode, flow, function() {
helper.getNode("c1").should.have.property("name", "change1");
helper.getNode("c1").should.have.property("rules", [{t:undefined,p:''}]);
done();
});
});
it('should load defaults if set to replace', function(done) {
var flow = [{ id: "c1", type: "change", name:"change1", action:"replace" }];
helper.load(changeNode, flow, function() {
helper.getNode("c1").should.have.property("name", "change1");
helper.getNode("c1").should.have.property("rules", [ { p: '', t: 'set', to: '' } ]);
done();
});
});
it('should load defaults if set to change', function(done) {
var flow = [{ id: "c1", type: "change", name:"change1", action:"change" }];
helper.load(changeNode, flow, function() {
//console.log(helper.getNode("c1"));
helper.getNode("c1").should.have.property("name", "change1");
helper.getNode("c1").should.have.property("rules", [ { from: /(?:)/g, p: '', re: undefined, t: 'change', to: '' } ]);
done();
});
});
describe('#replace' , function() { describe('#replace' , function() {
it('sets the value of the message property', function(done) { it('sets the value of the message property', function(done) {
var flow = [{"id":"changeNode1","type":"change","action":"replace","property":"payload","from":"","to":"changed","reg":false,"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change","action":"replace","property":"payload","from":"","to":"changed","reg":false,"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
@ -473,4 +500,3 @@ describe('ChangeNode', function() {
}); });
}); });

View File

@ -19,7 +19,7 @@ var should = require("should");
var rangeNode = require("../../../../nodes/core/logic/16-range.js"); var rangeNode = require("../../../../nodes/core/logic/16-range.js");
var helper = require("../../helper.js"); var helper = require("../../helper.js");
describe('RangeNode', function() { describe('range Node', function() {
beforeEach(function(done) { beforeEach(function(done) {
helper.startServer(done); helper.startServer(done);
@ -30,11 +30,12 @@ describe('RangeNode', function() {
helper.stopServer(done); helper.stopServer(done);
}); });
it('should be loaded', function(done) { it('should load some defaults', function(done) {
var flow = [{"id":"rangeNode1","type":"range","minin":"0","maxin":"99","minout":"100","maxout":"199","action":"range","round":true,"name":"rangeNode","wires":[[]]}]; var flow = [{"id":"rangeNode1","type":"range","name":"rangeNode"}];
helper.load(rangeNode, flow, function() { helper.load(rangeNode, flow, function() {
var rangeNode1 = helper.getNode("rangeNode1"); var rangeNode1 = helper.getNode("rangeNode1");
rangeNode1.should.have.property('name', 'rangeNode'); rangeNode1.should.have.property('name', 'rangeNode');
rangeNode1.should.have.property('round', false);
done(); done();
}); });
}); });