2015-04-07 17:02:15 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-04-07 17:02:15 +02:00
|
|
|
*
|
|
|
|
* 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 when = require("when");
|
|
|
|
var sinon = require("sinon");
|
2017-02-15 23:54:32 +01:00
|
|
|
var path = require("path");
|
2015-04-07 17:02:15 +02:00
|
|
|
|
2015-11-12 08:56:23 +01:00
|
|
|
var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry");
|
2015-04-07 17:02:15 +02:00
|
|
|
|
2016-04-07 23:18:28 +02:00
|
|
|
var Node = require("../../../../../red/runtime/nodes/Node");
|
|
|
|
|
2015-11-14 00:16:47 +01:00
|
|
|
var events = require("../../../../../red/runtime/events");
|
|
|
|
|
2016-04-07 23:18:28 +02:00
|
|
|
var inherits = require("util").inherits;
|
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
describe("red/nodes/registry/registry",function() {
|
2015-11-14 00:16:47 +01:00
|
|
|
|
|
|
|
afterEach(function() {
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.clear();
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
function stubSettings(s,available,initialConfig) {
|
|
|
|
s.available = function() {return available;};
|
2015-11-14 00:16:47 +01:00
|
|
|
s.set = sinon.spy(function(s,v) { return when.resolve();});
|
2015-04-07 17:02:15 +02:00
|
|
|
s.get = function(s) { return initialConfig;};
|
|
|
|
return s;
|
|
|
|
}
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
var settings = stubSettings({},false,null);
|
|
|
|
var settingsWithStorageAndInitialConfig = stubSettings({},true,{"node-red":{module:"testModule",name:"testName",version:"testVersion",nodes:{"node":{id:"node-red/testName",name:"test",types:["a","b"],enabled:true}}}});
|
|
|
|
|
|
|
|
var testNodeSet1 = {
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
2015-11-14 00:16:47 +01:00
|
|
|
config: "configA",
|
2015-04-07 17:02:15 +02:00
|
|
|
types: [ "test-a","test-b"]
|
|
|
|
};
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
var testNodeSet2 = {
|
|
|
|
id: "test-module/test-name-2",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name-2",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
2015-11-14 00:16:47 +01:00
|
|
|
config: "configB",
|
2015-04-07 17:02:15 +02:00
|
|
|
types: [ "test-c","test-d"]
|
|
|
|
};
|
|
|
|
var testNodeSet2WithError = {
|
|
|
|
id: "test-module/test-name-2",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name-2",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
err: "I have an error",
|
2015-11-14 00:16:47 +01:00
|
|
|
config: "configC",
|
2015-04-07 17:02:15 +02:00
|
|
|
types: [ "test-c","test-d"]
|
|
|
|
};
|
2018-01-16 00:20:20 +01:00
|
|
|
var testNodeSet3 = {
|
|
|
|
id: "test-module-2/test-name-3",
|
|
|
|
module: "test-module-2",
|
|
|
|
name: "test-name-3",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configB",
|
|
|
|
types: [ "test-a","test-e"]
|
|
|
|
};
|
2015-11-14 00:16:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-15 01:11:28 +02:00
|
|
|
describe('#init/load', function() {
|
2015-04-07 17:02:15 +02:00
|
|
|
it('loads initial config', function(done) {
|
|
|
|
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
2016-07-15 01:11:28 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
|
|
|
typeRegistry.load();
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
|
|
|
done();
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
it('migrates legacy format', function(done) {
|
|
|
|
var legacySettings = {
|
|
|
|
available: function() { return true; },
|
|
|
|
set: sinon.stub().returns(when.resolve()),
|
|
|
|
get: function() { return {
|
|
|
|
"123": {
|
|
|
|
"name": "72-sentiment.js",
|
|
|
|
"types": [
|
|
|
|
"sentiment"
|
|
|
|
],
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
"456": {
|
|
|
|
"name": "20-inject.js",
|
|
|
|
"types": [
|
|
|
|
"inject"
|
|
|
|
],
|
|
|
|
"enabled": true
|
|
|
|
},
|
|
|
|
"789": {
|
|
|
|
"name": "testModule:a-module.js",
|
|
|
|
"types": [
|
|
|
|
"example"
|
|
|
|
],
|
|
|
|
"enabled":true,
|
|
|
|
"module":"testModule"
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
};
|
|
|
|
var expected = JSON.parse('{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}');
|
|
|
|
typeRegistry.init(legacySettings);
|
2016-07-15 01:11:28 +02:00
|
|
|
typeRegistry.load();
|
2016-10-10 14:27:43 +02:00
|
|
|
legacySettings.set.calledOnce.should.be.true();
|
2015-04-07 17:02:15 +02:00
|
|
|
legacySettings.set.args[0][1].should.eql(expected);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
|
|
|
|
2018-05-21 23:08:04 +02:00
|
|
|
describe.skip('#addNodeSet', function() {
|
2015-04-07 17:02:15 +02:00
|
|
|
it('adds a node set for an unknown module', function() {
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.init(settings);
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
2015-04-08 21:17:24 +02:00
|
|
|
typeRegistry.getModuleList().should.eql({});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
2015-04-08 21:17:24 +02:00
|
|
|
var moduleList = typeRegistry.getModuleList();
|
|
|
|
moduleList.should.have.a.property("test-module");
|
|
|
|
moduleList["test-module"].should.have.a.property("name","test-module");
|
|
|
|
moduleList["test-module"].should.have.a.property("version","0.0.1");
|
|
|
|
moduleList["test-module"].should.have.a.property("nodes");
|
|
|
|
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-08 21:17:24 +02:00
|
|
|
moduleList["test-module"].nodes["test-name"].should.eql({
|
2015-11-14 00:16:47 +01:00
|
|
|
config: 'configA',
|
2015-04-08 21:17:24 +02:00
|
|
|
id: 'test-module/test-name',
|
|
|
|
module: 'test-module',
|
|
|
|
name: 'test-name',
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
types: [ 'test-a', 'test-b' ]
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
it('adds a node set to an existing module', function() {
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.init(settings);
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
2015-04-08 21:17:24 +02:00
|
|
|
typeRegistry.getModuleList().should.eql({});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-08 21:17:24 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
|
|
|
var moduleList = typeRegistry.getModuleList();
|
|
|
|
Object.keys(moduleList).should.have.a.lengthOf(1);
|
|
|
|
moduleList.should.have.a.property("test-module");
|
|
|
|
moduleList["test-module"].should.have.a.property("name","test-module");
|
|
|
|
moduleList["test-module"].should.have.a.property("version","0.0.1");
|
|
|
|
moduleList["test-module"].should.have.a.property("nodes");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-08 21:17:24 +02:00
|
|
|
Object.keys(moduleList["test-module"].nodes).should.have.a.lengthOf(1);
|
|
|
|
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
|
|
|
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2);
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(2);
|
2015-04-08 21:17:24 +02:00
|
|
|
moduleList = typeRegistry.getModuleList();
|
|
|
|
Object.keys(moduleList).should.have.a.lengthOf(1);
|
|
|
|
Object.keys(moduleList["test-module"].nodes).should.have.a.lengthOf(2);
|
|
|
|
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
|
|
|
moduleList["test-module"].nodes.should.have.a.property("test-name-2");
|
2015-04-07 17:02:15 +02:00
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
it('doesnt add node set types if node set has an error', function() {
|
|
|
|
typeRegistry.init(settings);
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
2015-04-08 21:17:24 +02:00
|
|
|
typeRegistry.getModuleList().should.eql({});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.getTypeId("test-a").should.eql("test-module/test-name");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
should.not.exist(typeRegistry.getTypeId("test-c"));
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
should.not.exist(typeRegistry.getTypeId("test-c"));
|
2018-01-16 00:20:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('doesnt add node set if type already exists', function() {
|
|
|
|
typeRegistry.init(settings);
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
|
|
|
typeRegistry.getModuleList().should.eql({});
|
|
|
|
|
|
|
|
should.not.exist(typeRegistry.getTypeId("test-e"));
|
|
|
|
|
|
|
|
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
|
|
|
should.exist(typeRegistry.getTypeId("test-a"));
|
|
|
|
typeRegistry.addNodeSet(testNodeSet3.id,testNodeSet3, "0.0.1");
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(2);
|
|
|
|
|
|
|
|
// testNodeSet3 registers a duplicate test-a and unique test-e
|
|
|
|
// as test-a is a duplicate, test-e should not get registered
|
|
|
|
should.not.exist(typeRegistry.getTypeId("test-e"));
|
|
|
|
|
|
|
|
var testNodeSet3Result = typeRegistry.getNodeList()[1];
|
|
|
|
should.exist(testNodeSet3Result.err);
|
|
|
|
testNodeSet3Result.err.code.should.equal("type_already_registered");
|
|
|
|
testNodeSet3Result.err.details.type.should.equal("test-a");
|
|
|
|
testNodeSet3Result.err.details.moduleA.should.equal("test-module");
|
|
|
|
testNodeSet3Result.err.details.moduleB.should.equal("test-module-2");
|
|
|
|
|
|
|
|
//
|
|
|
|
// typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
|
|
|
//
|
|
|
|
// should.not.exist(typeRegistry.getTypeId("test-c"));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
describe("#enableNodeSet", function() {
|
|
|
|
it('throws error if settings unavailable', function() {
|
|
|
|
typeRegistry.init(settings);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.enableNodeSet("test-module/test-name");
|
|
|
|
}).should.throw("Settings unavailable");
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
it('throws error if module unknown', function() {
|
|
|
|
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.enableNodeSet("test-module/unknown");
|
|
|
|
}).should.throw("Unrecognised id: test-module/unknown");
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
it.skip('enables the node',function(){})
|
|
|
|
|
|
|
|
});
|
|
|
|
describe("#disableNodeSet", function() {
|
|
|
|
it('throws error if settings unavailable', function() {
|
|
|
|
typeRegistry.init(settings);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.disableNodeSet("test-module/test-name");
|
|
|
|
}).should.throw("Settings unavailable");
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws error if module unknown', function() {
|
|
|
|
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.disableNodeSet("test-module/unknown");
|
|
|
|
}).should.throw("Unrecognised id: test-module/unknown");
|
|
|
|
});
|
|
|
|
it.skip('disables the node',function(){})
|
2015-04-07 17:02:15 +02:00
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
describe('#getNodeConfig', function() {
|
|
|
|
it('returns nothing for an unregistered type config', function(done) {
|
|
|
|
typeRegistry.init(settings);
|
|
|
|
var config = typeRegistry.getNodeConfig("imaginary-shark");
|
2016-10-10 14:27:43 +02:00
|
|
|
(config === null).should.be.true();
|
2015-04-07 17:02:15 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
|
|
|
|
describe('#saveNodeList',function() {
|
|
|
|
it('rejects when settings unavailable',function(done) {
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.init(stubSettings({},false,{}),null,events);
|
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {"test-name":{module:"test-module",name:"test-name",types:[]}}});
|
|
|
|
typeRegistry.saveNodeList().catch(function(err) {
|
2015-11-14 00:16:47 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('saves the list',function(done) {
|
|
|
|
var s = stubSettings({},true,{});
|
|
|
|
typeRegistry.init(s);
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":testNodeSet1,
|
|
|
|
"test-name-2":testNodeSet2WithError
|
|
|
|
}});
|
|
|
|
|
2015-11-14 00:16:47 +01:00
|
|
|
typeRegistry.saveNodeList().then(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
s.set.called.should.be.true();
|
2015-11-14 00:16:47 +01:00
|
|
|
s.set.lastCall.args[0].should.eql('nodes');
|
|
|
|
var nodes = s.set.lastCall.args[1];
|
|
|
|
nodes.should.have.property('test-module');
|
|
|
|
for (var n in nodes['test-module'].nodes) {
|
2018-05-21 23:08:04 +02:00
|
|
|
if (nodes['test-module'].nodes.hasOwnProperty(n)) {
|
|
|
|
var nn = nodes['test-module'].nodes[n];
|
|
|
|
nn.should.not.have.property('err');
|
|
|
|
nn.should.not.have.property('id');
|
|
|
|
}
|
2015-11-14 00:16:47 +01:00
|
|
|
}
|
|
|
|
done();
|
2018-05-21 23:08:04 +02:00
|
|
|
}).catch(function(err) {
|
2015-11-14 00:16:47 +01:00
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#removeModule',function() {
|
|
|
|
it('throws error for unknown module', function() {
|
|
|
|
var s = stubSettings({},true,{});
|
|
|
|
typeRegistry.init(s);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.removeModule("test-module/unknown");
|
|
|
|
}).should.throw("Unrecognised module: test-module/unknown");
|
|
|
|
});
|
|
|
|
it('throws error for unavaiable settings', function() {
|
|
|
|
var s = stubSettings({},false,{});
|
|
|
|
typeRegistry.init(s);
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
|
|
|
typeRegistry.removeModule("test-module/unknown");
|
|
|
|
}).should.throw("Settings unavailable");
|
|
|
|
});
|
|
|
|
it('removes a known module', function() {
|
|
|
|
var s = stubSettings({},true,{});
|
|
|
|
typeRegistry.init(s);
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":testNodeSet1
|
|
|
|
}});
|
2015-11-14 00:16:47 +01:00
|
|
|
var moduleList = typeRegistry.getModuleList();
|
|
|
|
moduleList.should.have.a.property("test-module");
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
|
|
|
|
|
|
|
var info = typeRegistry.removeModule('test-module');
|
|
|
|
moduleList = typeRegistry.getModuleList();
|
|
|
|
moduleList.should.not.have.a.property("test-module");
|
|
|
|
typeRegistry.getNodeList().should.have.lengthOf(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#get[All]NodeConfigs', function() {
|
|
|
|
it('returns node config', function() {
|
|
|
|
typeRegistry.init(settings,{
|
|
|
|
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
|
|
|
|
});
|
2018-05-21 23:08:04 +02:00
|
|
|
|
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"]
|
|
|
|
},
|
|
|
|
"test-name-2":{
|
|
|
|
id: "test-module/test-name-2",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name-2",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configB",
|
|
|
|
types: [ "test-c","test-d"]
|
|
|
|
}
|
|
|
|
}});
|
2018-05-11 23:30:57 +02:00
|
|
|
typeRegistry.getNodeConfig("test-module/test-name").should.eql('<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
|
|
|
|
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
|
|
|
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP\n<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
2015-11-14 00:16:47 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('#getModuleInfo', function() {
|
|
|
|
it('returns module info', function() {
|
|
|
|
typeRegistry.init(settings,{});
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
}
|
|
|
|
}});
|
2015-11-14 00:16:47 +01:00
|
|
|
var moduleInfo = typeRegistry.getModuleInfo("test-module");
|
|
|
|
moduleInfo.should.have.a.property('name','test-module');
|
|
|
|
moduleInfo.should.have.a.property('version','0.0.1');
|
|
|
|
moduleInfo.should.have.a.property('nodes');
|
|
|
|
moduleInfo.nodes.should.have.a.lengthOf(1);
|
|
|
|
moduleInfo.nodes[0].should.have.a.property('id','test-module/test-name');
|
|
|
|
moduleInfo.nodes[0].should.not.have.a.property('file');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('#getNodeInfo', function() {
|
|
|
|
it('returns node info', function() {
|
|
|
|
typeRegistry.init(settings,{});
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
}
|
|
|
|
}});
|
2015-11-14 00:16:47 +01:00
|
|
|
var nodeSetInfo = typeRegistry.getNodeInfo("test-module/test-name");
|
|
|
|
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
|
|
|
nodeSetInfo.should.not.have.a.property('config');
|
|
|
|
nodeSetInfo.should.not.have.a.property('file');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('#getFullNodeInfo', function() {
|
|
|
|
it('returns node info', function() {
|
|
|
|
typeRegistry.init(settings,{});
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
|
|
|
|
}
|
|
|
|
}});
|
2015-11-14 00:16:47 +01:00
|
|
|
var nodeSetInfo = typeRegistry.getFullNodeInfo("test-module/test-name");
|
|
|
|
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
|
|
|
nodeSetInfo.should.have.a.property('config');
|
|
|
|
nodeSetInfo.should.have.a.property('file');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('#cleanModuleList', function() {
|
|
|
|
it.skip("cleans the module list");
|
|
|
|
});
|
|
|
|
describe('#getNodeList', function() {
|
|
|
|
it("returns a filtered list", function() {
|
|
|
|
typeRegistry.init(settings,{});
|
2018-05-21 23:08:04 +02:00
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
},
|
|
|
|
"test-name-2":{
|
|
|
|
id: "test-module/test-name-2",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name-2",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configB",
|
|
|
|
types: [ "test-c","test-d"],
|
|
|
|
file: "def"
|
|
|
|
}
|
|
|
|
}});
|
2015-11-14 00:16:47 +01:00
|
|
|
var filterCallCount = 0;
|
|
|
|
var filteredList = typeRegistry.getNodeList(function(n) { filterCallCount++; return n.name === 'test-name-2';});
|
|
|
|
filterCallCount.should.eql(2);
|
|
|
|
filteredList.should.have.a.lengthOf(1);
|
|
|
|
filteredList[0].should.have.a.property('id',"test-module/test-name-2");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#registerNodeConstructor', function() {
|
2016-04-07 23:18:28 +02:00
|
|
|
var TestNodeConstructor;
|
2015-11-14 00:16:47 +01:00
|
|
|
beforeEach(function() {
|
2016-04-07 23:18:28 +02:00
|
|
|
TestNodeConstructor = function TestNodeConstructor() {
|
|
|
|
};
|
2015-11-14 00:16:47 +01:00
|
|
|
sinon.stub(events,'emit');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
events.emit.restore();
|
|
|
|
});
|
|
|
|
it('registers a node constructor', function() {
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
2016-10-10 14:27:43 +02:00
|
|
|
events.emit.calledOnce.should.be.true();
|
2015-11-14 00:16:47 +01:00
|
|
|
events.emit.lastCall.args[0].should.eql('type-registered');
|
|
|
|
events.emit.lastCall.args[1].should.eql('node-type');
|
|
|
|
})
|
|
|
|
it('throws error on duplicate node registration', function() {
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
2016-10-10 14:27:43 +02:00
|
|
|
events.emit.calledOnce.should.be.true();
|
2015-11-14 00:16:47 +01:00
|
|
|
events.emit.lastCall.args[0].should.eql('type-registered');
|
|
|
|
events.emit.lastCall.args[1].should.eql('node-type');
|
|
|
|
/*jshint immed: false */
|
|
|
|
(function(){
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
2015-11-14 00:16:47 +01:00
|
|
|
}).should.throw("node-type already registered");
|
2016-10-10 14:27:43 +02:00
|
|
|
events.emit.calledOnce.should.be.true();
|
2016-04-07 23:18:28 +02:00
|
|
|
});
|
|
|
|
it('extends a constructor with the Node constructor', function() {
|
|
|
|
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
2016-04-07 23:18:28 +02:00
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
|
|
|
});
|
|
|
|
it('does not override a constructor\'s prototype', function() {
|
|
|
|
function Foo(){};
|
|
|
|
inherits(TestNodeConstructor,Foo);
|
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
|
|
|
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
|
|
|
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
2016-04-07 23:18:28 +02:00
|
|
|
|
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
|
|
|
|
2016-04-28 12:23:42 +02:00
|
|
|
typeRegistry.registerNodeConstructor('node-set','node-type2',TestNodeConstructor);
|
2016-04-07 23:18:28 +02:00
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
|
|
|
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
|
|
|
});
|
2015-11-14 00:16:47 +01:00
|
|
|
});
|
|
|
|
|
2017-02-15 23:54:32 +01:00
|
|
|
describe('#getNodeIconPath', function() {
|
|
|
|
it('returns the default icon when getting an unknown icon', function() {
|
|
|
|
var defaultIcon = path.resolve(__dirname+'/../../../../../public/icons/arrow-in.png');
|
|
|
|
var iconPath = typeRegistry.getNodeIconPath('random-module','youwonthaveme.png');
|
|
|
|
iconPath.should.eql(defaultIcon);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a registered icon' , function() {
|
2018-05-21 23:08:04 +02:00
|
|
|
var testIcon = path.resolve(__dirname+'/../../../../resources/icons/');
|
|
|
|
typeRegistry.init(settings,{});
|
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
}
|
|
|
|
},icons: [{path:testIcon,icons:['test_icon.png']}]});
|
2017-02-15 23:54:32 +01:00
|
|
|
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
|
2018-05-24 05:06:39 +02:00
|
|
|
iconPath.should.eql(path.resolve(testIcon+"/test_icon.png"));
|
2017-02-15 23:54:32 +01:00
|
|
|
});
|
2017-07-04 10:04:27 +02:00
|
|
|
|
|
|
|
it('returns the debug icon when getting an unknown module', function() {
|
|
|
|
var debugIcon = path.resolve(__dirname+'/../../../../../public/icons/debug.png');
|
|
|
|
var iconPath = typeRegistry.getNodeIconPath('unknown-module', 'debug.png');
|
|
|
|
iconPath.should.eql(debugIcon);
|
|
|
|
});
|
2017-02-15 23:54:32 +01:00
|
|
|
});
|
|
|
|
|
2017-11-30 14:13:35 +01:00
|
|
|
describe('#getNodeIcons', function() {
|
|
|
|
it('returns empty icon list when no modules are registered', function() {
|
|
|
|
var iconList = typeRegistry.getNodeIcons();
|
|
|
|
iconList.should.eql({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns an icon list of registered node module', function() {
|
2018-05-21 23:08:04 +02:00
|
|
|
var testIcon = path.resolve(__dirname+'/resources/userDir/lib/icons/');
|
|
|
|
typeRegistry.init(settings,{},events);
|
|
|
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
|
|
|
"test-name":{
|
|
|
|
id: "test-module/test-name",
|
|
|
|
module: "test-module",
|
|
|
|
name: "test-name",
|
|
|
|
enabled: true,
|
|
|
|
loaded: false,
|
|
|
|
config: "configA",
|
|
|
|
types: [ "test-a","test-b"],
|
|
|
|
file: "abc"
|
|
|
|
}
|
|
|
|
},icons: [{path:testIcon,icons:['test_icon.png']}]});
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconList = typeRegistry.getNodeIcons();
|
2018-05-21 23:08:04 +02:00
|
|
|
iconList.should.eql({"test-module":["test_icon.png"]});
|
2017-11-30 14:13:35 +01:00
|
|
|
});
|
|
|
|
|
2018-05-21 23:08:04 +02:00
|
|
|
it.skip('returns an icon list of unregistered node module', function() {
|
|
|
|
// events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconList = typeRegistry.getNodeIcons();
|
|
|
|
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
});
|