2016-03-09 05:36:33 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine,xit*/
|
|
|
|
|
|
|
|
define(
|
|
|
|
[
|
2016-04-21 02:31:54 +00:00
|
|
|
"../../src/controllers/RTTelemetryTableController"
|
2016-03-09 05:36:33 +00:00
|
|
|
],
|
|
|
|
function (TableController) {
|
|
|
|
"use strict";
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
describe('The real-time table controller', function () {
|
2016-03-09 05:36:33 +00:00
|
|
|
var mockScope,
|
|
|
|
mockTelemetryHandler,
|
|
|
|
mockTelemetryHandle,
|
|
|
|
mockTelemetryFormatter,
|
|
|
|
mockDomainObject,
|
|
|
|
mockTable,
|
|
|
|
mockConfiguration,
|
|
|
|
watches,
|
|
|
|
mockTableRow,
|
|
|
|
controller;
|
|
|
|
|
|
|
|
function promise(value) {
|
|
|
|
return {
|
|
|
|
then: function (callback){
|
|
|
|
return promise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
beforeEach(function () {
|
2016-03-09 05:36:33 +00:00
|
|
|
watches = {};
|
|
|
|
mockTableRow = {'col1': 'val1', 'col2': 'row2'};
|
|
|
|
|
|
|
|
mockScope = jasmine.createSpyObj('scope', [
|
|
|
|
'$on',
|
|
|
|
'$watch',
|
|
|
|
'$watchCollection',
|
2016-03-14 22:52:01 +00:00
|
|
|
'$digest',
|
2016-03-09 05:36:33 +00:00
|
|
|
'$broadcast'
|
|
|
|
]);
|
2016-03-14 18:25:26 +00:00
|
|
|
mockScope.$on.andCallFake(function (expression, callback){
|
2016-03-09 05:36:33 +00:00
|
|
|
watches[expression] = callback;
|
|
|
|
});
|
2016-03-14 18:25:26 +00:00
|
|
|
mockScope.$watch.andCallFake(function (expression, callback){
|
2016-03-09 05:36:33 +00:00
|
|
|
watches[expression] = callback;
|
|
|
|
});
|
2016-03-14 18:25:26 +00:00
|
|
|
mockScope.$watchCollection.andCallFake(function (expression, callback){
|
2016-03-09 05:36:33 +00:00
|
|
|
watches[expression] = callback;
|
|
|
|
});
|
|
|
|
|
|
|
|
mockConfiguration = {
|
|
|
|
'range1': true,
|
|
|
|
'range2': true,
|
|
|
|
'domain1': true
|
|
|
|
};
|
|
|
|
|
|
|
|
mockTable = jasmine.createSpyObj('table',
|
|
|
|
[
|
2016-04-21 02:31:54 +00:00
|
|
|
'buildColumns',
|
|
|
|
'getColumnConfiguration',
|
2016-03-09 05:36:33 +00:00
|
|
|
'getRowValues',
|
|
|
|
'saveColumnConfiguration'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockTable.columns = [];
|
2016-04-21 02:31:54 +00:00
|
|
|
mockTable.getColumnConfiguration.andReturn(mockConfiguration);
|
2016-03-09 05:36:33 +00:00
|
|
|
mockTable.getRowValues.andReturn(mockTableRow);
|
|
|
|
|
|
|
|
mockDomainObject= jasmine.createSpyObj('domainObject', [
|
|
|
|
'getCapability',
|
|
|
|
'useCapability',
|
|
|
|
'getModel'
|
|
|
|
]);
|
|
|
|
mockDomainObject.getModel.andReturn({});
|
|
|
|
mockDomainObject.getCapability.andReturn(
|
|
|
|
{
|
2016-03-14 18:25:26 +00:00
|
|
|
getMetadata: function (){
|
2016-03-09 05:36:33 +00:00
|
|
|
return {ranges: [{format: 'string'}]};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mockScope.domainObject = mockDomainObject;
|
|
|
|
|
|
|
|
mockTelemetryHandle = jasmine.createSpyObj('telemetryHandle', [
|
|
|
|
'getMetadata',
|
|
|
|
'unsubscribe',
|
|
|
|
'getDatum',
|
|
|
|
'promiseTelemetryObjects',
|
2016-04-21 02:31:54 +00:00
|
|
|
'getTelemetryObjects'
|
2016-03-09 05:36:33 +00:00
|
|
|
]);
|
|
|
|
// Arbitrary array with non-zero length, contents are not
|
|
|
|
// used by mocks
|
|
|
|
mockTelemetryHandle.getTelemetryObjects.andReturn([{}]);
|
|
|
|
mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined));
|
|
|
|
mockTelemetryHandle.getDatum.andReturn({});
|
|
|
|
|
|
|
|
mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [
|
|
|
|
'handle'
|
|
|
|
]);
|
|
|
|
mockTelemetryHandler.handle.andReturn(mockTelemetryHandle);
|
|
|
|
|
|
|
|
controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter);
|
|
|
|
controller.table = mockTable;
|
|
|
|
controller.handle = mockTelemetryHandle;
|
|
|
|
});
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
it('registers for streaming telemetry', function () {
|
2016-03-09 05:36:33 +00:00
|
|
|
controller.subscribe();
|
|
|
|
expect(mockTelemetryHandler.handle).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function), true);
|
|
|
|
});
|
|
|
|
|
2016-03-31 23:30:35 +00:00
|
|
|
describe('receives new telemetry', function () {
|
2016-03-17 01:26:14 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
controller.subscribe();
|
|
|
|
mockScope.rows = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates table with new streaming telemetry', function () {
|
|
|
|
mockTelemetryHandler.handle.mostRecentCall.args[1]();
|
|
|
|
expect(mockScope.$broadcast).toHaveBeenCalledWith('add:row', 0);
|
|
|
|
});
|
|
|
|
it('observes the row limit', function () {
|
2016-03-17 17:09:59 +00:00
|
|
|
var i = 0;
|
2016-03-17 01:26:14 +00:00
|
|
|
controller.maxRows = 10;
|
|
|
|
|
|
|
|
//Fill rows array with elements
|
|
|
|
for (; i < 10; i++) {
|
|
|
|
mockScope.rows.push({row: i});
|
|
|
|
}
|
|
|
|
mockTelemetryHandler.handle.mostRecentCall.args[1]();
|
|
|
|
expect(mockScope.rows.length).toBe(controller.maxRows);
|
|
|
|
expect(mockScope.rows[mockScope.rows.length-1]).toBe(mockTableRow);
|
|
|
|
expect(mockScope.rows[0].row).toBe(1);
|
|
|
|
});
|
2016-03-09 05:36:33 +00:00
|
|
|
});
|
|
|
|
|
2016-03-14 18:25:26 +00:00
|
|
|
it('enables autoscroll for event telemetry', function () {
|
2016-03-09 05:36:33 +00:00
|
|
|
controller.subscribe();
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(mockScope.autoScroll).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|