2016-02-26 19:09:51 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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(
|
|
|
|
[
|
2016-04-22 16:44:34 +00:00
|
|
|
"../../src/controllers/HistoricalTableController"
|
2016-02-26 19:09:51 +00:00
|
|
|
],
|
|
|
|
function (TableController) {
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
describe('The Table Controller', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
var mockScope,
|
|
|
|
mockTelemetryHandler,
|
|
|
|
mockTelemetryHandle,
|
|
|
|
mockTelemetryFormatter,
|
|
|
|
mockDomainObject,
|
|
|
|
mockTable,
|
|
|
|
mockConfiguration,
|
2016-05-31 11:02:22 +00:00
|
|
|
mockAngularTimeout,
|
2016-02-26 19:09:51 +00:00
|
|
|
watches,
|
|
|
|
controller;
|
|
|
|
|
|
|
|
function promise(value) {
|
|
|
|
return {
|
2016-05-19 18:29:13 +00:00
|
|
|
then: function (callback) {
|
2016-02-26 19:09:51 +00:00
|
|
|
return promise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
beforeEach(function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
watches = {};
|
|
|
|
mockScope = jasmine.createSpyObj('scope', [
|
|
|
|
'$on',
|
|
|
|
'$watch',
|
|
|
|
'$watchCollection'
|
|
|
|
]);
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockScope.$on.andCallFake(function (expression, callback) {
|
2016-02-26 19:09:51 +00:00
|
|
|
watches[expression] = callback;
|
|
|
|
});
|
2016-05-19 18:29:13 +00:00
|
|
|
mockScope.$watch.andCallFake(function (expression, callback) {
|
|
|
|
watches[expression] = callback;
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
2016-05-19 18:29:13 +00:00
|
|
|
mockScope.$watchCollection.andCallFake(function (expression, callback) {
|
2016-02-26 19:09:51 +00:00
|
|
|
watches[expression] = callback;
|
|
|
|
});
|
|
|
|
|
2016-05-31 11:02:22 +00:00
|
|
|
mockAngularTimeout = jasmine.createSpy('$timeout');
|
|
|
|
|
2016-02-26 19:09:51 +00:00
|
|
|
mockConfiguration = {
|
|
|
|
'range1': true,
|
|
|
|
'range2': true,
|
|
|
|
'domain1': true
|
|
|
|
};
|
|
|
|
|
|
|
|
mockTable = jasmine.createSpyObj('table',
|
|
|
|
[
|
2016-04-22 16:44:34 +00:00
|
|
|
'populateColumns',
|
|
|
|
'buildColumnConfiguration',
|
2016-03-03 17:26:12 +00:00
|
|
|
'getRowValues',
|
|
|
|
'saveColumnConfiguration'
|
2016-02-26 19:09:51 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
mockTable.columns = [];
|
2016-04-22 16:44:34 +00:00
|
|
|
mockTable.buildColumnConfiguration.andReturn(mockConfiguration);
|
2016-02-26 19:09:51 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
2016-02-26 19:09:51 +00:00
|
|
|
'getCapability',
|
|
|
|
'useCapability',
|
|
|
|
'getModel'
|
|
|
|
]);
|
|
|
|
mockDomainObject.getModel.andReturn({});
|
|
|
|
|
|
|
|
mockScope.domainObject = mockDomainObject;
|
|
|
|
|
|
|
|
mockTelemetryHandle = jasmine.createSpyObj('telemetryHandle', [
|
|
|
|
'request',
|
|
|
|
'promiseTelemetryObjects',
|
2016-03-14 02:37:08 +00:00
|
|
|
'getTelemetryObjects',
|
2016-02-26 19:09:51 +00:00
|
|
|
'getMetadata',
|
2016-03-14 02:37:08 +00:00
|
|
|
'getSeries',
|
2016-02-26 19:09:51 +00:00
|
|
|
'unsubscribe',
|
|
|
|
'makeDatum'
|
|
|
|
]);
|
|
|
|
mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined));
|
2016-03-14 02:37:08 +00:00
|
|
|
mockTelemetryHandle.request.andReturn(promise(undefined));
|
|
|
|
mockTelemetryHandle.getTelemetryObjects.andReturn([]);
|
2016-02-26 19:09:51 +00:00
|
|
|
|
|
|
|
mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [
|
|
|
|
'handle'
|
|
|
|
]);
|
|
|
|
mockTelemetryHandler.handle.andReturn(mockTelemetryHandle);
|
|
|
|
|
2016-05-31 11:02:22 +00:00
|
|
|
controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter, mockAngularTimeout);
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.table = mockTable;
|
|
|
|
controller.handle = mockTelemetryHandle;
|
|
|
|
});
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
it('subscribes to telemetry handler for telemetry updates', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.subscribe();
|
|
|
|
expect(mockTelemetryHandler.handle).toHaveBeenCalled();
|
|
|
|
expect(mockTelemetryHandle.request).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it('Unsubscribes from telemetry when scope is destroyed', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.handle = mockTelemetryHandle;
|
|
|
|
watches.$destroy();
|
|
|
|
expect(mockTelemetryHandle.unsubscribe).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2016-04-22 16:44:34 +00:00
|
|
|
describe('makes use of the table', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
|
|
|
|
it('to create column definitions from telemetry' +
|
2016-03-14 18:25:26 +00:00
|
|
|
' metadata', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.setup();
|
2016-04-22 16:44:34 +00:00
|
|
|
expect(mockTable.populateColumns).toHaveBeenCalled();
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('to create column configuration, which is written to the' +
|
2016-03-14 18:25:26 +00:00
|
|
|
' object model', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.setup();
|
2016-04-22 16:44:34 +00:00
|
|
|
expect(mockTable.buildColumnConfiguration).toHaveBeenCalled();
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it('updates the rows on scope when historical telemetry is received', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
var mockSeries = {
|
2016-03-14 18:25:26 +00:00
|
|
|
getPointCount: function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
return 5;
|
|
|
|
},
|
2016-03-14 18:25:26 +00:00
|
|
|
getDomainValue: function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
return 'Domain Value';
|
|
|
|
},
|
2016-03-14 18:25:26 +00:00
|
|
|
getRangeValue: function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
return 'Range Value';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mockRow = {'domain': 'Domain Value', 'range': 'Range' +
|
|
|
|
' Value'};
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockTelemetryHandle.makeDatum.andCallFake(function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
return mockRow;
|
|
|
|
});
|
|
|
|
mockTable.getRowValues.andReturn(mockRow);
|
2016-03-14 02:37:08 +00:00
|
|
|
mockTelemetryHandle.getTelemetryObjects.andReturn([mockDomainObject]);
|
|
|
|
mockTelemetryHandle.getSeries.andReturn(mockSeries);
|
|
|
|
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
2016-05-31 11:02:22 +00:00
|
|
|
expect(mockAngularTimeout).toHaveBeenCalled();
|
|
|
|
mockAngularTimeout.mostRecentCall.args[0]();
|
|
|
|
|
2016-02-26 19:09:51 +00:00
|
|
|
expect(controller.$scope.rows.length).toBe(5);
|
|
|
|
expect(controller.$scope.rows[0]).toBe(mockRow);
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it('filters the visible columns based on configuration', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.filterColumns();
|
|
|
|
expect(controller.$scope.headers.length).toBe(3);
|
|
|
|
expect(controller.$scope.headers[2]).toEqual('domain1');
|
|
|
|
|
|
|
|
mockConfiguration.domain1 = false;
|
|
|
|
controller.filterColumns();
|
|
|
|
expect(controller.$scope.headers.length).toBe(2);
|
|
|
|
expect(controller.$scope.headers[2]).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
describe('creates event listeners', function () {
|
2016-03-14 18:25:26 +00:00
|
|
|
beforeEach(function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
spyOn(controller, 'subscribe');
|
2016-02-26 19:09:51 +00:00
|
|
|
spyOn(controller, 'filterColumns');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers telemetry subscription update when domain' +
|
2016-03-14 18:25:26 +00:00
|
|
|
' object changes', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.registerChangeListeners();
|
|
|
|
//'watches' object is populated by fake scope watch and
|
|
|
|
// watchCollection functions defined above
|
|
|
|
expect(watches.domainObject).toBeDefined();
|
|
|
|
watches.domainObject(mockDomainObject);
|
|
|
|
expect(controller.subscribe).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers telemetry subscription update when domain' +
|
2016-03-31 23:30:35 +00:00
|
|
|
' object composition changes', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.registerChangeListeners();
|
|
|
|
expect(watches['domainObject.getModel().composition']).toBeDefined();
|
2016-05-31 11:02:22 +00:00
|
|
|
watches['domainObject.getModel().composition']([], []);
|
2016-02-26 19:09:51 +00:00
|
|
|
expect(controller.subscribe).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers telemetry subscription update when time' +
|
2016-03-14 18:25:26 +00:00
|
|
|
' conductor bounds change', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.registerChangeListeners();
|
|
|
|
expect(watches['telemetry:display:bounds']).toBeDefined();
|
|
|
|
watches['telemetry:display:bounds']();
|
|
|
|
expect(controller.subscribe).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers refiltering of the columns when configuration' +
|
2016-03-31 23:30:35 +00:00
|
|
|
' changes', function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
controller.setup();
|
|
|
|
expect(watches['domainObject.getModel().configuration.table.columns']).toBeDefined();
|
|
|
|
watches['domainObject.getModel().configuration.table.columns']();
|
|
|
|
expect(controller.filterColumns).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2016-05-31 11:02:22 +00:00
|
|
|
describe('Yields thread', function () {
|
|
|
|
var mockSeries,
|
|
|
|
mockRow,
|
|
|
|
mockWindowTimeout = {};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockSeries = {
|
|
|
|
getPointCount: function () {
|
|
|
|
return 5;
|
|
|
|
},
|
|
|
|
getDomainValue: function () {
|
|
|
|
return 'Domain Value';
|
|
|
|
},
|
|
|
|
getRangeValue: function () {
|
|
|
|
return 'Range Value';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mockRow = {'domain': 'Domain Value', 'range': 'Range Value'};
|
|
|
|
|
|
|
|
mockTelemetryHandle.makeDatum.andCallFake(function () {
|
|
|
|
return mockRow;
|
|
|
|
});
|
|
|
|
mockTable.getRowValues.andReturn(mockRow);
|
|
|
|
mockTelemetryHandle.getTelemetryObjects.andReturn([mockDomainObject]);
|
|
|
|
mockTelemetryHandle.getSeries.andReturn(mockSeries);
|
|
|
|
|
|
|
|
jasmine.getGlobal().setTimeout = jasmine.createSpy("setTimeout");
|
|
|
|
jasmine.getGlobal().setTimeout.andReturn(mockWindowTimeout);
|
|
|
|
jasmine.getGlobal().clearTimeout = jasmine.createSpy("clearTimeout");
|
|
|
|
|
|
|
|
});
|
|
|
|
it('only when necessary', function () {
|
|
|
|
|
|
|
|
controller.batchSize = 1000;
|
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
|
|
|
expect(mockAngularTimeout).toHaveBeenCalled();
|
|
|
|
mockAngularTimeout.mostRecentCall.args[0]();
|
|
|
|
|
|
|
|
expect(controller.$scope.rows.length).toBe(5);
|
|
|
|
expect(controller.$scope.rows[0]).toBe(mockRow);
|
|
|
|
|
|
|
|
expect(jasmine.getGlobal().setTimeout).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
});
|
|
|
|
it('when row count exceeds batch size', function () {
|
|
|
|
controller.batchSize = 3;
|
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
|
|
|
expect(jasmine.getGlobal().setTimeout).toHaveBeenCalled();
|
|
|
|
jasmine.getGlobal().setTimeout.mostRecentCall.args[0]();
|
|
|
|
|
|
|
|
expect(mockAngularTimeout).toHaveBeenCalled();
|
|
|
|
mockAngularTimeout.mostRecentCall.args[0]();
|
|
|
|
|
|
|
|
expect(controller.$scope.rows.length).toBe(5);
|
|
|
|
expect(controller.$scope.rows[0]).toBe(mockRow);
|
|
|
|
});
|
|
|
|
it('cancelling any outstanding timeouts', function () {
|
|
|
|
controller.batchSize = 3;
|
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
|
|
|
expect(jasmine.getGlobal().setTimeout).toHaveBeenCalled();
|
|
|
|
jasmine.getGlobal().setTimeout.mostRecentCall.args[0]();
|
|
|
|
|
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
|
|
|
expect(jasmine.getGlobal().clearTimeout).toHaveBeenCalledWith(mockWindowTimeout);
|
|
|
|
});
|
|
|
|
it('cancels timeout on scope destruction', function () {
|
|
|
|
controller.batchSize = 3;
|
|
|
|
controller.addHistoricalData(mockDomainObject, mockSeries);
|
|
|
|
|
|
|
|
expect(jasmine.getGlobal().setTimeout).toHaveBeenCalled();
|
|
|
|
jasmine.getGlobal().setTimeout.mostRecentCall.args[0]();
|
|
|
|
|
|
|
|
//Call destroy function
|
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
|
|
|
mockScope.$on.mostRecentCall.args[1]();
|
|
|
|
expect(jasmine.getGlobal().clearTimeout).toHaveBeenCalledWith(mockWindowTimeout);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|