[Events] Policy test correction

The view policy test for real time Messages
actually now works. #26.
This commit is contained in:
Sarah Hale 2015-06-29 09:56:59 -07:00
parent d120c8b139
commit 4c6b3c7a13
2 changed files with 27 additions and 25 deletions

View File

@ -30,7 +30,7 @@ define(
"use strict"; "use strict";
/** /**
* Policy controlling when the Messages view should be avaliable. * Policy controlling when the real time Messages view should be avaliable.
* @constructor * @constructor
*/ */
function RTMessagesViewPolicy() { function RTMessagesViewPolicy() {
@ -39,7 +39,6 @@ define(
var telemetry = domainObject && var telemetry = domainObject &&
domainObject.getCapability('telemetry'), domainObject.getCapability('telemetry'),
metadata = telemetry ? telemetry.getMetadata() : {}, metadata = telemetry ? telemetry.getMetadata() : {},
data = telemetry ? telemetry.requestData() : {},
ranges = metadata.ranges || []; ranges = metadata.ranges || [];
return ranges.some(function (range) { return ranges.some(function (range) {

View File

@ -29,51 +29,54 @@ define(
function (RTMessagesViewPolicy) { function (RTMessagesViewPolicy) {
"use strict"; "use strict";
describe("The real time messages view policy", function () { describe("The real time Messages view policy", function () {
var mockDomainObject, var testView,
mockDomainObject,
mockTelemetry, mockTelemetry,
telemetryType,
testType,
testView,
testMetadata, testMetadata,
policy; policy;
beforeEach(function () { beforeEach(function () {
testMetadata = {ranges}; testView = { key: "rtmessages" };
testMetadata = {};
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
'domainObject', 'domainObject',
['getModel', 'getCapability'] ['getId', 'getModel', 'getCapability']
); );
mockTelemetry = jasmine.createSpyObj( mockTelemetry = jasmine.createSpyObj(
'telemetry', 'telemetry',
['getMetadata'] ['getMetadata']
); );
mockDomainObject.getModel.andCallFake(function (c) {
return {type: testType};
});
mockDomainObject.getCapability.andCallFake(function (c) { mockDomainObject.getCapability.andCallFake(function (c) {
return c === 'telemetry' ? mockTelemetry : undefined; return c === 'telemetry' ? mockTelemetry : undefined;
}); });
mockTelemetry.getMetadata = testMetadata; mockTelemetry.getMetadata.andReturn(testMetadata);
policy = new RTMessagesViewPolicy(); policy = new RTMessagesViewPolicy();
}); });
it("disallows the message view for objects without string telemetry", function () { it("allows the real time messages view for domain objects with string telemetry", function () {
testMetadata.ranges = [ { format: 'notString' } ]; testMetadata.ranges = [ { key: "foo", format: "string" } ];
expect(policy.allow({ key: 'messages' }, mockDomainObject)).toBeFalsy(); expect(policy.allow(testView, mockDomainObject)).toBeTruthy();
}); });
it("allows the message view for objects with string telemetry", function () { it("disallows the real time messages view for domain objects without string telemetry", function () {
testMetadata.ranges = [ { format: 'string' } ]; testMetadata.ranges = [ { key: "foo", format: "somethingElse" } ];
expect(policy.allow({ key: 'messages' }, mockDomainObject)).toBeTruthy(); expect(policy.allow(testView, mockDomainObject)).toBeFalsy();
}); });
it("returns true when the current view is not the Messages view", function () { it("disallows the real time messages view for domain objects without telemetry", function () {
expect(policy.allow({ key: 'notMessages' }, mockDomainObject)).toBeTruthy(); testMetadata.ranges = [ { key: "foo", format: "string" } ];
mockDomainObject.getCapability.andReturn(undefined);
expect(policy.allow(testView, mockDomainObject)).toBeFalsy();
}); });
it("allows other views", function () {
testView.key = "somethingElse";
testMetadata.ranges = [ { key: "foo", format: "somethingElse" } ];
expect(policy.allow(testView, mockDomainObject)).toBeTruthy();
});
}); });
} }
); );