mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add test script for link node (#1463)
* fixed unmatched HTML tags * add test for link node & red.js fix for it
This commit is contained in:
parent
80a8efd8ce
commit
8f2f7ea1a5
@ -97,6 +97,7 @@ module.exports = {
|
||||
settings:runtime.settings,
|
||||
util: runtime.util,
|
||||
version: runtime.version,
|
||||
events: runtime.events,
|
||||
|
||||
comms: api.comms,
|
||||
library: api.library,
|
||||
|
118
test/nodes/core/core/60-link_spec.js
Normal file
118
test/nodes/core/core/60-link_spec.js
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var linkNode = require("../../../../nodes/core/core/60-link.js");
|
||||
var helper = require("../../helper.js");
|
||||
|
||||
describe('link Node', function() {
|
||||
|
||||
before(function(done) {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
||||
it('should be loaded (link in)', function(done) {
|
||||
var flow = [{id:"n1", type:"link in", name: "link-in" }];
|
||||
helper.load(linkNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property('name', 'link-in');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be loaded (link out)', function(done) {
|
||||
var flow = [{id:"n1", type:"link out", name: "link-out" }];
|
||||
helper.load(linkNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property('name', 'link-out');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be linked', function(done) {
|
||||
var flow = [{id:"n1", type:"link out", name: "link-out", links:["n2"]},
|
||||
{id:"n2", type:"link in", name: "link-in", wires:[["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
helper.load(linkNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n3 = helper.getNode("n3");
|
||||
n3.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('payload', 'hello');
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:"hello"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be linked to multiple nodes', function(done) {
|
||||
var flow = [{id:"n1", type:"link out", name: "link-out", links:["n2", "n3"]},
|
||||
{id:"n2", type:"link in", name: "link-in0", wires:[["n4"]]},
|
||||
{id:"n3", type:"link in", name: "link-in1", wires:[["n4"]]},
|
||||
{id:"n4", type:"helper"} ];
|
||||
helper.load(linkNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n4 = helper.getNode("n4");
|
||||
var count = 0;
|
||||
n4.on("input", function (msg) {
|
||||
try {
|
||||
msg.should.have.property('payload', 'hello');
|
||||
count++;
|
||||
if(count == 2) {
|
||||
done();
|
||||
}
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:"hello"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be linked from multiple nodes', function(done) {
|
||||
var flow = [{id:"n1", type:"link out", name: "link-out0", links:["n3"]},
|
||||
{id:"n2", type:"link out", name: "link-out1", links:["n3"]},
|
||||
{id:"n3", type:"link in", name: "link-in", wires:[["n4"]]},
|
||||
{id:"n4", type:"helper"} ];
|
||||
helper.load(linkNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var n4 = helper.getNode("n4");
|
||||
var count = 0;
|
||||
n4.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('payload', 'hello');
|
||||
count++;
|
||||
if(count == 2) {
|
||||
done();
|
||||
}
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:"hello"});
|
||||
n2.receive({payload:"hello"});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user