[Status] Test platform/status

This commit is contained in:
Victor Woeltjen
2015-11-19 14:22:44 -08:00
parent 3ffa6f70aa
commit 5b9e43f8ff
6 changed files with 234 additions and 8 deletions

View File

@@ -27,6 +27,58 @@ define(
"use strict";
describe("The status capability", function () {
var mockStatusService,
mockDomainObject,
mockUnlisten,
testId,
testStatusFlags,
capability;
beforeEach(function () {
testId = "some-id";
testStatusFlags = [ 'a', 'b', 'c' ];
mockStatusService = jasmine.createSpyObj(
'statusService',
[ 'listen', 'setStatus', 'getStatus' ]
);
mockDomainObject = jasmine.createSpyObj(
'domainObject',
[ 'getId', 'getCapability', 'getModel' ]
);
mockUnlisten = jasmine.createSpy('unlisten');
mockStatusService.listen.andReturn(mockUnlisten);
mockStatusService.getStatus.andReturn(testStatusFlags);
mockDomainObject.getId.andReturn(testId);
capability = new StatusCapability(
mockStatusService,
mockDomainObject
);
});
it("sets status with the statusService", function () {
var testStatus = "some-test-status";
capability.set(testStatus, true);
expect(mockStatusService.setStatus)
.toHaveBeenCalledWith(testId, testStatus, true);
capability.set(testStatus, false);
expect(mockStatusService.setStatus)
.toHaveBeenCalledWith(testId, testStatus, false);
});
it("gets status from the statusService", function () {
expect(capability.get()).toBe(testStatusFlags);
});
it("listens to changes from the statusService", function () {
var mockCallback = jasmine.createSpy();
expect(capability.listen(mockCallback))
.toBe(mockUnlisten);
expect(mockStatusService.listen)
.toHaveBeenCalledWith(testId, mockCallback);
});
});
}
);