mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add initial subflow tests
This commit is contained in:
parent
d9648ca76b
commit
6169e4299a
@ -79,6 +79,7 @@ function createSubflow(sf,sfn) {
|
|||||||
var Node = require("./Node");
|
var Node = require("./Node");
|
||||||
var subflowInstance = {
|
var subflowInstance = {
|
||||||
id: sfn.id,
|
id: sfn.id,
|
||||||
|
type: sfn.type,
|
||||||
name: sfn.name,
|
name: sfn.name,
|
||||||
wires: []
|
wires: []
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,12 @@ function loadFlows(testFlows, cb) {
|
|||||||
|
|
||||||
describe('flows', function() {
|
describe('flows', function() {
|
||||||
|
|
||||||
|
afterEach(function(done) {
|
||||||
|
flows.clear().then(function() {
|
||||||
|
loadFlows([],done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#add',function() {
|
describe('#add',function() {
|
||||||
it('should be called by node constructor',function(done) {
|
it('should be called by node constructor',function(done) {
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
@ -108,6 +114,58 @@ describe('flows', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not instantiate nodes of an unused subflow', function(done) {
|
||||||
|
RED.registerType('abc', function() {});
|
||||||
|
var typeRegistryGet = sinon.stub(typeRegistry,"get",function(nt) {
|
||||||
|
return function() {};
|
||||||
|
});
|
||||||
|
loadFlows([{"id":"n1","type":"subflow",inputs:[],outputs:[],wires:[]},
|
||||||
|
{"id":"n2","type":"abc","z":"n1",wires:[]}
|
||||||
|
],function() { });
|
||||||
|
events.once('nodes-started', function() {
|
||||||
|
(flows.get("n2") == null).should.be.true;
|
||||||
|
var ncount = 0
|
||||||
|
flows.each(function(n) {
|
||||||
|
ncount++;
|
||||||
|
});
|
||||||
|
ncount.should.equal(0);
|
||||||
|
console.log(ncount);
|
||||||
|
typeRegistryGet.restore();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should instantiate nodes of an used subflow with new IDs', function(done) {
|
||||||
|
RED.registerType('abc', function() {});
|
||||||
|
var typeRegistryGet = sinon.stub(typeRegistry,"get",function(nt) {
|
||||||
|
return RedNode;
|
||||||
|
});
|
||||||
|
loadFlows([{"id":"n1","type":"subflow",inputs:[],outputs:[]},
|
||||||
|
{"id":"n2","type":"abc","z":"n1","name":"def",wires:[]},
|
||||||
|
{"id":"n3","type":"subflow:n1"}
|
||||||
|
], function() { });
|
||||||
|
events.once('nodes-started', function() {
|
||||||
|
// n2 should not get instantiated with that id
|
||||||
|
(flows.get("n2") == null).should.be.true;
|
||||||
|
var ncount = 0
|
||||||
|
var nodes = [];
|
||||||
|
flows.each(function(n) {
|
||||||
|
nodes.push(n);
|
||||||
|
});
|
||||||
|
nodes.should.have.lengthOf(2);
|
||||||
|
|
||||||
|
// Assume the nodes are instantiated in this order - not
|
||||||
|
// a requirement, but makes the test easier to write.
|
||||||
|
nodes[0].should.have.property("id","n3");
|
||||||
|
nodes[0].should.have.property("type","subflow:n1");
|
||||||
|
nodes[1].should.not.have.property("id","n2");
|
||||||
|
nodes[1].should.have.property("name","def");
|
||||||
|
|
||||||
|
// TODO: verify instance wiring is correct
|
||||||
|
typeRegistryGet.restore();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#setFlows',function() {
|
describe('#setFlows',function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user