Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7cc008e

Browse files
committedOct 28, 2016
Added tests for tables, TOI controller
1 parent b0901e8 commit 7cc008e

File tree

5 files changed

+236
-2
lines changed

5 files changed

+236
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*****************************************************************************
2+
* Open MCT Web, Copyright (c) 2014-2015, United States Government
3+
* as represented by the Administrator of the National Aeronautics and Space
4+
* Administration. All rights reserved.
5+
*
6+
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* Open MCT Web includes source code licensed under additional open source
18+
* licenses. See the Open Source Licenses file (LICENSES.md) included with
19+
* this source code distribution or the Licensing information page available
20+
* at runtime from the About dialog for additional information.
21+
*****************************************************************************/
22+
23+
define([
24+
'./ConductorTOIController'
25+
], function (
26+
ConductorTOIController
27+
) {
28+
var mockConductor;
29+
var mockConductorViewService;
30+
31+
describe("The ConductorTOIController", function () {
32+
mockConductor = jasmine.createSpyObj("conductor", [
33+
"on"
34+
]);
35+
mockConductorViewService = jasmine.createSpyObj("conductorViewService", [
36+
"on"
37+
]);
38+
39+
});
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*****************************************************************************
2+
* Open MCT Web, Copyright (c) 2014-2015, United States Government
3+
* as represented by the Administrator of the National Aeronautics and Space
4+
* Administration. All rights reserved.
5+
*
6+
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* Open MCT Web includes source code licensed under additional open source
18+
* licenses. See the Open Source Licenses file (LICENSES.md) included with
19+
* this source code distribution or the Licensing information page available
20+
* at runtime from the About dialog for additional information.
21+
*****************************************************************************/
22+
23+
define(['./TimeOfInterestController'], function (TimeOfInterestController) {
24+
25+
ddescribe("The time of interest controller", function () {
26+
var controller;
27+
var mockScope;
28+
var mockConductor;
29+
var mockFormatService;
30+
var mockTimeSystem;
31+
var mockFormat;
32+
33+
beforeEach(function () {
34+
mockConductor = jasmine.createSpyObj("conductor", [
35+
"on",
36+
"timeSystem"
37+
]);
38+
mockScope = jasmine.createSpyObj("scope", [
39+
"$on"
40+
]);
41+
42+
mockFormat = jasmine.createSpyObj("format", [
43+
"format"
44+
]);
45+
46+
mockFormatService = jasmine.createSpyObj("formatService", [
47+
"getFormat"
48+
]);
49+
50+
mockFormatService.getFormat.andReturn(mockFormat);
51+
52+
mockTimeSystem = {
53+
formats: function() {
54+
return ["mockFormat"];
55+
}
56+
};
57+
58+
controller = new TimeOfInterestController(mockScope, {conductor: mockConductor}, mockFormatService);
59+
});
60+
61+
function getCallback(target, event){
62+
return target.calls.filter(function (call) {
63+
return call.args[0] === event;
64+
})[0].args[1];
65+
}
66+
67+
it("Listens for changes to TOI", function () {
68+
expect(mockConductor.on).toHaveBeenCalledWith("timeOfInterest", controller.changeTimeOfInterest);
69+
});
70+
71+
it("updates format when time system changes", function () {
72+
expect(mockConductor.on).toHaveBeenCalledWith("timeSystem", controller.changeTimeSystem);
73+
getCallback(mockConductor.on, "timeSystem")(mockTimeSystem);
74+
expect(controller.format).toBe(mockFormat);
75+
});
76+
77+
describe("When TOI changes", function () {
78+
var toi;
79+
var toiCallback;
80+
var formattedTOI;
81+
82+
beforeEach(function () {
83+
var timeSystemCallback = getCallback(mockConductor.on, "timeSystem");
84+
toi = 1;
85+
mockConductor.timeSystem.andReturn(mockTimeSystem);
86+
87+
//Set time system
88+
timeSystemCallback(mockTimeSystem);
89+
90+
toiCallback = getCallback(mockConductor.on, "timeOfInterest");
91+
formattedTOI = "formatted TOI";
92+
93+
mockFormatService.getFormat.andReturn("mockFormat");
94+
mockFormat.format.andReturn(formattedTOI);
95+
});
96+
it("Uses the time system formatter to produce TOI text", function () {
97+
var toiCallback = getCallback(mockConductor.on, "timeOfInterest");
98+
//Set TOI
99+
toiCallback(toi);
100+
expect(mockFormat.format).toHaveBeenCalled();
101+
});
102+
it("Sets the time of interest text", function () {
103+
//Set TOI
104+
toiCallback(toi);
105+
expect(controller.toiText).toBe(formattedTOI);
106+
});
107+
it("Pins the time of interest", function () {
108+
//Set TOI
109+
toiCallback(toi);
110+
expect(mockScope.pinned).toBe(true);
111+
});
112+
})
113+
114+
});
115+
});

‎platform/features/table/src/controllers/TelemetryTableController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ define(
6969

7070
// Unsubscribe when the plot is destroyed
7171
this.$scope.$on("$destroy", this.destroy);
72-
this.$scope.timeColumns = [];
72+
this.timeColumns = [];
7373

7474

7575
this.sortByTimeSystem = this.sortByTimeSystem.bind(this);

‎platform/features/table/test/controllers/HistoricalTableControllerSpec.js

+71-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ define(
3737
mockAngularTimeout,
3838
mockTimeoutHandle,
3939
watches,
40+
mockConductor,
4041
controller;
4142

4243
function promise(value) {
@@ -47,6 +48,12 @@ define(
4748
};
4849
}
4950

51+
function getCallback(target, event) {
52+
return target.calls.filter(function (call){
53+
return call.args[0] === event;
54+
})[0].args[1];
55+
}
56+
5057
beforeEach(function () {
5158
watches = {};
5259
mockScope = jasmine.createSpyObj('scope', [
@@ -108,13 +115,22 @@ define(
108115
mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined));
109116
mockTelemetryHandle.request.andReturn(promise(undefined));
110117
mockTelemetryHandle.getTelemetryObjects.andReturn([]);
118+
mockTelemetryHandle.getMetadata.andReturn([]);
111119

112120
mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [
113121
'handle'
114122
]);
115123
mockTelemetryHandler.handle.andReturn(mockTelemetryHandle);
116124

117-
controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter, mockAngularTimeout);
125+
mockConductor = jasmine.createSpyObj("conductor", [
126+
"timeSystem",
127+
"on",
128+
"off"
129+
]);
130+
131+
controller = new TableController(mockScope, mockTelemetryHandler,
132+
mockTelemetryFormatter, mockAngularTimeout, {conductor: mockConductor});
133+
118134
controller.table = mockTable;
119135
controller.handle = mockTelemetryHandle;
120136
});
@@ -233,6 +249,60 @@ define(
233249
});
234250

235251
});
252+
describe('After populating columns', function () {
253+
var metadata;
254+
beforeEach(function () {
255+
metadata = [{domains: [{name: 'time domain 1'}, {name:'time domain 2'}]}, {domains: [{name: 'time domain 3'}, {name: 'time domain 4'}]} ];
256+
controller.populateColumns(metadata);
257+
});
258+
259+
it('Automatically identifies time columns', function () {
260+
expect(controller.timeColumns.length).toBe(4);
261+
expect(controller.timeColumns[0]).toBe('time domain 1');
262+
});
263+
264+
it('Automatically sorts by time column that matches current' +
265+
' time system', function () {
266+
var key = 'time_domain_1',
267+
name = 'time domain 1',
268+
mockTimeSystem = {
269+
metadata: {
270+
key: key
271+
}
272+
};
273+
274+
mockTable.columns = [
275+
{
276+
domainMetadata: {
277+
key: key
278+
},
279+
getTitle: function () {
280+
return name;
281+
}
282+
},
283+
{
284+
domainMetadata: {
285+
key: 'anotherColumn'
286+
},
287+
getTitle: function () {
288+
return 'some other column';
289+
}
290+
},
291+
{
292+
domainMetadata: {
293+
key: 'thirdColumn'
294+
},
295+
getTitle: function () {
296+
return 'a third column';
297+
}
298+
}
299+
];
300+
301+
expect(mockConductor.on).toHaveBeenCalledWith('timeSystem', jasmine.any(Function));
302+
getCallback(mockConductor.on, 'timeSystem')(mockTimeSystem);
303+
expect(controller.$scope.defaultSort).toBe(name);
304+
});
305+
});
236306
describe('Yields thread', function () {
237307
var mockSeries,
238308
mockRow;

‎platform/features/table/test/controllers/MCTTableControllerSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ define(
114114
expect(mockScope.$watch).toHaveBeenCalledWith('rows', jasmine.any(Function));
115115
});
116116

117+
it('destroys listeners on destruction', function() {
118+
expect(mockScope.$on).toHaveBeenCalledWith('$destroy', controller.destroyConductorListeners);
119+
getCallback(mockScope.$on, '$destroy')();
120+
121+
expect(mockConductor.off).toHaveBeenCalledWith('timeSystem', controller.changeTimeSystem);
122+
expect(mockConductor.off).toHaveBeenCalledWith('timeOfInterest', controller.setTimeOfInterest);
123+
expect(mockConductor.off).toHaveBeenCalledWith('bounds', controller.changeBounds);
124+
});
125+
117126
describe('The time of interest', function() {
118127
var rowsAsc = [];
119128
var rowsDesc = [];

0 commit comments

Comments
 (0)
Please sign in to comment.