From 750d3f473e6d0aa25f95a620bf9100bfc2f3cb46 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 25 Jun 2015 15:04:53 -0700 Subject: [PATCH 01/10] [Events] Starting tests Starting to write tests for the real time messages view. #26. --- bundles.json | 1 + .../rtevents/test/DomainColumnSpec.js | 84 +++++++++++++ .../test/RTEventListControllerSpec.js | 110 ++++++++++++++++++ .../features/rtevents/test/RangeColumnSpec.js | 81 +++++++++++++ .../test/policies/RTMessagesViewPolicySpec.js | 81 +++++++++++++ platform/features/rtevents/test/suite.js | 6 + 6 files changed, 363 insertions(+) diff --git a/bundles.json b/bundles.json index f69e127eec..ed59299d16 100644 --- a/bundles.json +++ b/bundles.json @@ -17,6 +17,7 @@ "platform/features/plot", "platform/features/scrolling", "platform/features/events", + "platform/features/rtevents", "platform/forms", "platform/persistence/queue", "platform/policy", diff --git a/platform/features/rtevents/test/DomainColumnSpec.js b/platform/features/rtevents/test/DomainColumnSpec.js index e69de29bb2..9ede34d02c 100644 --- a/platform/features/rtevents/test/DomainColumnSpec.js +++ b/platform/features/rtevents/test/DomainColumnSpec.js @@ -0,0 +1,84 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +/** + * RTEventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/25/2015. + */ +define( + ["../src/DomainColumn"], + function (DomainColumn) { + "use strict"; + + var TEST_DOMAIN_VALUE = "some formatted domain value"; + + describe("A real time event list domain column", function () { + var mockDataSet, + testMetadata, + mockFormatter, + column; + + beforeEach(function () { + mockDataSet = jasmine.createSpyObj( + "data", + [ "getDomainValue" ] + ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); + testMetadata = { + key: "testKey", + name: "Test Name" + }; + mockFormatter.formatDomainValue.andReturn(TEST_DOMAIN_VALUE); + + column = new DomainColumn(testMetadata, mockFormatter); + }); + + it("reports a column header from domain metadata", function () { + expect(column.getTitle()).toEqual("Test Name"); + }); + + it("looks up data from a data set", function () { + column.getValue(undefined, mockDataSet, 42); + expect(mockDataSet.getDomainValue) + .toHaveBeenCalledWith(42, "testKey"); + }); + + it("formats domain values as time", function () { + mockDataSet.getDomainValue.andReturn(402513731000); + + // Should have just given the value the formatter gave + expect(column.getValue(undefined, mockDataSet, 42)) + .toEqual(TEST_DOMAIN_VALUE); + + // Make sure that service interactions were as expected + expect(mockFormatter.formatDomainValue) + .toHaveBeenCalledWith(402513731000); + expect(mockFormatter.formatRangeValue) + .not.toHaveBeenCalled(); + }); + + }); + } +); \ No newline at end of file diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index e69de29bb2..a2a72a4a75 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -0,0 +1,110 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +/** + * RTEventSpec. Created by shale on 06/25/2015. + */ +define( + ["../src/RTEventListController"], + function (RTEventListController) { + "use strict"; + + describe("The real time event list controller", function () { + var mockScope, + mockTelemetry, + testMetadata, + controller; + + beforeEach(function () { + mockScope = jasmine.createSpyObj( + "$scope", + [ "$on", "$watch" ] + ); + mockTelemetry = jasmine.createSpyObj( + "telemetryController", + [ "getResponse", "getMetadata", "getTelemetryObjects" ] + ); + testMetadata = [ + { + domains: [ + { key: "d0", name: "D0" }, + { key: "d1", name: "D1" } + ], + ranges: [ + { key: "r0", name: "R0" }, + { key: "r1", name: "R1" } + ] + }, + { + domains: [ + { key: "d0", name: "D0" }, + { key: "d2", name: "D2" } + ], + ranges: [ + { key: "r0", name: "R0" } + ] + } + ]; + mockTelemetry.getMetadata.andReturn(testMetadata); + mockTelemetry.getResponse.andReturn([]); + mockTelemetry.getTelemetryObjects.andReturn([]); + mockScope.telemetry = mockTelemetry; + controller = new RTEventListController(mockScope); + }); + + it("listens for telemetry data updates", function () { + expect(mockScope.$on).toHaveBeenCalledWith( + "telemetryUpdate", + jasmine.any(Function) + ); + }); + + it("watches for telemetry controller changes", function () { + expect(mockScope.$watch).toHaveBeenCalledWith( + "telemetry", + jasmine.any(Function) + ); + }); + + it("provides a column for each unique domain and range", function () { + // Should have five columns based on metadata above, + // (d0, d1, d2, r0, r1) + mockScope.$watch.mostRecentCall.args[1](mockTelemetry); + expect(mockScope.headers).toEqual(["D0", "D1", "D2", "R0", "R1"]); + }); + + it("does not throw if telemetry controller is undefined", function () { + // Just a general robustness check + mockScope.telemetry = undefined; + expect(mockScope.$watch.mostRecentCall.args[1]) + .not.toThrow(); + }); + + it("provides default columns if domain/range metadata is unavailable", function () { + mockTelemetry.getMetadata.andReturn([]); + mockScope.$watch.mostRecentCall.args[1](mockTelemetry); + expect(mockScope.headers).toEqual(["Time", "Message"]); + }); + }); + } +); \ No newline at end of file diff --git a/platform/features/rtevents/test/RangeColumnSpec.js b/platform/features/rtevents/test/RangeColumnSpec.js index e69de29bb2..59d559a988 100644 --- a/platform/features/rtevents/test/RangeColumnSpec.js +++ b/platform/features/rtevents/test/RangeColumnSpec.js @@ -0,0 +1,81 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +/** + * RTEventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/25/2015. + */ +define( + ["../src/RangeColumn"], + function (RangeColumn) { + "use strict"; + + var TEST_RANGE_VALUE = "some formatted range value"; + + describe("A real time event list range column", function () { + var mockDataSet, + testMetadata, + mockFormatter, + column; + + beforeEach(function () { + mockDataSet = jasmine.createSpyObj( + "data", + [ "getRangeValue" ] + ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); + testMetadata = { + key: "testKey", + name: "Test Name" + }; + mockFormatter.formatRangeValue.andReturn(TEST_RANGE_VALUE); + + column = new RangeColumn(testMetadata, mockFormatter); + }); + + it("reports a column header from range metadata", function () { + expect(column.getTitle()).toEqual("Test Name"); + }); + + it("looks up data from a data set", function () { + column.getValue(undefined, mockDataSet, 42); + expect(mockDataSet.getRangeValue) + .toHaveBeenCalledWith(42, "testKey"); + }); + + it("formats range values as time", function () { + mockDataSet.getRangeValue.andReturn(123.45678); + expect(column.getValue(undefined, mockDataSet, 42)) + .toEqual(TEST_RANGE_VALUE); + + // Make sure that service interactions were as expected + expect(mockFormatter.formatRangeValue) + .toHaveBeenCalledWith(123.45678); + expect(mockFormatter.formatDomainValue) + .not.toHaveBeenCalled(); + }); + }); + } +); \ No newline at end of file diff --git a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js index e69de29bb2..7e976b015b 100644 --- a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js +++ b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js @@ -0,0 +1,81 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +/** + * RTEventSpec. Created by shale on 06/25/2015. + */ +define( + ["../../src/policies/RTMessagesViewPolicy"], + function (RTMessagesViewPolicy) { + "use strict"; + + describe("The real time messages view policy", function () { + var mockDomainObject, + mockTelemetry, + telemetryType, + testType, + testView, + testMetadata, + policy; + + beforeEach(function () { + + testView = { key: "string" }; + testMetadata = {}; + + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + ['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.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 message view for objects with string telemetry", function () { + testMetadata.ranges = [ { format: 'string' } ]; + expect(policy.allow({ key: 'messages' }, mockDomainObject)).toBeTruthy(); + }); + + it("returns true when the current view is not the Messages view", function () { + expect(policy.allow({ key: 'notMessages' }, mockDomainObject)).toBeTruthy(); + }); + }); + } +); \ No newline at end of file diff --git a/platform/features/rtevents/test/suite.js b/platform/features/rtevents/test/suite.js index e69de29bb2..8ee31624a6 100644 --- a/platform/features/rtevents/test/suite.js +++ b/platform/features/rtevents/test/suite.js @@ -0,0 +1,6 @@ +[ + "DomainColumn", + "RTEventListController", + "policies/RTMessagesViewPolicy", + "RangeColumn" +] \ No newline at end of file From 95f9d783d354124064dd6a45e058db068795b453 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Fri, 26 Jun 2015 14:23:41 -0700 Subject: [PATCH 02/10] [Events] Column tests working Tests for the domain and range columns now work for the real time event list. #26. --- .../rtevents/test/DomainColumnSpec.js | 44 +++++++------- .../test/RTEventListControllerSpec.js | 24 +++++++- .../features/rtevents/test/RangeColumnSpec.js | 57 ++++++++++--------- platform/features/rtevents/test/suite.js | 6 -- platform/features/rtevents/test/suite.json | 6 ++ 5 files changed, 83 insertions(+), 54 deletions(-) delete mode 100644 platform/features/rtevents/test/suite.js create mode 100644 platform/features/rtevents/test/suite.json diff --git a/platform/features/rtevents/test/DomainColumnSpec.js b/platform/features/rtevents/test/DomainColumnSpec.js index 9ede34d02c..b40a5e0331 100644 --- a/platform/features/rtevents/test/DomainColumnSpec.js +++ b/platform/features/rtevents/test/DomainColumnSpec.js @@ -32,44 +32,48 @@ define( var TEST_DOMAIN_VALUE = "some formatted domain value"; describe("A real time event list domain column", function () { - var mockDataSet, - testMetadata, + var mockDomainObject, + mockTelemetryHandler, + mockHandle, mockFormatter, column; beforeEach(function () { - mockDataSet = jasmine.createSpyObj( - "data", - [ "getDomainValue" ] + mockDomainObject = jasmine.createSpyObj( + "domainObject", + ["getModel", "getCapability"] + ); + mockTelemetryHandler = jasmine.createSpyObj( + "telemetryHandler", + ["handle"] + ); + mockHandle = jasmine.createSpyObj( + "handle", + ["getDomainValue", "getRangeValue"] ); mockFormatter = jasmine.createSpyObj( "formatter", - [ "formatDomainValue", "formatRangeValue" ] + ["formatDomainValue", "formatRangeValue"] ); - testMetadata = { - key: "testKey", - name: "Test Name" - }; mockFormatter.formatDomainValue.andReturn(TEST_DOMAIN_VALUE); - - column = new DomainColumn(testMetadata, mockFormatter); + + column = new DomainColumn(mockFormatter); }); - it("reports a column header from domain metadata", function () { - expect(column.getTitle()).toEqual("Test Name"); + it("reports the domain column header as 'Time'", function () { + expect(column.getTitle()).toEqual("Time"); }); - it("looks up data from a data set", function () { - column.getValue(undefined, mockDataSet, 42); - expect(mockDataSet.getDomainValue) - .toHaveBeenCalledWith(42, "testKey"); + it("retrives data from a telemetry provider", function () { + column.getValue(mockDomainObject, mockHandle); + expect(mockHandle.getDomainValue).toHaveBeenCalled(); }); it("formats domain values as time", function () { - mockDataSet.getDomainValue.andReturn(402513731000); + mockHandle.getDomainValue.andReturn(402513731000); // Should have just given the value the formatter gave - expect(column.getValue(undefined, mockDataSet, 42)) + expect(column.getValue(mockDomainObject, mockHandle).text) .toEqual(TEST_DOMAIN_VALUE); // Make sure that service interactions were as expected diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index a2a72a4a75..6ed2b553f5 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -32,8 +32,18 @@ define( describe("The real time event list controller", function () { var mockScope, mockTelemetry, + mockTelemetryHandler, + mockHandle, + mockTelemetryFormatter, testMetadata, controller; +/* + var mockDomainObject, + mockTelemetryHandler, + mockHandle, + mockFormatter, + column; +*/ beforeEach(function () { mockScope = jasmine.createSpyObj( @@ -44,6 +54,18 @@ define( "telemetryController", [ "getResponse", "getMetadata", "getTelemetryObjects" ] ); + mockTelemetryHandler = jasmine.createSpyObj( + "telemetryHandler", + ["handle"] + ); + mockHandle = jasmine.createSpyObj( + "handle", + ["getDomainValue", "getRangeValue"] + ); + mockTelemetryFormatter = jasmine.createSpyObj( + "formatter", + ["formatDomainValue", "formatRangeValue"] + ); testMetadata = [ { domains: [ @@ -69,7 +91,7 @@ define( mockTelemetry.getResponse.andReturn([]); mockTelemetry.getTelemetryObjects.andReturn([]); mockScope.telemetry = mockTelemetry; - controller = new RTEventListController(mockScope); + controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter); }); it("listens for telemetry data updates", function () { diff --git a/platform/features/rtevents/test/RangeColumnSpec.js b/platform/features/rtevents/test/RangeColumnSpec.js index 59d559a988..fa196618f0 100644 --- a/platform/features/rtevents/test/RangeColumnSpec.js +++ b/platform/features/rtevents/test/RangeColumnSpec.js @@ -32,49 +32,52 @@ define( var TEST_RANGE_VALUE = "some formatted range value"; describe("A real time event list range column", function () { - var mockDataSet, - testMetadata, + var mockDomainObject, + mockTelemetryHandler, + mockHandle, mockFormatter, column; beforeEach(function () { - mockDataSet = jasmine.createSpyObj( - "data", - [ "getRangeValue" ] + mockDomainObject = jasmine.createSpyObj( + "domainObject", + ["getModel", "getCapability"] + ); + mockTelemetryHandler = jasmine.createSpyObj( + "telemetryHandler", + ["handle"] + ); + mockHandle = jasmine.createSpyObj( + "handle", + ["getDomainValue", "getRangeValue"] ); mockFormatter = jasmine.createSpyObj( "formatter", - [ "formatDomainValue", "formatRangeValue" ] + ["formatDomainValue", "formatRangeValue"] ); - testMetadata = { - key: "testKey", - name: "Test Name" - }; mockFormatter.formatRangeValue.andReturn(TEST_RANGE_VALUE); - column = new RangeColumn(testMetadata, mockFormatter); + column = new RangeColumn(); }); - it("reports a column header from range metadata", function () { - expect(column.getTitle()).toEqual("Test Name"); + it("reports a range column header as 'Message'", function () { + expect(column.getTitle()).toEqual("Message"); }); - it("looks up data from a data set", function () { - column.getValue(undefined, mockDataSet, 42); - expect(mockDataSet.getRangeValue) - .toHaveBeenCalledWith(42, "testKey"); + it("retrives data from a telemetry provider", function () { + column.getValue(mockDomainObject, mockHandle); + expect(mockHandle.getRangeValue).toHaveBeenCalled(); }); - it("formats range values as time", function () { - mockDataSet.getRangeValue.andReturn(123.45678); - expect(column.getValue(undefined, mockDataSet, 42)) - .toEqual(TEST_RANGE_VALUE); - - // Make sure that service interactions were as expected - expect(mockFormatter.formatRangeValue) - .toHaveBeenCalledWith(123.45678); - expect(mockFormatter.formatDomainValue) - .not.toHaveBeenCalled(); + it("does not format range values", function () { + mockHandle.getRangeValue.andReturn(123.45678); + // Does not format range value as time + expect(column.getValue(mockDomainObject, mockHandle).text) + .not.toEqual(TEST_RANGE_VALUE); + // There should be no additional formatting + // i.e. the message string stays a string + expect(column.getValue(mockDomainObject, mockHandle).text) + .toEqual(123.45678); }); }); } diff --git a/platform/features/rtevents/test/suite.js b/platform/features/rtevents/test/suite.js deleted file mode 100644 index 8ee31624a6..0000000000 --- a/platform/features/rtevents/test/suite.js +++ /dev/null @@ -1,6 +0,0 @@ -[ - "DomainColumn", - "RTEventListController", - "policies/RTMessagesViewPolicy", - "RangeColumn" -] \ No newline at end of file diff --git a/platform/features/rtevents/test/suite.json b/platform/features/rtevents/test/suite.json new file mode 100644 index 0000000000..bbc59b1738 --- /dev/null +++ b/platform/features/rtevents/test/suite.json @@ -0,0 +1,6 @@ +[ + "DomainColumn", + "RangeColumn", + "RTEventListController", + "policies/RTMessagesViewPolicy" +] \ No newline at end of file From 41e75d74948ca835c68ffc38b68fcadf29b68e7f Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Fri, 26 Jun 2015 14:59:04 -0700 Subject: [PATCH 03/10] [Events] EventListController test Test for the Event List controller now works. #26. --- .../test/RTEventListControllerSpec.js | 64 ++++--------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index 6ed2b553f5..693d0ffc98 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -31,29 +31,17 @@ define( describe("The real time event list controller", function () { var mockScope, - mockTelemetry, + //mockTelemetry, mockTelemetryHandler, mockHandle, mockTelemetryFormatter, - testMetadata, controller; -/* - var mockDomainObject, - mockTelemetryHandler, - mockHandle, - mockFormatter, - column; -*/ beforeEach(function () { mockScope = jasmine.createSpyObj( "$scope", [ "$on", "$watch" ] ); - mockTelemetry = jasmine.createSpyObj( - "telemetryController", - [ "getResponse", "getMetadata", "getTelemetryObjects" ] - ); mockTelemetryHandler = jasmine.createSpyObj( "telemetryHandler", ["handle"] @@ -66,32 +54,13 @@ define( "formatter", ["formatDomainValue", "formatRangeValue"] ); - testMetadata = [ - { - domains: [ - { key: "d0", name: "D0" }, - { key: "d1", name: "D1" } - ], - ranges: [ - { key: "r0", name: "R0" }, - { key: "r1", name: "R1" } - ] - }, - { - domains: [ - { key: "d0", name: "D0" }, - { key: "d2", name: "D2" } - ], - ranges: [ - { key: "r0", name: "R0" } - ] - } - ]; - mockTelemetry.getMetadata.andReturn(testMetadata); - mockTelemetry.getResponse.andReturn([]); - mockTelemetry.getTelemetryObjects.andReturn([]); - mockScope.telemetry = mockTelemetry; + controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter); + + // Add some data into the table + controller.setUpColumns([{id: 'a'}, {id: 'b'}]); + } + }); it("listens for telemetry data updates", function () { @@ -107,12 +76,13 @@ define( jasmine.any(Function) ); }); - - it("provides a column for each unique domain and range", function () { - // Should have five columns based on metadata above, - // (d0, d1, d2, r0, r1) - mockScope.$watch.mostRecentCall.args[1](mockTelemetry); - expect(mockScope.headers).toEqual(["D0", "D1", "D2", "R0", "R1"]); + + it("provides a domain and a range column", function () { + // Should have two columns + expect(controller.rows()[0].length).toEqual([]); + + // And they should have these headers + expect(controller.headers()).toEqual(["Time", "Message"]); }); it("does not throw if telemetry controller is undefined", function () { @@ -121,12 +91,6 @@ define( expect(mockScope.$watch.mostRecentCall.args[1]) .not.toThrow(); }); - - it("provides default columns if domain/range metadata is unavailable", function () { - mockTelemetry.getMetadata.andReturn([]); - mockScope.$watch.mostRecentCall.args[1](mockTelemetry); - expect(mockScope.headers).toEqual(["Time", "Message"]); - }); }); } ); \ No newline at end of file From 4e03d7b29bf45d62a2ba87c428d2f0d7112ec544 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Fri, 26 Jun 2015 15:17:17 -0700 Subject: [PATCH 04/10] [Events] RT Messages policy test The view policy test for real time Messages now works. #26. --- .../rtevents/test/policies/RTMessagesViewPolicySpec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js index 7e976b015b..cd87f90807 100644 --- a/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js +++ b/platform/features/rtevents/test/policies/RTMessagesViewPolicySpec.js @@ -39,9 +39,7 @@ define( policy; beforeEach(function () { - - testView = { key: "string" }; - testMetadata = {}; + testMetadata = {ranges}; mockDomainObject = jasmine.createSpyObj( 'domainObject', @@ -58,7 +56,7 @@ define( mockDomainObject.getCapability.andCallFake(function (c) { return c === 'telemetry' ? mockTelemetry : undefined; }); - mockTelemetry.getMetadata.andReturn(testMetadata); + mockTelemetry.getMetadata = testMetadata; policy = new RTMessagesViewPolicy(); }); From 4c6b3c7a133260a80cfc796173fad77085a5e4e3 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 09:56:59 -0700 Subject: [PATCH 05/10] [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 From 6616dedf63ccc531634234c5f3238255333dacdb Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 13:09:00 -0700 Subject: [PATCH 06/10] [Events] Controller test correction Test for the RT Event List controller now actually works. #26. --- .../rtevents/src/RTEventListController.js | 2 +- .../test/RTEventListControllerSpec.js | 94 +++++++++++++------ 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/platform/features/rtevents/src/RTEventListController.js b/platform/features/rtevents/src/RTEventListController.js index 618d6eede9..563dcee2ce 100644 --- a/platform/features/rtevents/src/RTEventListController.js +++ b/platform/features/rtevents/src/RTEventListController.js @@ -65,7 +65,7 @@ define( columns = []; - columns.push(new DomainColumn(telemetryFormatter)); + columns.push(new DomainColumn(telemetryFormatter, telemetryHandler.getMetadata())); columns.push(new RangeColumn()); headers = columns.map(function (column) { diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index 693d0ffc98..ec92306455 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -30,14 +30,19 @@ define( "use strict"; describe("The real time event list controller", function () { - var mockScope, - //mockTelemetry, + var mockDomainObject, + mockScope, mockTelemetryHandler, mockHandle, mockTelemetryFormatter, + mockColumn, controller; - + beforeEach(function () { + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel", "getCapability" ] + ); mockScope = jasmine.createSpyObj( "$scope", [ "$on", "$watch" ] @@ -48,48 +53,83 @@ define( ); mockHandle = jasmine.createSpyObj( "handle", - ["getDomainValue", "getRangeValue"] + ["getDomainValue", "getRangeValue", "getTelemetryObjects", "unsubscribe"] ); mockTelemetryFormatter = jasmine.createSpyObj( "formatter", ["formatDomainValue", "formatRangeValue"] ); + mockColumn = jasmine.createSpyObj( + "column", + ["getValue"] + ); controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter); - // Add some data into the table - controller.setUpColumns([{id: 'a'}, {id: 'b'}]); - } + mockHandle.getDomainValue.andReturn("domain value"); + mockHandle.getRangeValue.andReturn("range value"); + mockTelemetryHandler.handle.andReturn(mockHandle); + mockHandle.getTelemetryObjects.andReturn([mockDomainObject]); + + // Subscribe to the RT telemetry + // second argument of: $scope.$watch("domainObject", makeSubscription); + ////// TODO: Maybe use some instead of forEach? + mockScope.$watch.calls.forEach(function (c) { + // There are two possible calls of $watch, so we need to filter + // through the calls to get the correct kind + if (c.args[0] === 'domainObject') { + c.args[1](); + } + }); + + // callback, passed into telemetry handler + mockTelemetryHandler.handle.mostRecentCall.args[1](); + + // Update the telemetry objects + // second argument of: $scope.$watch(getTelemetryObjects, updateObjects); + mockScope.$watch.calls.forEach(function (c) { + // There are two possible calls of $watch, so we need to filter + // through the calls to get the correct kind + if (c.args[0] !== 'domainObject') { + c.args[1]([mockDomainObject]); + } + }); + + }); + + it("provides a domain and a range column", function () { + // Should have two columns with these headers + expect(controller.headers()).toEqual(["Time", "Message"]); }); it("listens for telemetry data updates", function () { - expect(mockScope.$on).toHaveBeenCalledWith( - "telemetryUpdate", - jasmine.any(Function) - ); - }); - - it("watches for telemetry controller changes", function () { + // Of the two possible $watch calls, this corresponds to + // $scope.$watch(getTelemetryObjects, updateObjects); expect(mockScope.$watch).toHaveBeenCalledWith( - "telemetry", + jasmine.any(Function), jasmine.any(Function) ); }); - it("provides a domain and a range column", function () { - // Should have two columns - expect(controller.rows()[0].length).toEqual([]); - - // And they should have these headers - expect(controller.headers()).toEqual(["Time", "Message"]); + it("makes telemetry subscriptions", function () { + // Of the two possible $watch calls, this corresponds to + // $scope.$watch("domainObject", makeSubscription); + expect(mockScope.$watch).toHaveBeenCalledWith( + "domainObject", + jasmine.any(Function) + ); }); - - it("does not throw if telemetry controller is undefined", function () { - // Just a general robustness check - mockScope.telemetry = undefined; - expect(mockScope.$watch.mostRecentCall.args[1]) - .not.toThrow(); + + it("releases telemetry subscriptions on destruction", function () { + // Call the second argument of + // $scope.$on("$destroy", releaseSubscription); + mockScope.$on.mostRecentCall.args[1](); + + expect(mockScope.$on).toHaveBeenCalledWith( + "$destroy", + jasmine.any(Function) + ); }); }); } From 14694c675b654747218734a0bb0c532e8bb57fb4 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 13:13:05 -0700 Subject: [PATCH 07/10] [Events] All tests work All of the tests for the RT Events are working. #26. --- platform/features/rtevents/src/DomainColumn.js | 2 ++ platform/features/rtevents/src/RTEventListController.js | 4 ++-- platform/features/rtevents/src/RangeColumn.js | 2 +- platform/features/rtevents/test/suite.json | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/platform/features/rtevents/src/DomainColumn.js b/platform/features/rtevents/src/DomainColumn.js index c4f8a2a143..43279a42d7 100644 --- a/platform/features/rtevents/src/DomainColumn.js +++ b/platform/features/rtevents/src/DomainColumn.js @@ -47,6 +47,8 @@ define( * @returns {string} the title to display */ getTitle: function () { + // At the moment there does not appear to be a way to get the + // column's title through metadata for real time telemetry return "Time"; }, /** diff --git a/platform/features/rtevents/src/RTEventListController.js b/platform/features/rtevents/src/RTEventListController.js index 563dcee2ce..bed335c6cd 100644 --- a/platform/features/rtevents/src/RTEventListController.js +++ b/platform/features/rtevents/src/RTEventListController.js @@ -46,6 +46,7 @@ define( rows = []; function getTelemetryObjects() { + //console.log("handle.getTelemetryObjects() ", handle.getTelemetryObjects()); return handle ? handle.getTelemetryObjects() : []; } @@ -65,7 +66,7 @@ define( columns = []; - columns.push(new DomainColumn(telemetryFormatter, telemetryHandler.getMetadata())); + columns.push(new DomainColumn(telemetryFormatter)); columns.push(new RangeColumn()); headers = columns.map(function (column) { @@ -92,7 +93,6 @@ define( return column.getValue(telemetryObject, handle).text; })); // Remove first rows when adding past the max rows limit - //rows.splice(ROW_COUNT, Number.MAX_VALUE); rows.splice(0, rows.length - ROW_COUNT); lastUpdated[id] = domainValue; } diff --git a/platform/features/rtevents/src/RangeColumn.js b/platform/features/rtevents/src/RangeColumn.js index 8fcf747b25..68147062b5 100644 --- a/platform/features/rtevents/src/RangeColumn.js +++ b/platform/features/rtevents/src/RangeColumn.js @@ -32,7 +32,7 @@ define( /** * A column which will report telemetry range values - * (typically, measurements.) Used by the RTScrollingListController. + * (typically, measurements.) Used by the RTEventListController. * * @constructor * @param rangeMetadata an object with the machine- and human- diff --git a/platform/features/rtevents/test/suite.json b/platform/features/rtevents/test/suite.json index bbc59b1738..996a8ce906 100644 --- a/platform/features/rtevents/test/suite.json +++ b/platform/features/rtevents/test/suite.json @@ -1,6 +1,6 @@ [ "DomainColumn", + "policies/RTMessagesViewPolicy", "RangeColumn", - "RTEventListController", - "policies/RTMessagesViewPolicy" + "RTEventListController" ] \ No newline at end of file From b91b197f5bc46e425c9d1ffa6c41d86030fa3855 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 13:14:51 -0700 Subject: [PATCH 08/10] [Events] Comments Removed todo comment. #26. --- platform/features/rtevents/test/RTEventListControllerSpec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index ec92306455..8de06820ef 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -74,7 +74,6 @@ define( // Subscribe to the RT telemetry // second argument of: $scope.$watch("domainObject", makeSubscription); - ////// TODO: Maybe use some instead of forEach? mockScope.$watch.calls.forEach(function (c) { // There are two possible calls of $watch, so we need to filter // through the calls to get the correct kind From f816b5018a9c8d5e0b93c32c7d85f25744bbaef4 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 13:15:56 -0700 Subject: [PATCH 09/10] [Events] Style Removed unused variables. #26. --- platform/features/rtevents/test/RTEventListControllerSpec.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/platform/features/rtevents/test/RTEventListControllerSpec.js b/platform/features/rtevents/test/RTEventListControllerSpec.js index 8de06820ef..a614d38e21 100644 --- a/platform/features/rtevents/test/RTEventListControllerSpec.js +++ b/platform/features/rtevents/test/RTEventListControllerSpec.js @@ -35,7 +35,6 @@ define( mockTelemetryHandler, mockHandle, mockTelemetryFormatter, - mockColumn, controller; beforeEach(function () { @@ -59,10 +58,6 @@ define( "formatter", ["formatDomainValue", "formatRangeValue"] ); - mockColumn = jasmine.createSpyObj( - "column", - ["getValue"] - ); controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter); From a8fdbdc98b6d3970124cce121addb4c8c1b04fb2 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Mon, 29 Jun 2015 14:42:54 -0700 Subject: [PATCH 10/10] [Events] Changed bundles.json Changed bundles.json so that rtevents are not included by default. #26. --- bundles.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles.json b/bundles.json index ed59299d16..f69e127eec 100644 --- a/bundles.json +++ b/bundles.json @@ -17,7 +17,6 @@ "platform/features/plot", "platform/features/scrolling", "platform/features/events", - "platform/features/rtevents", "platform/forms", "platform/persistence/queue", "platform/policy",