From 4c6b3c7a133260a80cfc796173fad77085a5e4e3 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 09:56:59 -0700 Subject: [PATCH] [Events] Policy test correction The view policy test for real time Messages actually now works. #26. --- .../src/policies/RTMessagesViewPolicy.js | 3 +- .../test/policies/RTMessagesViewPolicySpec.js | 49 ++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/platform/features/rtevents/src/policies/RTMessagesViewPolicy.js b/platform/features/rtevents/src/policies/RTMessagesViewPolicy.js index 32daca6873..e3948e5a5c 100644 --- a/platform/features/rtevents/src/policies/RTMessagesViewPolicy.js +++ b/platform/features/rtevents/src/policies/RTMessagesViewPolicy.js @@ -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) { diff --git a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js index cd87f90807..c89770da63 100644 --- a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js +++ b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js @@ -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(); + }); + }); } ); \ No newline at end of file