mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #1825 from node-red-hitachi/add-types-to-trigger-node
Add support of bin, data, and env type to trigger node
This commit is contained in:
commit
ba1a67969b
@ -162,7 +162,7 @@
|
||||
$("#node-input-op1").typedInput({
|
||||
default: 'str',
|
||||
typeField: $("#node-input-op1type"),
|
||||
types:['flow','global','str','num','bool','json',
|
||||
types:['flow','global','str','num','bool','json','bin','date','env',
|
||||
optionPayload,
|
||||
optionNothing
|
||||
]
|
||||
@ -170,7 +170,7 @@
|
||||
$("#node-input-op2").typedInput({
|
||||
default: 'str',
|
||||
typeField: $("#node-input-op2type"),
|
||||
types:['flow','global','str','num','bool','json',
|
||||
types:['flow','global','str','num','bool','json','bin','date','env',
|
||||
optionOriginalPayload,
|
||||
optionLatestPayload,
|
||||
optionNothing
|
||||
|
@ -35,6 +35,9 @@ describe('trigger node', function() {
|
||||
},
|
||||
memory1: {
|
||||
module: "memory"
|
||||
},
|
||||
memory2: {
|
||||
module: "memory"
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -96,6 +99,74 @@ describe('trigger node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
function basicTest(type, val, rval) {
|
||||
it('should output 1st value when triggered ('+type+')', function(done) {
|
||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:val, op1type:type, op2:"", op2type:"null", duration:"20", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
process.env[val] = rval;
|
||||
helper.load(triggerNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
if (rval) {
|
||||
msg.should.have.property("payload");
|
||||
should.deepEqual(msg.payload, rval);
|
||||
}
|
||||
else {
|
||||
msg.should.have.property("payload", val);
|
||||
}
|
||||
delete process.env[val];
|
||||
done();
|
||||
}
|
||||
catch(err) { done(err); }
|
||||
});
|
||||
n1.emit("input", {payload:null});
|
||||
});
|
||||
});
|
||||
|
||||
it('should output 2st value when triggered ('+type+')', function(done) {
|
||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"str", op2:val, op2type:type, duration:"20", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
process.env[val] = rval;
|
||||
helper.load(triggerNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
if (c === 0) {
|
||||
msg.should.have.property("payload", "foo");
|
||||
c++;
|
||||
}
|
||||
else {
|
||||
if (rval) {
|
||||
msg.should.have.property("payload");
|
||||
should.deepEqual(msg.payload, rval);
|
||||
}
|
||||
else {
|
||||
msg.should.have.property("payload", val);
|
||||
}
|
||||
delete process.env[val];
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(err) { done(err); }
|
||||
});
|
||||
n1.emit("input", {payload:null});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
basicTest("num", 10);
|
||||
basicTest("str", "10");
|
||||
basicTest("bool", true);
|
||||
var val_json = '{ "x":"vx", "y":"vy", "z":"vz" }';
|
||||
basicTest("json", val_json, JSON.parse(val_json));
|
||||
var val_buf = "[1,2,3,4,5]";
|
||||
basicTest("bin", val_buf, Buffer.from(JSON.parse(val_buf)));
|
||||
basicTest("env", "NR-TEST", "env-val");
|
||||
|
||||
it('should output 1 then 0 when triggered (default)', function(done) {
|
||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"20", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
@ -336,8 +407,8 @@ describe('trigger node', function() {
|
||||
});
|
||||
|
||||
it('should be able to return things from persistable flow and global context variables', function (done) {
|
||||
var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory0)::foo", "op1type": "flow",
|
||||
"op2": "#:(memory0)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" },
|
||||
var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory1)::foo", "op1type": "flow",
|
||||
"op2": "#:(memory1)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" },
|
||||
{"id": "n2", "type": "helper"}];
|
||||
helper.load(triggerNode, flow, function () {
|
||||
initContext(function () {
|
||||
@ -360,8 +431,8 @@ describe('trigger node', function() {
|
||||
var context = n1.context();
|
||||
var flow = context.flow;
|
||||
var global = context.global;
|
||||
flow.set("foo", "foo", "memory0", function (err) {
|
||||
global.set("bar", "bar", "memory0", function (err) {
|
||||
flow.set("foo", "foo", "memory1", function (err) {
|
||||
global.set("bar", "bar", "memory1", function (err) {
|
||||
n1.emit("input", { payload: null });
|
||||
});
|
||||
});
|
||||
@ -372,8 +443,8 @@ describe('trigger node', function() {
|
||||
it('should be able to return things from multiple persistable global context variables', function (done) {
|
||||
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
|
||||
"duration": "20", "wires": [["n2"]],
|
||||
"op1": "#:(memory0)::val", "op1type": "global",
|
||||
"op2": "#:(memory1)::val", "op2type": "global"
|
||||
"op1": "#:(memory1)::val", "op1type": "global",
|
||||
"op2": "#:(memory2)::val", "op2type": "global"
|
||||
},
|
||||
{"id": "n2", "type": "helper"}];
|
||||
helper.load(triggerNode, flow, function () {
|
||||
@ -399,8 +470,8 @@ describe('trigger node', function() {
|
||||
}
|
||||
});
|
||||
var global = n1.context().global;
|
||||
global.set("val", "foo", "memory0", function (err) {
|
||||
global.set("val", "bar", "memory1", function (err) {
|
||||
global.set("val", "foo", "memory1", function (err) {
|
||||
global.set("val", "bar", "memory2", function (err) {
|
||||
n1.emit("input", { payload: null });
|
||||
});
|
||||
});
|
||||
@ -411,8 +482,8 @@ describe('trigger node', function() {
|
||||
it('should be able to return things from multiple persistable flow context variables', function (done) {
|
||||
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
|
||||
"duration": "20", "wires": [["n2"]],
|
||||
"op1": "#:(memory0)::val", "op1type": "flow",
|
||||
"op2": "#:(memory1)::val", "op2type": "flow"
|
||||
"op1": "#:(memory1)::val", "op1type": "flow",
|
||||
"op2": "#:(memory2)::val", "op2type": "flow"
|
||||
},
|
||||
{"id": "n2", "type": "helper"}];
|
||||
helper.load(triggerNode, flow, function () {
|
||||
@ -438,8 +509,8 @@ describe('trigger node', function() {
|
||||
}
|
||||
});
|
||||
var flow = n1.context().flow;
|
||||
flow.set("val", "foo", "memory0", function (err) {
|
||||
flow.set("val", "bar", "memory1", function (err) {
|
||||
flow.set("val", "foo", "memory1", function (err) {
|
||||
flow.set("val", "bar", "memory2", function (err) {
|
||||
n1.emit("input", { payload: null });
|
||||
});
|
||||
});
|
||||
@ -450,8 +521,8 @@ describe('trigger node', function() {
|
||||
it('should be able to return things from multiple persistable flow & global context variables', function (done) {
|
||||
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
|
||||
"duration": "20", "wires": [["n2"]],
|
||||
"op1": "#:(memory0)::val", "op1type": "flow",
|
||||
"op2": "#:(memory1)::val", "op2type": "global"
|
||||
"op1": "#:(memory1)::val", "op1type": "flow",
|
||||
"op2": "#:(memory2)::val", "op2type": "global"
|
||||
},
|
||||
{"id": "n2", "type": "helper"}];
|
||||
helper.load(triggerNode, flow, function () {
|
||||
@ -479,8 +550,8 @@ describe('trigger node', function() {
|
||||
var context = n1.context();
|
||||
var flow = context.flow;
|
||||
var global = context.flow;
|
||||
flow.set("val", "foo", "memory0", function (err) {
|
||||
global.set("val", "bar", "memory1", function (err) {
|
||||
flow.set("val", "foo", "memory1", function (err) {
|
||||
global.set("val", "bar", "memory2", function (err) {
|
||||
n1.emit("input", { payload: null });
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user