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

View File

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