diff --git a/platform/status/src/StatusCapability.js b/platform/status/src/StatusCapability.js index 2751c198a9..6b0221d188 100644 --- a/platform/status/src/StatusCapability.js +++ b/platform/status/src/StatusCapability.js @@ -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; }; /** diff --git a/platform/status/src/StatusRepresenter.js b/platform/status/src/StatusRepresenter.js index 0808688c02..550fec3e6d 100644 --- a/platform/status/src/StatusRepresenter.js +++ b/platform/status/src/StatusRepresenter.js @@ -77,7 +77,7 @@ define( self.lastClasses = newClasses; } - updateStatus(statusCapability.get()); + updateStatus(statusCapability.list()); this.unlisten = statusCapability.listen(updateStatus); }; diff --git a/platform/status/src/StatusService.js b/platform/status/src/StatusService.js index 6fff6f49d8..d75e935429 100644 --- a/platform/status/src/StatusService.js +++ b/platform/status/src/StatusService.js @@ -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] || []; }; diff --git a/platform/status/test/StatusCapabilitySpec.js b/platform/status/test/StatusCapabilitySpec.js index 481abf6a53..1bd3326c4e 100644 --- a/platform/status/test/StatusCapabilitySpec.js +++ b/platform/status/test/StatusCapabilitySpec.js @@ -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); + }); }); } ); diff --git a/platform/status/test/StatusRepresenterSpec.js b/platform/status/test/StatusRepresenterSpec.js index e9191587a7..1d305ea983 100644 --- a/platform/status/test/StatusRepresenterSpec.js +++ b/platform/status/test/StatusRepresenterSpec.js @@ -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) { diff --git a/platform/status/test/StatusServiceSpec.js b/platform/status/test/StatusServiceSpec.js index 1f85cd70a1..c064af6bc8 100644 --- a/platform/status/test/StatusServiceSpec.js +++ b/platform/status/test/StatusServiceSpec.js @@ -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 () {