mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow node.status() to be passed number/bool types
Adds to the existing support for string types. Also adds unit tests for all three cases
This commit is contained in:
parent
147d2a02be
commit
c1c694035d
@ -539,7 +539,12 @@ Node.prototype.metric = function(eventname, msg, metricValue) {
|
||||
* status: "simple text status"
|
||||
*/
|
||||
Node.prototype.status = function(status) {
|
||||
if (typeof(status) === "string") { status = {text:status}; }
|
||||
switch (typeof status) {
|
||||
case "string":
|
||||
case "number":
|
||||
case "boolean":
|
||||
status = {text:""+status}
|
||||
}
|
||||
this._flow.handleStatus(this,status);
|
||||
};
|
||||
|
||||
|
@ -613,9 +613,6 @@ describe('Node', function() {
|
||||
}
|
||||
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
|
||||
var status = {fill:"green",shape:"dot",text:"connected"};
|
||||
var topic;
|
||||
var message;
|
||||
var retain;
|
||||
|
||||
n.status(status);
|
||||
|
||||
@ -624,6 +621,33 @@ describe('Node', function() {
|
||||
flow.handleStatus.args[0][1].should.eql(status);
|
||||
done();
|
||||
});
|
||||
it('publishes status for plain string', function(done) {
|
||||
var flow = { handleStatus: sinon.stub() }
|
||||
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
|
||||
n.status("text status");
|
||||
flow.handleStatus.called.should.be.true();
|
||||
flow.handleStatus.args[0][0].should.eql(n);
|
||||
flow.handleStatus.args[0][1].should.eql({text:"text status"});
|
||||
done();
|
||||
});
|
||||
it('publishes status for plain boolean', function(done) {
|
||||
var flow = { handleStatus: sinon.stub() }
|
||||
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
|
||||
n.status(false);
|
||||
flow.handleStatus.called.should.be.true();
|
||||
flow.handleStatus.args[0][0].should.eql(n);
|
||||
flow.handleStatus.args[0][1].should.eql({text:"false"});
|
||||
done();
|
||||
});
|
||||
it('publishes status for plain number', function(done) {
|
||||
var flow = { handleStatus: sinon.stub() }
|
||||
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
|
||||
n.status(123);
|
||||
flow.handleStatus.called.should.be.true();
|
||||
flow.handleStatus.args[0][0].should.eql(n);
|
||||
flow.handleStatus.args[0][1].should.eql({text:"123"});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user