2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2018-05-14 22:46:17 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2018, United States Government
|
2015-05-13 23:42:35 +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
|
2015-05-13 23:42:35 +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
|
2015-05-13 23:42:35 +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.
|
|
|
|
*****************************************************************************/
|
2015-02-17 17:03:23 +00:00
|
|
|
|
|
|
|
define(
|
2017-12-07 22:59:12 +00:00
|
|
|
[
|
|
|
|
"../src/FixedController",
|
|
|
|
"zepto"
|
|
|
|
],
|
|
|
|
function (
|
|
|
|
FixedController,
|
|
|
|
$
|
|
|
|
) {
|
2015-02-17 17:03:23 +00:00
|
|
|
|
|
|
|
describe("The Fixed Position controller", function () {
|
|
|
|
var mockScope,
|
2015-02-20 23:53:41 +00:00
|
|
|
mockQ,
|
|
|
|
mockDialogService,
|
2015-02-17 17:03:23 +00:00
|
|
|
mockFormatter,
|
|
|
|
mockDomainObject,
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent,
|
2015-02-17 17:03:23 +00:00
|
|
|
testGrid,
|
|
|
|
testModel,
|
2015-02-20 00:24:45 +00:00
|
|
|
testConfiguration,
|
2017-03-29 19:18:11 +00:00
|
|
|
mockOpenMCT,
|
|
|
|
mockTelemetryAPI,
|
|
|
|
mockCompositionAPI,
|
|
|
|
mockCompositionCollection,
|
|
|
|
mockChildren,
|
|
|
|
mockConductor,
|
|
|
|
mockMetadata,
|
|
|
|
mockTimeSystem,
|
|
|
|
mockLimitEvaluator,
|
2017-12-07 22:59:12 +00:00
|
|
|
mockSelection,
|
2018-06-27 20:30:01 +00:00
|
|
|
mockObjects,
|
|
|
|
mockNewDomainObject,
|
|
|
|
unlistenFunc,
|
2017-12-07 22:59:12 +00:00
|
|
|
$element = [],
|
|
|
|
selectable = [],
|
2015-02-17 17:03:23 +00:00
|
|
|
controller;
|
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
// Utility function; find a $on calls for a given expression.
|
2015-02-17 18:50:02 +00:00
|
|
|
function findOn(expr) {
|
|
|
|
var on;
|
2018-06-30 00:32:59 +00:00
|
|
|
mockScope.$on.calls.all().forEach(function (call) {
|
2015-02-17 18:50:02 +00:00
|
|
|
if (call.args[0] === expr) {
|
|
|
|
on = call.args[1];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
function makeMockDomainObject(id) {
|
2017-03-29 19:18:11 +00:00
|
|
|
return {
|
|
|
|
identifier: {
|
2018-06-27 20:30:01 +00:00
|
|
|
key: "domainObject-" + id,
|
|
|
|
namespace: ""
|
2017-03-29 19:18:11 +00:00
|
|
|
},
|
|
|
|
name: "Point " + id
|
|
|
|
};
|
2015-02-17 17:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
'$scope',
|
2017-03-29 19:18:11 +00:00
|
|
|
["$on", "$watch", "$digest", "commit"]
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2015-02-20 23:53:41 +00:00
|
|
|
mockQ = jasmine.createSpyObj('$q', ['when']);
|
|
|
|
mockDialogService = jasmine.createSpyObj(
|
|
|
|
'dialogService',
|
|
|
|
['getUserInput']
|
|
|
|
);
|
2015-02-17 17:03:23 +00:00
|
|
|
mockFormatter = jasmine.createSpyObj(
|
|
|
|
'telemetryFormatter',
|
2017-03-29 19:18:11 +00:00
|
|
|
['format']
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockFormatter.format.and.callFake(function (valueMetadata) {
|
2018-03-07 21:49:11 +00:00
|
|
|
return "Formatted " + valueMetadata.value;
|
2017-03-29 19:18:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
mockConductor = jasmine.createSpyObj('conductor', [
|
|
|
|
'on',
|
|
|
|
'off',
|
|
|
|
'bounds',
|
|
|
|
'timeSystem',
|
2017-05-01 23:19:11 +00:00
|
|
|
'clock'
|
2017-03-29 19:18:11 +00:00
|
|
|
]);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockConductor.bounds.and.returnValue({});
|
2017-03-29 19:18:11 +00:00
|
|
|
mockTimeSystem = {
|
|
|
|
metadata: {
|
|
|
|
key: 'key'
|
|
|
|
}
|
|
|
|
};
|
2018-06-30 00:32:59 +00:00
|
|
|
mockConductor.timeSystem.and.returnValue(mockTimeSystem);
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent = jasmine.createSpyObj(
|
|
|
|
'event',
|
2016-05-19 18:29:13 +00:00
|
|
|
['preventDefault']
|
2015-06-25 18:35:18 +00:00
|
|
|
);
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockTelemetryAPI = jasmine.createSpyObj('telemetry',
|
|
|
|
[
|
|
|
|
'subscribe',
|
|
|
|
'request',
|
2018-03-21 21:18:08 +00:00
|
|
|
'isTelemetryObject',
|
2017-03-29 19:18:11 +00:00
|
|
|
'getMetadata',
|
|
|
|
'limitEvaluator',
|
|
|
|
'getValueFormatter'
|
|
|
|
]
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.isTelemetryObject.and.returnValue(true);
|
|
|
|
mockTelemetryAPI.request.and.returnValue(Promise.resolve([]));
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
testGrid = [123, 456];
|
2015-02-17 17:03:23 +00:00
|
|
|
testModel = {
|
|
|
|
composition: ['a', 'b', 'c'],
|
|
|
|
layoutGrid: testGrid
|
|
|
|
};
|
2015-02-20 00:24:45 +00:00
|
|
|
testConfiguration = { elements: [
|
2017-06-28 20:38:35 +00:00
|
|
|
{ type: "fixed.telemetry", id: 'a', x: 1, y: 1, useGrid: true},
|
|
|
|
{ type: "fixed.telemetry", id: 'b', x: 1, y: 1, useGrid: true},
|
|
|
|
{ type: "fixed.telemetry", id: 'c', x: 1, y: 1, useGrid: true}
|
2015-02-20 00:24:45 +00:00
|
|
|
]};
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockChildren = testModel.composition.map(makeMockDomainObject);
|
2018-06-27 20:30:01 +00:00
|
|
|
mockCompositionCollection = jasmine.createSpyObj('compositionCollection', [
|
|
|
|
'load',
|
|
|
|
'on',
|
|
|
|
'off'
|
|
|
|
]);
|
|
|
|
mockCompositionAPI = jasmine.createSpyObj('composition', [
|
|
|
|
'get'
|
|
|
|
]);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockCompositionAPI.get.and.returnValue(mockCompositionCollection);
|
|
|
|
mockCompositionCollection.load.and.returnValue(
|
2017-03-29 19:18:11 +00:00
|
|
|
Promise.resolve(mockChildren)
|
|
|
|
);
|
|
|
|
|
2015-02-19 18:22:12 +00:00
|
|
|
mockScope.model = testModel;
|
2015-02-20 00:24:45 +00:00
|
|
|
mockScope.configuration = testConfiguration;
|
2017-12-07 22:59:12 +00:00
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
mockNewDomainObject = jasmine.createSpyObj("newDomainObject", [
|
|
|
|
'layoutGrid',
|
|
|
|
'configuration',
|
|
|
|
'composition'
|
|
|
|
]);
|
|
|
|
mockNewDomainObject.layoutGrid = testGrid;
|
|
|
|
mockNewDomainObject.configuration = {
|
|
|
|
'fixed-display': testConfiguration
|
|
|
|
};
|
|
|
|
mockNewDomainObject.composition = ['a', 'b', 'c'];
|
|
|
|
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
|
|
|
['getId', 'getModel', 'getCapability', 'useCapability']
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockDomainObject.useCapability.and.returnValue(mockNewDomainObject);
|
2018-06-27 20:30:01 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
|
|
|
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0] = {
|
|
|
|
context: {
|
|
|
|
oldItem: mockDomainObject
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mockSelection = jasmine.createSpyObj("selection", [
|
|
|
|
'select',
|
|
|
|
'on',
|
|
|
|
'off',
|
|
|
|
'get'
|
|
|
|
]);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockSelection.get.and.returnValue([]);
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
unlistenFunc = jasmine.createSpy("unlisten");
|
|
|
|
mockObjects = jasmine.createSpyObj('objects', [
|
|
|
|
'observe',
|
|
|
|
'get'
|
|
|
|
]);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockObjects.observe.and.returnValue(unlistenFunc);
|
2018-06-27 20:30:01 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockOpenMCT = {
|
2017-05-01 23:19:11 +00:00
|
|
|
time: mockConductor,
|
2017-03-29 19:18:11 +00:00
|
|
|
telemetry: mockTelemetryAPI,
|
2017-12-07 22:59:12 +00:00
|
|
|
composition: mockCompositionAPI,
|
2018-06-27 20:30:01 +00:00
|
|
|
selection: mockSelection,
|
|
|
|
objects: mockObjects
|
2017-03-29 19:18:11 +00:00
|
|
|
};
|
|
|
|
|
2017-12-07 22:59:12 +00:00
|
|
|
$element = $('<div></div>');
|
|
|
|
spyOn($element[0], 'click');
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockMetadata = jasmine.createSpyObj('mockMetadata', [
|
|
|
|
'valuesForHints',
|
2017-10-23 17:14:43 +00:00
|
|
|
'value',
|
|
|
|
'values'
|
2017-03-29 19:18:11 +00:00
|
|
|
]);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockMetadata.value.and.returnValue({
|
2017-03-29 19:18:11 +00:00
|
|
|
key: 'value'
|
|
|
|
});
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockMetadata.valuesForHints.and.callFake(function (hints) {
|
2017-03-29 19:18:11 +00:00
|
|
|
if (hints === ['domain']) {
|
|
|
|
return [{
|
|
|
|
key: 'time'
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
return [{
|
|
|
|
key: 'value'
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mockLimitEvaluator = jasmine.createSpyObj('limitEvaluator', [
|
|
|
|
'evaluate'
|
|
|
|
]);
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockLimitEvaluator.evaluate.and.returnValue({});
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.getMetadata.and.returnValue(mockMetadata);
|
|
|
|
mockTelemetryAPI.limitEvaluator.and.returnValue(mockLimitEvaluator);
|
|
|
|
mockTelemetryAPI.getValueFormatter.and.returnValue(mockFormatter);
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
controller = new FixedController(
|
|
|
|
mockScope,
|
2015-02-20 23:53:41 +00:00
|
|
|
mockQ,
|
|
|
|
mockDialogService,
|
2017-12-07 22:59:12 +00:00
|
|
|
mockOpenMCT,
|
|
|
|
$element
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2018-06-27 20:30:01 +00:00
|
|
|
spyOn(controller, "mutate");
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
it("subscribes a domain object", function () {
|
|
|
|
var object = makeMockDomainObject("mock");
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
return controller.getTelemetry(object).then(function () {
|
2018-06-27 20:30:01 +00:00
|
|
|
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(
|
|
|
|
object,
|
|
|
|
jasmine.any(Function),
|
|
|
|
jasmine.any(Object)
|
|
|
|
);
|
2017-03-29 19:18:11 +00:00
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
it("releases subscription when a domain objects is removed", function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
var unsubscribe = jasmine.createSpy('unsubscribe');
|
2018-06-30 00:32:59 +00:00
|
|
|
var unsubscribePromise = new Promise(function (resolve) {
|
|
|
|
unsubscribe.and.callFake(resolve);
|
2018-06-27 20:30:01 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
var object = makeMockDomainObject("mock");
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
|
|
|
|
return controller.getTelemetry(object).then(function () {
|
2018-06-27 20:30:01 +00:00
|
|
|
controller.onCompositionRemove(object.identifier);
|
2018-06-30 00:32:59 +00:00
|
|
|
return unsubscribePromise;
|
|
|
|
}).then(function () {
|
|
|
|
expect(unsubscribe).toHaveBeenCalled();
|
2017-03-29 19:18:11 +00:00
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("exposes visible elements based on configuration", function () {
|
2018-06-27 20:30:01 +00:00
|
|
|
var elements = controller.getElements();
|
2015-02-20 00:24:45 +00:00
|
|
|
|
|
|
|
expect(elements.length).toEqual(3);
|
|
|
|
expect(elements[0].id).toEqual('a');
|
|
|
|
expect(elements[1].id).toEqual('b');
|
|
|
|
expect(elements[2].id).toEqual('c');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows elements to be selected", function () {
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = controller.getElements()[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2017-12-07 22:59:12 +00:00
|
|
|
|
|
|
|
expect(controller.isElementSelected()).toBe(true);
|
2015-02-20 00:24:45 +00:00
|
|
|
});
|
|
|
|
|
2015-02-24 18:12:33 +00:00
|
|
|
it("allows selection retrieval", function () {
|
2018-06-27 20:30:01 +00:00
|
|
|
var elements = controller.getElements();
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = elements[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2015-02-24 18:12:33 +00:00
|
|
|
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(controller.getSelectedElement()).toEqual(elements[1]);
|
|
|
|
});
|
2015-02-20 00:24:45 +00:00
|
|
|
|
2018-01-08 21:59:49 +00:00
|
|
|
it("selects the parent view when selected element is removed", function () {
|
2017-12-07 22:59:12 +00:00
|
|
|
var elements = controller.getElements();
|
|
|
|
selectable[0].context.elementProxy = elements[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2018-06-27 20:30:01 +00:00
|
|
|
controller.remove(elements[1]);
|
2017-12-07 22:59:12 +00:00
|
|
|
|
|
|
|
expect($element[0].click).toHaveBeenCalled();
|
2015-02-20 00:24:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("retains selections during refresh", function () {
|
|
|
|
// Get elements; remove one of them; trigger refresh.
|
|
|
|
// Same element (at least by index) should still be selected.
|
2018-06-27 20:30:01 +00:00
|
|
|
var elements = controller.getElements();
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = elements[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2015-03-04 02:47:44 +00:00
|
|
|
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(controller.getSelectedElement()).toEqual(elements[1]);
|
2015-03-04 02:47:44 +00:00
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
controller.remove(elements[2]);
|
2015-02-20 00:24:45 +00:00
|
|
|
elements = controller.getElements();
|
2017-12-07 22:59:12 +00:00
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
// Verify removal, as test assumes this
|
|
|
|
expect(elements.length).toEqual(2);
|
|
|
|
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(controller.shouldSelect(elements[1])).toBe(true);
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
it("Displays received values for telemetry elements", function () {
|
2015-02-20 00:24:45 +00:00
|
|
|
var elements;
|
2017-03-29 19:18:11 +00:00
|
|
|
var mockTelemetry = {
|
|
|
|
time: 100,
|
|
|
|
value: 200
|
|
|
|
};
|
|
|
|
var testElement = {};
|
|
|
|
var telemetryObject = {
|
|
|
|
identifier: {
|
|
|
|
key: '12345'
|
|
|
|
}
|
|
|
|
};
|
2018-06-30 00:32:59 +00:00
|
|
|
mockConductor.clock.and.returnValue({});
|
2017-03-29 19:18:11 +00:00
|
|
|
controller.elementProxiesById = {};
|
|
|
|
controller.elementProxiesById['12345'] = [testElement];
|
|
|
|
controller.elementProxies = [testElement];
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
controller.subscribeToObject(telemetryObject);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.subscribe.calls.mostRecent().args[1](mockTelemetry);
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
mockScope.$digest.and.callFake(resolve);
|
|
|
|
}).then(function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
// Get elements that controller is now exposing
|
|
|
|
elements = controller.getElements();
|
|
|
|
|
|
|
|
// Formatted values should be available
|
|
|
|
expect(elements[0].value).toEqual("Formatted 200");
|
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2015-06-25 17:58:01 +00:00
|
|
|
it("updates elements styles when grid size changes", function () {
|
2018-06-27 20:30:01 +00:00
|
|
|
// Grid size is initially set to testGrid which is [123, 456]
|
|
|
|
var originalLeft = controller.getElements()[0].style.left;
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
// Change the grid size
|
|
|
|
controller.updateElementPositions([20, 20]);
|
|
|
|
|
|
|
|
expect(controller.getElements()[0].style.left).not.toEqual(originalLeft);
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
2015-02-17 18:50:02 +00:00
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("listens for drop events", function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
|
|
|
mockScope.model = testModel;
|
|
|
|
|
2015-02-17 18:50:02 +00:00
|
|
|
// Layout should position panels according to
|
|
|
|
// where the user dropped them, so it needs to
|
|
|
|
// listen for drop events.
|
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith(
|
|
|
|
'mctDrop',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify precondition
|
2015-02-20 00:24:45 +00:00
|
|
|
expect(testConfiguration.elements.length).toEqual(3);
|
2015-02-17 18:50:02 +00:00
|
|
|
|
|
|
|
// Notify that a drop occurred
|
|
|
|
testModel.composition.push('d');
|
2018-06-27 20:30:01 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockObjects.get.and.returnValue(Promise.resolve([]));
|
2018-06-27 20:30:01 +00:00
|
|
|
|
2015-02-17 18:50:02 +00:00
|
|
|
findOn('mctDrop')(
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent,
|
2015-02-17 18:50:02 +00:00
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
2015-02-20 00:24:45 +00:00
|
|
|
|
|
|
|
// Should have added an element
|
|
|
|
expect(testConfiguration.elements.length).toEqual(4);
|
2015-02-17 18:50:02 +00:00
|
|
|
|
2015-06-25 18:35:18 +00:00
|
|
|
// ...and prevented default...
|
|
|
|
expect(mockEvent.preventDefault).toHaveBeenCalled();
|
2015-02-17 18:50:02 +00:00
|
|
|
});
|
2015-02-20 00:24:45 +00:00
|
|
|
|
2015-06-25 18:35:18 +00:00
|
|
|
it("ignores drops when default has been prevented", function () {
|
|
|
|
// Avoids redundant drop-handling, WTD-1233
|
2015-06-26 18:53:45 +00:00
|
|
|
mockEvent.defaultPrevented = true;
|
2015-06-25 18:35:18 +00:00
|
|
|
|
|
|
|
// Notify that a drop occurred
|
|
|
|
testModel.composition.push('d');
|
|
|
|
findOn('mctDrop')(
|
|
|
|
mockEvent,
|
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
|
|
|
|
|
|
|
// Should NOT have added an element
|
|
|
|
expect(testConfiguration.elements.length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("unsubscribes when destroyed", function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
var unsubscribe = jasmine.createSpy('unsubscribe');
|
2018-06-27 20:30:01 +00:00
|
|
|
var object = makeMockDomainObject("mock");
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
return controller.getTelemetry(object).then(function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
expect(unsubscribe).not.toHaveBeenCalled();
|
|
|
|
// Destroy the scope
|
|
|
|
findOn('$destroy')();
|
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
expect(unsubscribe).toHaveBeenCalled();
|
2017-03-29 19:18:11 +00:00
|
|
|
});
|
2015-02-20 00:24:45 +00:00
|
|
|
});
|
2015-02-20 23:59:22 +00:00
|
|
|
|
|
|
|
it("exposes its grid size", function () {
|
|
|
|
expect(controller.getGridSize()).toEqual(testGrid);
|
|
|
|
});
|
2015-03-04 02:52:13 +00:00
|
|
|
|
2015-02-24 18:12:33 +00:00
|
|
|
it("exposes drag handles", function () {
|
|
|
|
var handles;
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = controller.getElements()[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2015-02-24 18:12:33 +00:00
|
|
|
|
|
|
|
// Should have a non-empty array of handles
|
|
|
|
handles = controller.handles();
|
2017-12-07 22:59:12 +00:00
|
|
|
|
2015-02-24 18:12:33 +00:00
|
|
|
expect(handles).toEqual(jasmine.any(Array));
|
|
|
|
expect(handles.length).not.toEqual(0);
|
|
|
|
|
|
|
|
// And they should have start/continue/end drag methods
|
|
|
|
handles.forEach(function (handle) {
|
|
|
|
expect(handle.startDrag).toEqual(jasmine.any(Function));
|
|
|
|
expect(handle.continueDrag).toEqual(jasmine.any(Function));
|
|
|
|
expect(handle.endDrag).toEqual(jasmine.any(Function));
|
|
|
|
});
|
|
|
|
});
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
it("exposes a move handle", function () {
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = controller.getElements()[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Should have a move handle
|
2017-12-07 22:59:12 +00:00
|
|
|
var handle = controller.moveHandle();
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// And it should have start/continue/end drag methods
|
|
|
|
expect(handle.startDrag).toEqual(jasmine.any(Function));
|
|
|
|
expect(handle.continueDrag).toEqual(jasmine.any(Function));
|
|
|
|
expect(handle.endDrag).toEqual(jasmine.any(Function));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("updates selection style during drag", function () {
|
|
|
|
var oldStyle;
|
2017-12-07 22:59:12 +00:00
|
|
|
selectable[0].context.elementProxy = controller.getElements()[1];
|
2018-06-30 00:32:59 +00:00
|
|
|
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Get style
|
2017-12-07 22:59:12 +00:00
|
|
|
oldStyle = controller.getSelectedElementStyle();
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Start a drag gesture
|
|
|
|
controller.moveHandle().startDrag();
|
|
|
|
|
|
|
|
// Haven't moved yet; style shouldn't have updated yet
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(controller.getSelectedElementStyle()).toEqual(oldStyle);
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Drag a little
|
2016-05-19 18:29:13 +00:00
|
|
|
controller.moveHandle().continueDrag([1000, 100]);
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Style should have been updated
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(controller.getSelectedElementStyle()).not.toEqual(oldStyle);
|
|
|
|
});
|
|
|
|
|
2018-04-20 15:45:29 +00:00
|
|
|
it("cleans up selection on scope destroy", function () {
|
2017-12-07 22:59:12 +00:00
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith(
|
|
|
|
'$destroy',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockScope.$on.calls.mostRecent().args[1]();
|
2017-12-07 22:59:12 +00:00
|
|
|
|
|
|
|
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
2015-02-24 20:02:43 +00:00
|
|
|
});
|
2015-12-30 17:29:24 +00:00
|
|
|
|
|
|
|
describe("on display bounds changes", function () {
|
|
|
|
var testBounds;
|
2017-03-29 19:18:11 +00:00
|
|
|
var boundsChangeCallback;
|
|
|
|
var objectOne;
|
|
|
|
var objectTwo;
|
2015-12-30 17:29:24 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
testBounds = { start: 123, end: 321 };
|
2018-06-30 00:32:59 +00:00
|
|
|
boundsChangeCallback = mockConductor.on.calls.mostRecent().args[1];
|
2017-03-29 19:18:11 +00:00
|
|
|
objectOne = {};
|
|
|
|
objectTwo = {};
|
|
|
|
controller.telemetryObjects = [
|
|
|
|
objectOne,
|
|
|
|
objectTwo
|
|
|
|
];
|
|
|
|
spyOn(controller, "fetchHistoricalData");
|
2018-06-30 00:32:59 +00:00
|
|
|
controller.fetchHistoricalData.and.callThrough();
|
2015-12-30 17:29:24 +00:00
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
it("registers a bounds change listener", function () {
|
|
|
|
expect(mockConductor.on).toHaveBeenCalledWith("bounds", jasmine.any(Function));
|
2015-12-30 17:29:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("requests only a single point", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
mockConductor.clock.and.returnValue(undefined);
|
2017-03-29 19:18:11 +00:00
|
|
|
boundsChangeCallback(testBounds);
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(mockTelemetryAPI.request.calls.count()).toBe(2);
|
2015-12-30 17:29:24 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.request.calls.all().forEach(function (call) {
|
2017-03-29 19:18:11 +00:00
|
|
|
expect(call.args[1].size).toBe(1);
|
2015-12-30 17:29:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
it("Does not fetch historical data on tick", function () {
|
2017-05-01 23:19:11 +00:00
|
|
|
boundsChangeCallback(testBounds, true);
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(mockTelemetryAPI.request.calls.count()).toBe(0);
|
2017-03-29 19:18:11 +00:00
|
|
|
});
|
2015-12-30 17:29:24 +00:00
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
describe("on receipt of telemetry", function () {
|
|
|
|
var mockTelemetryObject;
|
|
|
|
var testValue;
|
|
|
|
var testElement;
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockTelemetryObject = {
|
|
|
|
identifier: {
|
|
|
|
key: '12345'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
testValue = 30;
|
|
|
|
testElement = {};
|
|
|
|
|
|
|
|
controller.elementProxiesById = {};
|
|
|
|
controller.elementProxiesById['12345'] = [testElement];
|
|
|
|
controller.elementProxies = [testElement];
|
|
|
|
});
|
|
|
|
|
|
|
|
it("updates displayed values from historical telemetry", function () {
|
|
|
|
spyOn(controller, "updateView");
|
2018-06-30 00:32:59 +00:00
|
|
|
controller.updateView.and.callThrough();
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockTelemetryAPI.request.and.returnValue(Promise.resolve([{
|
2017-03-29 19:18:11 +00:00
|
|
|
time: 100,
|
|
|
|
value: testValue
|
|
|
|
}]));
|
|
|
|
|
2018-06-27 20:30:01 +00:00
|
|
|
controller.fetchHistoricalData(mockTelemetryObject);
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
mockScope.$digest.and.callFake(resolve);
|
|
|
|
}).then(function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
expect(controller.updateView).toHaveBeenCalled();
|
|
|
|
expect(controller.getElements()[0].value)
|
|
|
|
.toEqual("Formatted " + testValue);
|
|
|
|
});
|
2015-12-07 20:33:29 +00:00
|
|
|
});
|
|
|
|
|
2017-10-23 17:14:43 +00:00
|
|
|
it("selects an range value to display, if available", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
mockMetadata.valuesForHints.and.returnValue([
|
2017-10-23 17:14:43 +00:00
|
|
|
{
|
|
|
|
key: 'range',
|
|
|
|
source: 'range'
|
|
|
|
}
|
|
|
|
]);
|
2018-03-07 21:49:11 +00:00
|
|
|
var key = controller.chooseValueMetadataToDisplay(mockMetadata).source;
|
2017-10-23 17:14:43 +00:00
|
|
|
expect(key).toEqual('range');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selects the first non-domain value to display, if no range available", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
mockMetadata.valuesForHints.and.returnValue([]);
|
|
|
|
mockMetadata.values.and.returnValue([
|
2017-10-23 17:14:43 +00:00
|
|
|
{
|
|
|
|
key: 'domain',
|
|
|
|
source: 'domain',
|
|
|
|
hints: {
|
|
|
|
domain: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'image',
|
|
|
|
source: 'image',
|
|
|
|
hints: {
|
|
|
|
image: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
2018-03-07 21:49:11 +00:00
|
|
|
var key = controller.chooseValueMetadataToDisplay(mockMetadata).source;
|
2017-10-23 17:14:43 +00:00
|
|
|
expect(key).toEqual('image');
|
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
it("reflects limit status", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
mockLimitEvaluator.evaluate.and.returnValue({cssClass: "alarm-a"});
|
2017-03-29 19:18:11 +00:00
|
|
|
controller.updateView(mockTelemetryObject, [{
|
|
|
|
time: 100,
|
|
|
|
value: testValue
|
|
|
|
}]);
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
mockScope.$digest.and.callFake(resolve);
|
|
|
|
}).then(function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
// Limit-based CSS classes should be available
|
|
|
|
expect(controller.getElements()[0].cssClass).toEqual("alarm-a");
|
|
|
|
});
|
|
|
|
});
|
2017-12-07 22:59:12 +00:00
|
|
|
|
|
|
|
it("listens for selection change events", function () {
|
|
|
|
expect(mockOpenMCT.selection.on).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-12-07 20:33:29 +00:00
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-23 20:43:00 +00:00
|
|
|
);
|