mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 03:06:54 +00:00
Added tests for tables, TOI controller
This commit is contained in:
parent
b0901e83cb
commit
7cc008ed01
@ -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"
|
||||
]);
|
||||
|
||||
});
|
||||
});
|
@ -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);
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
});
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 = [];
|
||||
|
Loading…
Reference in New Issue
Block a user