From 7cc008ed0104bd02717db87b46b2d9235f0c8c8e Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 28 Oct 2016 10:28:41 -0700 Subject: [PATCH] Added tests for tables, TOI controller --- .../src/ui/ConductorTOIControllerSpec.js | 40 ++++++ .../src/ui/TimeOfInterestControllerSpec.js | 115 ++++++++++++++++++ .../controllers/TelemetryTableController.js | 2 +- .../HistoricalTableControllerSpec.js | 72 ++++++++++- .../controllers/MCTTableControllerSpec.js | 9 ++ 5 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 platform/features/conductor-v2/conductor/src/ui/ConductorTOIControllerSpec.js create mode 100644 platform/features/conductor-v2/conductor/src/ui/TimeOfInterestControllerSpec.js diff --git a/platform/features/conductor-v2/conductor/src/ui/ConductorTOIControllerSpec.js b/platform/features/conductor-v2/conductor/src/ui/ConductorTOIControllerSpec.js new file mode 100644 index 0000000000..5c4e9aa9d5 --- /dev/null +++ b/platform/features/conductor-v2/conductor/src/ui/ConductorTOIControllerSpec.js @@ -0,0 +1,40 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +define([ + './ConductorTOIController' +], function ( + ConductorTOIController +) { + var mockConductor; + var mockConductorViewService; + + describe("The ConductorTOIController", function () { + mockConductor = jasmine.createSpyObj("conductor", [ + "on" + ]); + mockConductorViewService = jasmine.createSpyObj("conductorViewService", [ + "on" + ]); + + }); +}); diff --git a/platform/features/conductor-v2/conductor/src/ui/TimeOfInterestControllerSpec.js b/platform/features/conductor-v2/conductor/src/ui/TimeOfInterestControllerSpec.js new file mode 100644 index 0000000000..c6d4890b65 --- /dev/null +++ b/platform/features/conductor-v2/conductor/src/ui/TimeOfInterestControllerSpec.js @@ -0,0 +1,115 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +define(['./TimeOfInterestController'], function (TimeOfInterestController) { + + ddescribe("The time of interest controller", function () { + var controller; + var mockScope; + var mockConductor; + var mockFormatService; + var mockTimeSystem; + var mockFormat; + + beforeEach(function () { + mockConductor = jasmine.createSpyObj("conductor", [ + "on", + "timeSystem" + ]); + mockScope = jasmine.createSpyObj("scope", [ + "$on" + ]); + + mockFormat = jasmine.createSpyObj("format", [ + "format" + ]); + + mockFormatService = jasmine.createSpyObj("formatService", [ + "getFormat" + ]); + + mockFormatService.getFormat.andReturn(mockFormat); + + mockTimeSystem = { + formats: function() { + return ["mockFormat"]; + } + }; + + controller = new TimeOfInterestController(mockScope, {conductor: mockConductor}, mockFormatService); + }); + + function getCallback(target, event){ + return target.calls.filter(function (call) { + return call.args[0] === event; + })[0].args[1]; + } + + it("Listens for changes to TOI", function () { + expect(mockConductor.on).toHaveBeenCalledWith("timeOfInterest", controller.changeTimeOfInterest); + }); + + it("updates format when time system changes", function () { + expect(mockConductor.on).toHaveBeenCalledWith("timeSystem", controller.changeTimeSystem); + getCallback(mockConductor.on, "timeSystem")(mockTimeSystem); + expect(controller.format).toBe(mockFormat); + }); + + describe("When TOI changes", function () { + var toi; + var toiCallback; + var formattedTOI; + + beforeEach(function () { + var timeSystemCallback = getCallback(mockConductor.on, "timeSystem"); + toi = 1; + mockConductor.timeSystem.andReturn(mockTimeSystem); + + //Set time system + timeSystemCallback(mockTimeSystem); + + toiCallback = getCallback(mockConductor.on, "timeOfInterest"); + formattedTOI = "formatted TOI"; + + mockFormatService.getFormat.andReturn("mockFormat"); + mockFormat.format.andReturn(formattedTOI); + }); + it("Uses the time system formatter to produce TOI text", function () { + var toiCallback = getCallback(mockConductor.on, "timeOfInterest"); + //Set TOI + toiCallback(toi); + expect(mockFormat.format).toHaveBeenCalled(); + }); + it("Sets the time of interest text", function () { + //Set TOI + toiCallback(toi); + expect(controller.toiText).toBe(formattedTOI); + }); + it("Pins the time of interest", function () { + //Set TOI + toiCallback(toi); + expect(mockScope.pinned).toBe(true); + }); + }) + + }); +}); diff --git a/platform/features/table/src/controllers/TelemetryTableController.js b/platform/features/table/src/controllers/TelemetryTableController.js index e03959a47a..7d6cbc2bec 100644 --- a/platform/features/table/src/controllers/TelemetryTableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -69,7 +69,7 @@ define( // Unsubscribe when the plot is destroyed this.$scope.$on("$destroy", this.destroy); - this.$scope.timeColumns = []; + this.timeColumns = []; this.sortByTimeSystem = this.sortByTimeSystem.bind(this); diff --git a/platform/features/table/test/controllers/HistoricalTableControllerSpec.js b/platform/features/table/test/controllers/HistoricalTableControllerSpec.js index 46475b8dbc..962bff9542 100644 --- a/platform/features/table/test/controllers/HistoricalTableControllerSpec.js +++ b/platform/features/table/test/controllers/HistoricalTableControllerSpec.js @@ -37,6 +37,7 @@ define( mockAngularTimeout, mockTimeoutHandle, watches, + mockConductor, controller; function promise(value) { @@ -47,6 +48,12 @@ define( }; } + function getCallback(target, event) { + return target.calls.filter(function (call){ + return call.args[0] === event; + })[0].args[1]; + } + beforeEach(function () { watches = {}; mockScope = jasmine.createSpyObj('scope', [ @@ -108,13 +115,22 @@ define( mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined)); mockTelemetryHandle.request.andReturn(promise(undefined)); mockTelemetryHandle.getTelemetryObjects.andReturn([]); + mockTelemetryHandle.getMetadata.andReturn([]); mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [ 'handle' ]); mockTelemetryHandler.handle.andReturn(mockTelemetryHandle); - controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter, mockAngularTimeout); + mockConductor = jasmine.createSpyObj("conductor", [ + "timeSystem", + "on", + "off" + ]); + + controller = new TableController(mockScope, mockTelemetryHandler, + mockTelemetryFormatter, mockAngularTimeout, {conductor: mockConductor}); + controller.table = mockTable; controller.handle = mockTelemetryHandle; }); @@ -233,6 +249,60 @@ define( }); }); + describe('After populating columns', function () { + var metadata; + beforeEach(function () { + metadata = [{domains: [{name: 'time domain 1'}, {name:'time domain 2'}]}, {domains: [{name: 'time domain 3'}, {name: 'time domain 4'}]} ]; + controller.populateColumns(metadata); + }); + + it('Automatically identifies time columns', function () { + expect(controller.timeColumns.length).toBe(4); + expect(controller.timeColumns[0]).toBe('time domain 1'); + }); + + it('Automatically sorts by time column that matches current' + + ' time system', function () { + var key = 'time_domain_1', + name = 'time domain 1', + mockTimeSystem = { + metadata: { + key: key + } + }; + + mockTable.columns = [ + { + domainMetadata: { + key: key + }, + getTitle: function () { + return name; + } + }, + { + domainMetadata: { + key: 'anotherColumn' + }, + getTitle: function () { + return 'some other column'; + } + }, + { + domainMetadata: { + key: 'thirdColumn' + }, + getTitle: function () { + return 'a third column'; + } + } + ]; + + expect(mockConductor.on).toHaveBeenCalledWith('timeSystem', jasmine.any(Function)); + getCallback(mockConductor.on, 'timeSystem')(mockTimeSystem); + expect(controller.$scope.defaultSort).toBe(name); + }); + }); describe('Yields thread', function () { var mockSeries, mockRow; diff --git a/platform/features/table/test/controllers/MCTTableControllerSpec.js b/platform/features/table/test/controllers/MCTTableControllerSpec.js index a8effbf2d0..1cbf3b4954 100644 --- a/platform/features/table/test/controllers/MCTTableControllerSpec.js +++ b/platform/features/table/test/controllers/MCTTableControllerSpec.js @@ -114,6 +114,15 @@ define( expect(mockScope.$watch).toHaveBeenCalledWith('rows', jasmine.any(Function)); }); + it('destroys listeners on destruction', function() { + expect(mockScope.$on).toHaveBeenCalledWith('$destroy', controller.destroyConductorListeners); + getCallback(mockScope.$on, '$destroy')(); + + expect(mockConductor.off).toHaveBeenCalledWith('timeSystem', controller.changeTimeSystem); + expect(mockConductor.off).toHaveBeenCalledWith('timeOfInterest', controller.setTimeOfInterest); + expect(mockConductor.off).toHaveBeenCalledWith('bounds', controller.changeBounds); + }); + describe('The time of interest', function() { var rowsAsc = []; var rowsDesc = [];