Remove event passing for icons/examples from the api layer

This commit is contained in:
Nick O'Leary
2017-02-15 22:54:32 +00:00
parent 702e6d3b51
commit 869fdbcc6a
12 changed files with 291 additions and 149 deletions

View File

@@ -27,7 +27,7 @@ var auth = require("../../../red/api/auth");
describe("library api", function() {
function initLibrary(_flows,_libraryEntries) {
function initLibrary(_flows,_libraryEntries,_examples) {
var flows = _flows;
var libraryEntries = _libraryEntries;
library.init(app,{
@@ -84,6 +84,11 @@ describe("library api", function() {
events: {
on: function(){},
removeListener: function(){}
},
nodes: {
getNodeExampleFlows: function() {
return _examples;
}
}
});
}
@@ -179,6 +184,22 @@ describe("library api", function() {
.expect(403)
.end(done);
});
it('includes examples flows if set', function(done) {
var examples = {"d":{"node-module":{"f":["example-one"]}}};
initLibrary({},{},examples);
request(app)
.get('/library/flows')
.expect(200)
.end(function(err,res) {
if (err) {
throw err;
}
res.body.should.have.property('d');
res.body.d.should.have.property('_examples_');
should.deepEqual(res.body.d._examples_,examples);
done();
});
});
});
describe("type", function() {

View File

@@ -29,7 +29,14 @@ describe("ui api", function() {
var app;
before(function() {
ui.init({events:events});
ui.init({
events:events,
nodes: {
getNodeIconPath: function(module,icon) {
return path.resolve(__dirname+'/../../../public/icons/arrow-in.png');
}
}
});
});
describe("slash handler", function() {
before(function() {
@@ -71,10 +78,10 @@ describe("ui api", function() {
res.setEncoding('binary');
res.data = '';
res.on('data', function (chunk) {
res.data += chunk;
res.data += chunk;
});
res.on('end', function () {
callback(null, new Buffer(res.data, 'binary'));
callback(null, new Buffer(res.data, 'binary'));
});
}
function compareBuffers(b1,b2) {
@@ -83,11 +90,10 @@ describe("ui api", function() {
b1[i].should.equal(b2[i]);
}
}
it('returns the default icon when getting an unknown icon', function(done) {
it('returns the requested icon', function(done) {
var defaultIcon = fs.readFileSync(path.resolve(__dirname+'/../../../public/icons/arrow-in.png'));
request(app)
.get("/icons/random-module/youwonthaveme.png")
.get("/icons/module/icon.png")
.expect("Content-Type", /image\/png/)
.expect(200)
.parse(binaryParser)
@@ -101,40 +107,6 @@ describe("ui api", function() {
});
});
it('returns a known icon', function(done) {
var injectIcon = fs.readFileSync(path.resolve(__dirname+'/../../../public/icons/inject.png'));
request(app)
.get("/icons/node-red/inject.png")
.expect("Content-Type", /image\/png/)
.expect(200)
.parse(binaryParser)
.end(function(err, res){
if (err){
return done(err);
}
Buffer.isBuffer(res.body).should.be.true();
compareBuffers(res.body,injectIcon);
done();
});
});
it('returns a registered icon' , function(done) {
var testIcon = fs.readFileSync(path.resolve(__dirname+'/../../resources/icons/test_icon.png'));
events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../resources/icons')});
request(app)
.get("/icons/test-module/test_icon.png")
.expect("Content-Type", /image\/png/)
.expect(200)
.parse(binaryParser)
.end(function(err, res){
if (err){
return done(err);
}
Buffer.isBuffer(res.body).should.be.true();
compareBuffers(res.body,testIcon);
done();
});
});
});
describe("editor ui handler", function() {
@@ -174,8 +146,4 @@ describe("ui api", function() {
});
});
});
});