mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Update trigger node ui to use typedInputs
This commit is contained in:
parent
b74a35b9d1
commit
691b083364
@ -16,54 +16,49 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="trigger">
|
<script type="text/x-red" data-template-name="trigger">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<span data-i18n="trigger.send"></span>
|
<label data-i18n="trigger.send" for="node-input-op1"></label>
|
||||||
<select id="node-input-op1type" style="width:200px !important">
|
<input type="hidden" id="node-input-op1type">
|
||||||
<option value="val" data-i18n="trigger.output.string"></option>
|
<input style="width: 70%" type="text" id="node-input-op1">
|
||||||
<option value="num" data-i18n="trigger.output.number"></option>
|
|
||||||
<option value="pay" data-i18n="trigger.output.existing"></option>
|
|
||||||
<option value="nul" data-i18n="trigger.output.nothing"></option>
|
|
||||||
</select>
|
|
||||||
<input style="width: 180px !important" type="text" id="node-input-op1">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<span data-i18n="trigger.then"></span>
|
<label data-i18n="trigger.then"></label>
|
||||||
<select id="node-then-type" style="width:150px;">
|
<select id="node-then-type" style="width:70%;">
|
||||||
<option value="block" data-i18n="trigger.wait-reset"></option>
|
<option value="block" data-i18n="trigger.wait-reset"></option>
|
||||||
<option value="wait" data-i18n="trigger.wait-for"></option>
|
<option value="wait" data-i18n="trigger.wait-for"></option>
|
||||||
</select>
|
</select>
|
||||||
<span class="node-type-wait">
|
|
||||||
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
|
|
||||||
<select id="node-input-units" style="width:140px !important">
|
|
||||||
<option value="ms" data-i18n="trigger.duration.ms"></option>
|
|
||||||
<option value="s" data-i18n="trigger.duration.s"></option>
|
|
||||||
<option value="min" data-i18n="trigger.duration.m"></option>
|
|
||||||
<option value="hr" data-i18n="trigger.duration.h"></option>
|
|
||||||
</select>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row node-type-wait">
|
<div class="form-row node-type-wait">
|
||||||
|
<label></label>
|
||||||
|
<input type="text" id="node-input-duration" style="text-align:end; width:70px !important">
|
||||||
|
<select id="node-input-units" style="width:140px !important">
|
||||||
|
<option value="ms" data-i18n="trigger.duration.ms"></option>
|
||||||
|
<option value="s" data-i18n="trigger.duration.s"></option>
|
||||||
|
<option value="min" data-i18n="trigger.duration.m"></option>
|
||||||
|
<option value="hr" data-i18n="trigger.duration.h"></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row node-type-wait">
|
||||||
|
<label></label>
|
||||||
<input type="checkbox" id="node-input-extend" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
|
<input type="checkbox" id="node-input-extend" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-extend" data-i18n="trigger.extend"></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row node-type-wait">
|
<div class="form-row node-type-wait">
|
||||||
<span data-i18n="trigger.then-send"></span>
|
<label data-i18n="trigger.then-send"></label>
|
||||||
<select id="node-input-op2type" style="width:200px !important">
|
<input type="hidden" id="node-input-op2type">
|
||||||
<option value="val" data-i18n="trigger.output.string"></option>
|
<input style="width: 70%" type="text" id="node-input-op2">
|
||||||
<option value="num" data-i18n="trigger.output.number"></option>
|
|
||||||
<option value="pay" data-i18n="trigger.output.original"></option>
|
|
||||||
<option value="payl" data-i18n="trigger.output.latest"></option>
|
|
||||||
<option value="nul" data-i18n="trigger.output.nothing"></option>
|
|
||||||
</select>
|
|
||||||
<input style="width: 145px !important" type="text" id="node-input-op2">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<span data-i18n="trigger.label.reset"></span><input type="text" id="node-input-reset" style="width:240px" data-i18n="[placeholder]trigger.label.resetprompt">
|
<label data-i18n="trigger.label.reset" style="width:auto"></label>
|
||||||
|
<div style="display:inline-block; width:70%;vertical-align:top">
|
||||||
|
<ul>
|
||||||
|
<li data-i18n="trigger.label.resetMessage"></li>
|
||||||
|
<li><span data-i18n="trigger.label.resetPayload"></span> <input type="text" id="node-input-reset" style="width:150px" data-i18n="[placeholder]trigger.label.resetprompt"></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips" data-i18n="[html]trigger.tip"></div>
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="trigger">
|
<script type="text/x-red" data-help-name="trigger">
|
||||||
@ -118,34 +113,48 @@
|
|||||||
$("#node-then-type").change(function() {
|
$("#node-then-type").change(function() {
|
||||||
if ($(this).val() == "block") {
|
if ($(this).val() == "block") {
|
||||||
$(".node-type-wait").hide();
|
$(".node-type-wait").hide();
|
||||||
$(".form-tips").show();
|
|
||||||
} else {
|
} else {
|
||||||
$(".node-type-wait").show();
|
$(".node-type-wait").show();
|
||||||
$(".form-tips").hide();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#node-input-op1type").change(function() {
|
|
||||||
if (($(this).val() == "val")||($(this).val() == "num")) {
|
if (this.op1type === 'val') {
|
||||||
$("#node-input-op1").show();
|
$("#node-input-op1type").val('str');
|
||||||
} else {
|
}
|
||||||
$("#node-input-op1").hide();
|
if (this.op2type === 'val') {
|
||||||
}
|
$("#node-input-op2type").val('str');
|
||||||
|
}
|
||||||
|
|
||||||
|
var optionNothing = {value:"nul",label:this._("trigger.output.nothing"),hasValue:false};
|
||||||
|
var optionPayload = {value:"pay",label:this._("trigger.output.existing"),hasValue:false}
|
||||||
|
|
||||||
|
var optionOriginalPayload = {value:"pay",label:this._("trigger.output.original"),hasValue:false}
|
||||||
|
var optionLatestPayload = {value:"payl",label:this._("trigger.output.latest"),hasValue:false}
|
||||||
|
|
||||||
|
$("#node-input-op1").typedInput({
|
||||||
|
default: 'str',
|
||||||
|
typeField: $("#node-input-op1type"),
|
||||||
|
types:['flow','global','str','num','bool','json',
|
||||||
|
optionPayload,
|
||||||
|
optionNothing
|
||||||
|
]
|
||||||
});
|
});
|
||||||
$("#node-input-op2type").change(function() {
|
$("#node-input-op2").typedInput({
|
||||||
if (($(this).val() == "val")||($(this).val() == "num")) {
|
default: 'str',
|
||||||
$("#node-input-op2").show();
|
typeField: $("#node-input-op2type"),
|
||||||
} else {
|
types:['flow','global','str','num','bool','json',
|
||||||
$("#node-input-op2").hide();
|
optionOriginalPayload,
|
||||||
}
|
optionLatestPayload,
|
||||||
|
optionNothing
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.duration == "0") {
|
if (this.duration == "0") {
|
||||||
$("#node-then-type").val("block");
|
$("#node-then-type").val("block");
|
||||||
} else {
|
} else {
|
||||||
$("#node-then-type").val("wait");
|
$("#node-then-type").val("wait");
|
||||||
}
|
}
|
||||||
$("#node-then-type").change();
|
$("#node-then-type").change();
|
||||||
$("#node-input-op1type").change();
|
|
||||||
$("#node-input-op2type").change();
|
|
||||||
|
|
||||||
if (this.extend === "true" || this.extend === true) {
|
if (this.extend === "true" || this.extend === true) {
|
||||||
$("#node-input-extend").prop("checked",true);
|
$("#node-input-extend").prop("checked",true);
|
||||||
|
@ -21,8 +21,29 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.op1 = n.op1 || "1";
|
this.op1 = n.op1 || "1";
|
||||||
this.op2 = n.op2 || "0";
|
this.op2 = n.op2 || "0";
|
||||||
this.op1type = n.op1type || "val";
|
this.op1type = n.op1type || "str";
|
||||||
this.op2type = n.op2type || "val";
|
this.op2type = n.op2type || "str";
|
||||||
|
|
||||||
|
if (this.op1type === 'val') {
|
||||||
|
if (this.op1 === 'true' || this.op1 === 'false') {
|
||||||
|
this.op1type = 'bool'
|
||||||
|
} else if (this.op1 === 'null') {
|
||||||
|
this.op1type = 'null';
|
||||||
|
this.op1 = null;
|
||||||
|
} else {
|
||||||
|
this.op1type = 'str';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.op2type === 'val') {
|
||||||
|
if (this.op2 === 'true' || this.op2 === 'false') {
|
||||||
|
this.op2type = 'bool'
|
||||||
|
} else if (this.op2 === 'null') {
|
||||||
|
this.op2type = 'null';
|
||||||
|
this.op2 = null;
|
||||||
|
} else {
|
||||||
|
this.op2type = 'str';
|
||||||
|
}
|
||||||
|
}
|
||||||
this.extend = n.extend || "false";
|
this.extend = n.extend || "false";
|
||||||
this.units = n.units || "ms";
|
this.units = n.units || "ms";
|
||||||
this.reset = n.reset || '';
|
this.reset = n.reset || '';
|
||||||
@ -33,14 +54,10 @@ module.exports = function(RED) {
|
|||||||
if (this.units == "min") { this.duration = this.duration * 1000 * 60; }
|
if (this.units == "min") { this.duration = this.duration * 1000 * 60; }
|
||||||
if (this.units == "hr") { this.duration = this.duration * 1000 *60 * 60; }
|
if (this.units == "hr") { this.duration = this.duration * 1000 *60 * 60; }
|
||||||
}
|
}
|
||||||
this.op1Templated = this.op1.indexOf("{{") != -1;
|
this.op1Templated = (this.op1type === 'str' && this.op1.indexOf("{{") != -1);
|
||||||
this.op2Templated = this.op2.indexOf("{{") != -1;
|
this.op2Templated = (this.op2type === 'str' && this.op2.indexOf("{{") != -1);
|
||||||
if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); }
|
if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); }
|
||||||
if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); }
|
if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); }
|
||||||
if (this.op1 == "true") { this.op1 = true; }
|
|
||||||
if (this.op2 == "true") { this.op2 = true; }
|
|
||||||
if (this.op1 == "false") { this.op1 = false; }
|
|
||||||
if (this.op2 == "false") { this.op2 = false; }
|
|
||||||
if (this.op1 == "null") { this.op1 = null; }
|
if (this.op1 == "null") { this.op1 = null; }
|
||||||
if (this.op2 == "null") { this.op2 = null; }
|
if (this.op2 == "null") { this.op2 = null; }
|
||||||
//try { this.op1 = JSON.parse(this.op1); }
|
//try { this.op1 = JSON.parse(this.op1); }
|
||||||
@ -59,20 +76,31 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((!tout) && (tout !== 0)) {
|
if ((!tout) && (tout !== 0)) {
|
||||||
if (node.op2type === "pay") { m2 = msg.payload; }
|
if (node.op2type === "pay" || node.op2type === "payl") { m2 = msg.payload; }
|
||||||
else if (node.op2type === "payl") { m2 = msg.payload; }
|
|
||||||
else if (node.op2Templated) { m2 = mustache.render(node.op2,msg); }
|
else if (node.op2Templated) { m2 = mustache.render(node.op2,msg); }
|
||||||
else { m2 = node.op2; }
|
else if (node.op2type !== "nul") {
|
||||||
|
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (node.op1type === "pay") { }
|
if (node.op1type === "pay") { }
|
||||||
else if (node.op1Templated) { msg.payload = mustache.render(node.op1,msg); }
|
else if (node.op1Templated) { msg.payload = mustache.render(node.op1,msg); }
|
||||||
else { msg.payload = node.op1; }
|
else if (node.op1type !== "nul") {
|
||||||
|
msg.payload = RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (node.op1type !== "nul") { node.send(msg); }
|
if (node.op1type !== "nul") { node.send(msg); }
|
||||||
|
|
||||||
if (node.duration === 0) { tout = 0; }
|
if (node.duration === 0) { tout = 0; }
|
||||||
else {
|
else {
|
||||||
tout = setTimeout(function() {
|
tout = setTimeout(function() {
|
||||||
var msg2 = RED.util.cloneMessage(msg);
|
if (node.op2type !== "nul") {
|
||||||
msg2.payload = m2;
|
var msg2 = RED.util.cloneMessage(msg);
|
||||||
if (node.op2type !== "nul") { node.send(msg2); }
|
if (node.op2type === "flow" || node.op2type === "global") {
|
||||||
|
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
|
||||||
|
}
|
||||||
|
msg2.payload = m2;
|
||||||
|
node.send(msg2);
|
||||||
|
}
|
||||||
tout = null;
|
tout = null;
|
||||||
node.status({});
|
node.status({});
|
||||||
},node.duration);
|
},node.duration);
|
||||||
@ -83,9 +111,14 @@ module.exports = function(RED) {
|
|||||||
clearTimeout(tout);
|
clearTimeout(tout);
|
||||||
if (node.op2type === "payl") { m2 = msg.payload; }
|
if (node.op2type === "payl") { m2 = msg.payload; }
|
||||||
tout = setTimeout(function() {
|
tout = setTimeout(function() {
|
||||||
var msg2 = RED.util.cloneMessage(msg);
|
if (node.op2type !== "nul") {
|
||||||
msg2.payload = m2;
|
var msg2 = RED.util.cloneMessage(msg);
|
||||||
if (node.op2type !== "nul") { node.send(msg2); }
|
if (node.op2type === "flow" || node.op2type === "global") {
|
||||||
|
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
|
||||||
|
}
|
||||||
|
msg2.payload = m2;
|
||||||
|
node.send(msg2);
|
||||||
|
}
|
||||||
tout = null;
|
tout = null;
|
||||||
node.status({});
|
node.status({});
|
||||||
},node.duration);
|
},node.duration);
|
||||||
|
@ -228,12 +228,13 @@
|
|||||||
"h": "Hours"
|
"h": "Hours"
|
||||||
},
|
},
|
||||||
"extend": " extend delay if new message arrives",
|
"extend": " extend delay if new message arrives",
|
||||||
"tip": "The node can also be reset by sending a message with the <code>msg.reset</code> property set to any value.",
|
|
||||||
"label": {
|
"label": {
|
||||||
"trigger": "trigger",
|
"trigger": "trigger",
|
||||||
"trigger-block": "trigger & block",
|
"trigger-block": "trigger & block",
|
||||||
"reset": "and reset if msg.payload == ",
|
"reset": "Reset the trigger if:",
|
||||||
"resetprompt": "(optional reset value)"
|
"resetMessage":"msg.reset is set",
|
||||||
|
"resetPayload":"msg.payload equals",
|
||||||
|
"resetprompt": "optional"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
|
@ -18,7 +18,7 @@ var should = require("should");
|
|||||||
var helper = require("../../helper.js");
|
var helper = require("../../helper.js");
|
||||||
var triggerNode = require("../../../../nodes/core/core/89-trigger.js");
|
var triggerNode = require("../../../../nodes/core/core/89-trigger.js");
|
||||||
|
|
||||||
describe('trigger Node', function() {
|
describe('trigger node', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helper.startServer(done);
|
helper.startServer(done);
|
||||||
@ -37,8 +37,8 @@ describe('trigger Node', function() {
|
|||||||
n1.should.have.property('name', 'triggerNode');
|
n1.should.have.property('name', 'triggerNode');
|
||||||
n1.should.have.property('op1', '1');
|
n1.should.have.property('op1', '1');
|
||||||
n1.should.have.property('op2', '0');
|
n1.should.have.property('op2', '0');
|
||||||
n1.should.have.property('op1type', 'val');
|
n1.should.have.property('op1type', 'str');
|
||||||
n1.should.have.property('op2type', 'val');
|
n1.should.have.property('op2type', 'str');
|
||||||
n1.should.have.property('extend', "false");
|
n1.should.have.property('extend', "false");
|
||||||
n1.should.have.property('units', 'ms');
|
n1.should.have.property('units', 'ms');
|
||||||
n1.should.have.property('duration', 250);
|
n1.should.have.property('duration', 250);
|
||||||
@ -74,7 +74,7 @@ describe('trigger Node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should output 1 then 0 when triggered (default)', function(done) {
|
it('should output 1 then 0 when triggered (default)', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:20, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -95,50 +95,66 @@ describe('trigger Node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore any other inputs while triggered if extend is false', function(done) {
|
it('should ignore any other inputs while triggered if extend is false', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:50,wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
var n2 = helper.getNode("n2");
|
var n2 = helper.getNode("n2");
|
||||||
var c = 0;
|
var c = 0;
|
||||||
|
var errored = false;
|
||||||
n2.on("input", function(msg) {
|
n2.on("input", function(msg) {
|
||||||
if (c === 0) {
|
try {
|
||||||
msg.should.have.a.property("payload", '1');
|
if (c === 0) {
|
||||||
|
msg.should.have.a.property("payload", '1');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg.should.have.a.property("payload", '0');
|
||||||
|
}
|
||||||
c+=1;
|
c+=1;
|
||||||
}
|
}catch(err) {
|
||||||
else {
|
errored = true;
|
||||||
msg.should.have.a.property("payload", '0');
|
done(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
c.should.equal(1);
|
if (!errored) {
|
||||||
done();
|
try {
|
||||||
},500);
|
c.should.equal(2);
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},100);
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
},75);
|
},10);
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
},150);
|
},30);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle true and false as strings and delay of 0', function(done) {
|
it('should handle true and false as strings and delay of 0', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"true", op2:"false", duration:30, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"true",op1type:"val",op2:"false",op2type:"val",duration:30, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
var n2 = helper.getNode("n2");
|
var n2 = helper.getNode("n2");
|
||||||
var c = 0;
|
var c = 0;
|
||||||
n2.on("input", function(msg) {
|
n2.on("input", function(msg) {
|
||||||
if (c === 0) {
|
try {
|
||||||
msg.should.have.a.property("payload", true);
|
if (c === 0) {
|
||||||
c+=1;
|
msg.should.have.a.property("payload", true);
|
||||||
}
|
c+=1;
|
||||||
else {
|
}
|
||||||
msg.should.have.a.property("payload", false);
|
else {
|
||||||
done();
|
msg.should.have.a.property("payload", false);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
@ -146,21 +162,25 @@ describe('trigger Node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to not output anything on first trigger', function(done) {
|
it('should be able to not output anything on first trigger', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true", op2:"false", duration:30, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:30, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
var n2 = helper.getNode("n2");
|
var n2 = helper.getNode("n2");
|
||||||
n2.on("input", function(msg) {
|
n2.on("input", function(msg) {
|
||||||
msg.should.have.a.property("payload", false);
|
try {
|
||||||
done();
|
msg.should.have.a.property("payload", false);
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to not output anything on second edge', function(done) {
|
it('should be able to not output anything on second edge', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op2type:"nul", op1:"true", op2:"false", duration:30, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op2type:"nul", op1:"true",op1type:"val", op2:"false", duration:30, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -173,13 +193,13 @@ describe('trigger Node', function() {
|
|||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
c.should.equal(1); // should only have had one output.
|
c.should.equal(1); // should only have had one output.
|
||||||
done();
|
done();
|
||||||
},500);
|
},90);
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to extend the delay', function(done) {
|
it('should be able to extend the delay', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op1:"false", op2:"true", duration:200, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op1:"false", op2:"true", duration:100, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -191,9 +211,9 @@ describe('trigger Node', function() {
|
|||||||
c += 1;
|
c += 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg.should.have.a.property("payload", true);
|
msg.should.have.a.property("payload", "true");
|
||||||
//console.log(Date.now() - ss);
|
//console.log(Date.now() - ss);
|
||||||
(Date.now() - ss).should.be.greaterThan(299);
|
(Date.now() - ss).should.be.greaterThan(149);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -201,12 +221,12 @@ describe('trigger Node', function() {
|
|||||||
n1.emit("input", {payload:"Hello"});
|
n1.emit("input", {payload:"Hello"});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
},100);
|
},50);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to extend the delay (but with no 2nd output)', function(done) {
|
it('should be able to extend the delay (but with no 2nd output)', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op2type:"nul", op1:"false", op2:"true", duration:200, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op2type:"nul", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -220,7 +240,7 @@ describe('trigger Node', function() {
|
|||||||
else {
|
else {
|
||||||
msg.should.have.a.property("payload", "World");
|
msg.should.have.a.property("payload", "World");
|
||||||
//console.log(Date.now() - ss);
|
//console.log(Date.now() - ss);
|
||||||
(Date.now() - ss).should.be.greaterThan(380);
|
(Date.now() - ss).should.be.greaterThan(70);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -228,15 +248,15 @@ describe('trigger Node', function() {
|
|||||||
n1.emit("input", {payload:"Hello"});
|
n1.emit("input", {payload:"Hello"});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"Error"});
|
n1.emit("input", {payload:"Error"});
|
||||||
},100);
|
},20);
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"World"});
|
n1.emit("input", {payload:"World"});
|
||||||
},400);
|
},80);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to extend the delay and output the 2nd payload', function(done) {
|
it('should be able to extend the delay and output the 2nd payload', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:200, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -249,7 +269,7 @@ describe('trigger Node', function() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg.should.have.a.property("payload", "World");
|
msg.should.have.a.property("payload", "World");
|
||||||
(Date.now() - ss).should.be.greaterThan(380);
|
(Date.now() - ss).should.be.greaterThan(70);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -257,15 +277,15 @@ describe('trigger Node', function() {
|
|||||||
n1.emit("input", {payload:"Hello"});
|
n1.emit("input", {payload:"Hello"});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"Goodbye"});
|
n1.emit("input", {payload:"Goodbye"});
|
||||||
},100);
|
},20);
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"World"});
|
n1.emit("input", {payload:"World"});
|
||||||
},400);
|
},80);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able output the 2nd payload', function(done) {
|
it('should be able output the 2nd payload', function(done) {
|
||||||
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"false", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:200, wires:[["n2"]] },
|
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"false", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"} ];
|
{id:"n2", type:"helper"} ];
|
||||||
helper.load(triggerNode, flow, function() {
|
helper.load(triggerNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
@ -278,7 +298,7 @@ describe('trigger Node', function() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg.should.have.a.property("payload", "World");
|
msg.should.have.a.property("payload", "World");
|
||||||
(Date.now() - ss).should.be.greaterThan(380);
|
(Date.now() - ss).should.be.greaterThan(70);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -286,10 +306,10 @@ describe('trigger Node', function() {
|
|||||||
n1.emit("input", {payload:"Hello"});
|
n1.emit("input", {payload:"Hello"});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"Goodbye"});
|
n1.emit("input", {payload:"Goodbye"});
|
||||||
},100);
|
},20);
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
n1.emit("input", {payload:"World"});
|
n1.emit("input", {payload:"World"});
|
||||||
},400);
|
},80);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -348,7 +368,7 @@ describe('trigger Node', function() {
|
|||||||
});
|
});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
if (c === 2) { done(); }
|
if (c === 2) { done(); }
|
||||||
},100);
|
},20);
|
||||||
n1.emit("input", {payload:null}); // trigger
|
n1.emit("input", {payload:null}); // trigger
|
||||||
n1.emit("input", {payload:null}); // blocked
|
n1.emit("input", {payload:null}); // blocked
|
||||||
n1.emit("input", {payload:null}); // blocked
|
n1.emit("input", {payload:null}); // blocked
|
||||||
@ -370,7 +390,7 @@ describe('trigger Node', function() {
|
|||||||
});
|
});
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
if (c === 2) { done(); }
|
if (c === 2) { done(); }
|
||||||
},100);
|
},20);
|
||||||
n1.emit("input", {payload:null}); // trigger
|
n1.emit("input", {payload:null}); // trigger
|
||||||
n1.emit("input", {payload:null}); // blocked
|
n1.emit("input", {payload:null}); // blocked
|
||||||
n1.emit("input", {payload:null}); // blocked
|
n1.emit("input", {payload:null}); // blocked
|
||||||
|
Loading…
Reference in New Issue
Block a user