[Status] Revise API

Change method names, add a getter to status capability;
per code review feedback, nasa/openmctweb#319.
This commit is contained in:
Victor Woeltjen 2015-11-20 09:46:08 -08:00
parent b5d1118a3f
commit 400b992ec3
6 changed files with 27 additions and 13 deletions

View File

@ -49,11 +49,20 @@ define(
}
/**
* Get all status flags currently set for this domain object.
* List all status flags currently set for this domain object.
* @returns {string[]} all current status flags.
*/
StatusCapability.prototype.get = function () {
return this.statusService.getStatus(this.domainObject.getId());
StatusCapability.prototype.list = function () {
return this.statusService.listStatuses(this.domainObject.getId());
};
/**
* Check if a status flag is currently set for this domain object.
* @param {string} status the status to get
* @returns {boolean} true if the flag is present, otherwise false
*/
StatusCapability.prototype.get = function (status) {
return this.list().indexOf(status) !== -1;
};
/**

View File

@ -77,7 +77,7 @@ define(
self.lastClasses = newClasses;
}
updateStatus(statusCapability.get());
updateStatus(statusCapability.list());
this.unlisten = statusCapability.listen(updateStatus);
};

View File

@ -51,7 +51,7 @@ define(
* @returns {string[]} an array containing all status flags currently
* applicable to the object with this identifier
*/
StatusService.prototype.getStatus = function (id) {
StatusService.prototype.listStatuses = function (id) {
return this.statusTable[id] || [];
};

View File

@ -40,7 +40,7 @@ define(
mockStatusService = jasmine.createSpyObj(
'statusService',
[ 'listen', 'setStatus', 'getStatus' ]
[ 'listen', 'setStatus', 'listStatuses' ]
);
mockDomainObject = jasmine.createSpyObj(
'domainObject',
@ -49,7 +49,7 @@ define(
mockUnlisten = jasmine.createSpy('unlisten');
mockStatusService.listen.andReturn(mockUnlisten);
mockStatusService.getStatus.andReturn(testStatusFlags);
mockStatusService.listStatuses.andReturn(testStatusFlags);
mockDomainObject.getId.andReturn(testId);
capability = new StatusCapability(
@ -69,7 +69,7 @@ define(
});
it("gets status from the statusService", function () {
expect(capability.get()).toBe(testStatusFlags);
expect(capability.list()).toBe(testStatusFlags);
});
it("listens to changes from the statusService", function () {
@ -79,6 +79,11 @@ define(
expect(mockStatusService.listen)
.toHaveBeenCalledWith(testId, mockCallback);
});
it("allows statuses to be checked individually", function () {
expect(capability.get('some-unset-status')).toBe(false);
expect(capability.get(testStatusFlags[0])).toBe(true);
});
});
}
);

View File

@ -66,7 +66,7 @@ define(
);
mockStatusCapability = jasmine.createSpyObj(
'status',
[ 'get', 'set', 'listen' ]
[ 'list', 'get', 'set', 'listen' ]
);
mockUnlisten = jasmine.createSpy();
@ -79,7 +79,7 @@ define(
delete elementClasses[c];
});
mockStatusCapability.get.andReturn(testStatusFlags);
mockStatusCapability.list.andReturn(testStatusFlags);
mockStatusCapability.listen.andReturn(mockUnlisten);
mockDomainObject.getCapability.andCallFake(function (c) {

View File

@ -54,14 +54,14 @@ define(
});
it("initially contains no flags for an object", function () {
expect(statusService.getStatus(testId)).toEqual([]);
expect(statusService.listStatuses(testId)).toEqual([]);
});
it("stores and clears status flags", function () {
statusService.setStatus(testId, testStatus, true);
expect(statusService.getStatus(testId)).toEqual([testStatus]);
expect(statusService.listStatuses(testId)).toEqual([testStatus]);
statusService.setStatus(testId, testStatus, false);
expect(statusService.getStatus(testId)).toEqual([]);
expect(statusService.listStatuses(testId)).toEqual([]);
});
it("uses topic to listen for changes", function () {