diff --git a/platform/features/table/src/controllers/TelemetryTableController.js b/platform/features/table/src/controllers/TelemetryTableController.js index daf042893e..ea25ea6585 100644 --- a/platform/features/table/src/controllers/TelemetryTableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -72,7 +72,7 @@ define( * Create a new format object from legacy object, and replace it * when it changes */ - this.newObject = objectUtils.toNewFormat($scope.domainObject.getModel(), + this.domainObject = objectUtils.toNewFormat($scope.domainObject.getModel(), $scope.domainObject.getId()); _.bindAll(this, [ @@ -144,9 +144,9 @@ define( this.unobserveObject(); } - this.unobserveObject = this.openmct.objects.observe(this.newObject, "*", + this.unobserveObject = this.openmct.objects.observe(this.domainObject, "*", function (domainObject) { - this.newObject = domainObject; + this.domainObject = domainObject; this.getData(); }.bind(this) ); @@ -399,6 +399,42 @@ define( return objects; }; + /** + * Return an array of telemetry objects in this view that should be + * subscribed to. + * @private + * @returns {Promise} a promise that resolves with an array of + * telemetry objects in this view. + */ + TelemetryTableController.prototype.getTelemetryObjects = function () { + var telemetryApi = this.openmct.telemetry; + var compositionApi = this.openmct.composition; + + function filterForTelemetry(objects) { + return objects.filter(telemetryApi.canProvideTelemetry.bind(telemetryApi)); + } + + /* + * If parent object is a telemetry object, subscribe to it. Do not + * test composees. + */ + if (telemetryApi.canProvideTelemetry(this.domainObject)) { + return Promise.resolve([this.domainObject]); + } else { + /* + * If parent object is not a telemetry object, subscribe to all + * composees that are telemetry producing objects. + */ + var composition = compositionApi.get(this.domainObject); + + if (composition) { + return composition + .load() + .then(filterForTelemetry); + } + } + }; + /** * Request historical data, and subscribe to for real-time data. * @private @@ -406,10 +442,7 @@ define( * established, and historical telemetry is received and processed. */ TelemetryTableController.prototype.getData = function () { - var telemetryApi = this.openmct.telemetry; - var compositionApi = this.openmct.composition; var scope = this.$scope; - var newObject = this.newObject; this.telemetry.clear(); this.telemetry.bounds(this.openmct.conductor.bounds()); @@ -421,28 +454,9 @@ define( console.error(e.stack); } - function filterForTelemetry(objects) { - return objects.filter(telemetryApi.canProvideTelemetry.bind(telemetryApi)); - } - - function getDomainObjects() { - var objects = [newObject]; - var composition = compositionApi.get(newObject); - - if (composition) { - return composition - .load() - .then(function (children) { - return objects.concat(children); - }); - } else { - return Promise.resolve(objects); - } - } scope.rows = []; - return getDomainObjects() - .then(filterForTelemetry) + return this.getTelemetryObjects() .then(this.loadColumns) .then(this.subscribeToNewData) .then(this.getHistoricalData) diff --git a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js index b8c561ac96..f89f9dcec7 100644 --- a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js +++ b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js @@ -161,7 +161,7 @@ define( }); }); - describe ('Subscribes to new data', function () { + describe ('when getting telemetry', function () { var mockComposition, mockTelemetryObject, mockChildren, @@ -173,9 +173,7 @@ define( "load" ]); - mockTelemetryObject = jasmine.createSpyObj("mockTelemetryObject", [ - "something" - ]); + mockTelemetryObject = {}; mockTelemetryObject.identifier = { key: "mockTelemetryObject" }; @@ -192,22 +190,12 @@ define( }); done = false; - controller.getData().then(function () { - done = true; - }); - }); - - it('fetches historical data', function () { - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { - expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object)); - }); }); it('fetches historical data for the time period specified by the conductor bounds', function () { + controller.getData().then(function () { + done = true; + }); waitsFor(function () { return done; }, "getData to return", 100); @@ -217,17 +205,11 @@ define( }); }); - it('subscribes to new data', function () { - waitsFor(function () { - return done; - }, "getData to return", 100); - - runs(function () { - expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {}); + it('unsubscribes on view destruction', function () { + controller.getData().then(function () { + done = true; }); - }); - it('and unsubscribes on view destruction', function () { waitsFor(function () { return done; }, "getData to return", 100); @@ -239,6 +221,87 @@ define( expect(unsubscribe).toHaveBeenCalled(); }); }); + it('fetches historical data for the time period specified by the conductor bounds', function () { + controller.getData().then(function () { + done = true; + }); + waitsFor(function () { + return done; + }, "getData to return", 100); + + runs(function () { + expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds); + }); + }); + + it('fetches data for, and subscribes to parent object if it is a telemetry object', function () { + controller.getData().then(function () { + done = true; + }); + waitsFor(function () { + return done; + }, "getData to return", 100); + + runs(function () { + expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {}); + expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object)); + }); + }); + it('fetches data for, and subscribes to parent object if it is a telemetry object', function () { + controller.getData().then(function () { + done = true; + }); + waitsFor(function () { + return done; + }, "getData to return", 100); + + runs(function () { + expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {}); + expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object)); + }); + }); + + it('fetches data for, and subscribes to any composees that are telemetry objects if parent is not', function () { + mockChildren = [ + {name: "child 1"} + ]; + var mockTelemetryChildren = [ + {name: "child 2"}, + {name: "child 3"}, + {name: "child 4"} + ]; + mockChildren = mockChildren.concat(mockTelemetryChildren); + mockComposition.load.andReturn(Promise.resolve(mockChildren)); + + mockTelemetryAPI.canProvideTelemetry.andCallFake(function (object) { + if (object === mockTelemetryObject) { + return false; + } else { + return mockTelemetryChildren.indexOf(object) !== -1; + } + }); + + controller.getData().then(function () { + done = true; + }); + + waitsFor(function () { + return done; + }, "getData to return", 100); + + runs(function () { + mockTelemetryChildren.forEach(function (child) { + expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(child, jasmine.any(Function), {}); + }); + + mockTelemetryChildren.forEach(function (child) { + expect(mockTelemetryAPI.request).toHaveBeenCalledWith(child, jasmine.any(Object)); + }); + + expect(mockTelemetryAPI.subscribe).not.toHaveBeenCalledWith(mockChildren[0], jasmine.any(Function), {}); + expect(mockTelemetryAPI.subscribe).not.toHaveBeenCalledWith(mockTelemetryObject[0], jasmine.any(Function), {}); + }); + }); }); it('When in real-time mode, enables auto-scroll', function () {