2016-02-26 19:09:51 +00:00
|
|
|
/*****************************************************************************
|
2017-04-05 21:35:12 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2017, United States Government
|
2016-02-26 19:09:51 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2016-02-26 19:09:51 +00:00
|
|
|
* "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.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2016-02-26 19:09:51 +00:00
|
|
|
* 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(
|
|
|
|
[
|
2017-01-26 18:59:22 +00:00
|
|
|
"../src/TableConfiguration"
|
2016-02-26 19:09:51 +00:00
|
|
|
],
|
2017-01-26 18:59:22 +00:00
|
|
|
function (Table) {
|
2016-02-26 19:09:51 +00:00
|
|
|
|
|
|
|
describe("A table", function () {
|
|
|
|
var mockDomainObject,
|
2017-01-26 18:59:22 +00:00
|
|
|
mockAPI,
|
|
|
|
mockTelemetryAPI,
|
2016-02-26 19:09:51 +00:00
|
|
|
table,
|
|
|
|
mockModel;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockDomainObject = jasmine.createSpyObj('domainObject',
|
2017-02-02 23:08:26 +00:00
|
|
|
['getModel', 'useCapability', 'getCapability', 'hasCapability']
|
2016-02-26 19:09:51 +00:00
|
|
|
);
|
|
|
|
mockModel = {};
|
|
|
|
mockDomainObject.getModel.andReturn(mockModel);
|
2017-02-02 23:08:26 +00:00
|
|
|
mockDomainObject.getCapability.andCallFake(function (name) {
|
|
|
|
return name === 'editor' && {
|
|
|
|
isEditContextRoot: function () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2017-01-26 18:59:22 +00:00
|
|
|
mockTelemetryAPI = jasmine.createSpyObj('telemetryAPI', [
|
|
|
|
'getValueFormatter'
|
|
|
|
]);
|
|
|
|
mockAPI = {
|
|
|
|
telemetry: mockTelemetryAPI
|
|
|
|
};
|
2017-04-27 18:15:05 +00:00
|
|
|
mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) {
|
|
|
|
var formatter = jasmine.createSpyObj(
|
|
|
|
'telemetryFormatter:' + metadata.key,
|
|
|
|
[
|
|
|
|
'format',
|
|
|
|
'parse'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
var getter = function (datum) {
|
|
|
|
return datum[metadata.key];
|
|
|
|
};
|
|
|
|
formatter.format.andCallFake(getter);
|
|
|
|
formatter.parse.andCallFake(getter);
|
|
|
|
return formatter;
|
|
|
|
});
|
2016-02-26 19:09:51 +00:00
|
|
|
|
2017-01-26 18:59:22 +00:00
|
|
|
table = new Table(mockDomainObject, mockAPI);
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
describe("Building columns from telemetry metadata", function () {
|
2017-01-26 18:59:22 +00:00
|
|
|
var metadata = [
|
|
|
|
{
|
|
|
|
name: 'Range 1',
|
|
|
|
key: 'range1',
|
|
|
|
hints: {
|
|
|
|
y: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Range 2',
|
|
|
|
key: 'range2',
|
|
|
|
hints: {
|
|
|
|
y: 2
|
2016-02-26 19:09:51 +00:00
|
|
|
}
|
2017-01-26 18:59:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Domain 1',
|
|
|
|
key: 'domain1',
|
|
|
|
format: 'utc',
|
|
|
|
hints: {
|
|
|
|
x: 1
|
2016-02-26 19:09:51 +00:00
|
|
|
}
|
2017-01-26 18:59:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Domain 2',
|
|
|
|
key: 'domain2',
|
|
|
|
format: 'utc',
|
|
|
|
hints: {
|
|
|
|
x: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2016-02-26 19:09:51 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
beforeEach(function () {
|
2016-04-22 16:44:34 +00:00
|
|
|
table.populateColumns(metadata);
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("populates columns", function () {
|
2017-01-26 18:59:22 +00:00
|
|
|
expect(table.columns.length).toBe(4);
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("Produces headers for each column based on title", function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
var headers,
|
|
|
|
firstColumn = table.columns[0];
|
|
|
|
|
|
|
|
spyOn(firstColumn, 'getTitle');
|
|
|
|
headers = table.getHeaders();
|
2017-01-26 18:59:22 +00:00
|
|
|
expect(headers.length).toBe(4);
|
2016-02-26 19:09:51 +00:00
|
|
|
expect(firstColumn.getTitle).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Provides a default configuration with all columns" +
|
2016-05-19 18:29:13 +00:00
|
|
|
" visible", function () {
|
2016-04-22 16:44:34 +00:00
|
|
|
var configuration = table.buildColumnConfiguration();
|
2016-02-26 19:09:51 +00:00
|
|
|
|
|
|
|
expect(configuration).toBeDefined();
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(Object.keys(configuration).every(function (key) {
|
2016-02-26 19:09:51 +00:00
|
|
|
return configuration[key];
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("Column configuration exposes persisted configuration", function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
var tableConfig,
|
|
|
|
modelConfig = {
|
|
|
|
table: {
|
|
|
|
columns : {
|
|
|
|
'Range 1': false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mockModel.configuration = modelConfig;
|
|
|
|
|
2016-04-22 16:44:34 +00:00
|
|
|
tableConfig = table.buildColumnConfiguration();
|
2016-02-26 19:09:51 +00:00
|
|
|
|
|
|
|
expect(tableConfig).toBeDefined();
|
|
|
|
expect(tableConfig['Range 1']).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('retrieving row values', function () {
|
|
|
|
var datum,
|
|
|
|
rowValues;
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
beforeEach(function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
datum = {
|
2017-01-26 18:59:22 +00:00
|
|
|
'range1': 10,
|
|
|
|
'range2': 20,
|
2016-02-26 19:09:51 +00:00
|
|
|
'domain1': 0,
|
|
|
|
'domain2': 1
|
|
|
|
};
|
2017-01-26 18:59:22 +00:00
|
|
|
var limitEvaluator = {
|
|
|
|
evaluate: function () {
|
|
|
|
return {
|
|
|
|
"cssClass": "alarm-class"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
rowValues = table.getRowValues(limitEvaluator, datum);
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it("Returns a value for every column", function () {
|
2016-02-26 19:09:51 +00:00
|
|
|
expect(rowValues['Range 1'].text).toBeDefined();
|
2017-01-26 18:59:22 +00:00
|
|
|
expect(rowValues['Range 1'].text).toEqual(10);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Applies appropriate css class if limit violated.", function () {
|
|
|
|
expect(rowValues['Range 1'].cssClass).toEqual("alarm-class");
|
2016-02-26 19:09:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|