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:
parent
8748be28b7
commit
72a9de058d
@ -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) {
|
||||||
|
@ -19,26 +19,28 @@ 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
helper.unload();
|
helper.unload();
|
||||||
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a switch node where one argument is consumed by the rule (such as greater than).
|
* Test a switch node where one argument is consumed by the rule (such as greater than).
|
||||||
* @param rule - the switch rule (see 10-switc.js) string we're using
|
* @param rule - the switch rule (see 10-switc.js) string we're using
|
||||||
|
@ -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:[]}];
|
||||||
@ -336,7 +363,7 @@ describe('ChangeNode', function() {
|
|||||||
msg.should.have.property('level', helper.log().ERROR);
|
msg.should.have.property('level', helper.log().ERROR);
|
||||||
msg.should.have.property('id', 'changeNode1');
|
msg.should.have.property('id', 'changeNode1');
|
||||||
done();
|
done();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -417,7 +444,7 @@ describe('ChangeNode', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('- multiple rules', function() {
|
describe('- multiple rules', function() {
|
||||||
|
|
||||||
it('handles multiple rules', function(done) {
|
it('handles multiple rules', function(done) {
|
||||||
var flow = [{"id":"changeNode1","type":"change","wires":[["helperNode1"]],
|
var flow = [{"id":"changeNode1","type":"change","wires":[["helperNode1"]],
|
||||||
rules:[
|
rules:[
|
||||||
@ -470,7 +497,6 @@ describe('ChangeNode', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -19,8 +19,8 @@ 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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -45,7 +46,7 @@ describe('RangeNode', function() {
|
|||||||
* @param minin - map from minimum value
|
* @param minin - map from minimum value
|
||||||
* @param maxin - map from maximum value
|
* @param maxin - map from maximum value
|
||||||
* @param minout - map to minimum value
|
* @param minout - map to minimum value
|
||||||
* @param maxout - map to maximum value
|
* @param maxout - map to maximum value
|
||||||
* @param round - whether to round the result to the nearest integer
|
* @param round - whether to round the result to the nearest integer
|
||||||
* @param aPayload - what payload to send to the range node
|
* @param aPayload - what payload to send to the range node
|
||||||
* @param expectedResult - what result we're expecting
|
* @param expectedResult - what result we're expecting
|
||||||
|
Loading…
Reference in New Issue
Block a user