From 6bbdfcdfbe416432b9fbf121c3f92a38a71ebb62 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 22 Nov 2017 11:05:03 -0800 Subject: [PATCH] [Table] Retain rows in scope (#1813) * [Table] Push rows in as they are added ...such that sorting does not cause real-time table rows to be lost. Fixes #1738 * [Table] Test adding rows * [Table] Fix code style in test https://github.com/nasa/openmct/pull/1813#pullrequestreview-78277635 --- .../controllers/TelemetryTableController.js | 3 +++ .../TelemetryTableControllerSpec.js | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/platform/features/table/src/controllers/TelemetryTableController.js b/platform/features/table/src/controllers/TelemetryTableController.js index a46cdf6f9c..4018d61dd9 100644 --- a/platform/features/table/src/controllers/TelemetryTableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -170,6 +170,9 @@ define( * @param rows */ TelemetryTableController.prototype.addRowsToTable = function (rows) { + rows.forEach(function (row) { + this.$scope.rows.push(row); + }, this); this.$scope.$broadcast('add:rows', rows); }; diff --git a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js index 68bee66734..b745081974 100644 --- a/platform/features/table/test/controllers/TelemetryTableControllerSpec.js +++ b/platform/features/table/test/controllers/TelemetryTableControllerSpec.js @@ -436,5 +436,28 @@ define( expect(mockScope.$broadcast).toHaveBeenCalledWith("remove:rows", discardedRows); }); + describe('when telemetry is added', function () { + var testRows; + var expectedRows; + + beforeEach(function () { + testRows = [{ a: 0 }, { a: 1 }, { a: 2 }]; + mockScope.rows = [{ a: -1 }]; + expectedRows = mockScope.rows.concat(testRows); + + spyOn(controller.telemetry, "on").andCallThrough(); + controller.registerChangeListeners(); + + controller.telemetry.on.calls.forEach(function (call) { + if (call.args[0] === 'added') { + call.args[1](testRows); + } + }); + }); + + it("adds it to rows in scope", function () { + expect(mockScope.rows).toEqual(expectedRows); + }); + }); }); });