allow a node's icon to be set dynamically (#1490)

* create a proto type

* Fixed some problems after reviewing
This commit is contained in:
Kazuki Nakanishi
2017-11-30 13:13:35 +00:00
committed by Nick O'Leary
parent cc88ebd2b9
commit 6d2389945b
16 changed files with 367 additions and 19 deletions

View File

@@ -150,7 +150,22 @@ describe("red/nodes/registry/localfilesystem",function() {
});
it.skip("finds locales directory");
it.skip("finds icon path directory");
it("scans icon files in the resources tree",function(done) {
var count = 0;
localfilesystem.init({
i18n:{registerMessageCatalog:function(){}},
events:{emit:function(eventName,dir){
eventName.should.equal("node-icon-dir");
dir.name.should.equal("node-red");
dir.icons.should.be.an.Array();
if (count++ === 1) {
done();
}
}},
settings:{coreNodesDir:resourcesDir}
});
localfilesystem.getNodeFiles(true);
});
});
describe("#getModuleFiles",function() {
it("gets a nodes module files",function(done) {
@@ -196,5 +211,27 @@ describe("red/nodes/registry/localfilesystem",function() {
});
it.skip("finds locales directory");
it.skip("finds icon path directory");
it("scans icon files with a module file",function(done) {
var _join = path.join;
stubs.push(sinon.stub(path,"join",function() {
if (arguments[0] == resourcesDir) {
// This stops the module tree scan from going any higher
// up the tree than resourcesDir.
return arguments[0];
}
return _join.apply(null,arguments);
}));
localfilesystem.init({
i18n:{registerMessageCatalog:function(){}},
events:{emit:function(eventName,dir){
eventName.should.equal("node-icon-dir");
dir.name.should.equal("TestNodeModule");
dir.icons.should.be.an.Array();
done();
}},
settings:{coreNodesDir:moduleDir}
});
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
});
});
});

View File

@@ -493,7 +493,7 @@ describe("red/nodes/registry/registry",function() {
it('returns a registered icon' , function() {
var testIcon = path.resolve(__dirname+'/../../../../resources/icons/test_icon.png');
events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../../../resources/icons')});
events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../../../resources/icons'), icons:[]});
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
iconPath.should.eql(testIcon);
});
@@ -505,4 +505,24 @@ describe("red/nodes/registry/registry",function() {
});
});
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() {
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1,"0.0.1");
events.emit("node-icon-dir",{name:"test-module", path:"",icons:["test_icon1.png"]});
var iconList = typeRegistry.getNodeIcons();
iconList.should.eql({"test-module":["test_icon1.png"]});
});
it('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"]});
var iconList = typeRegistry.getNodeIcons();
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
});
});
});