2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2017-04-05 21:35:12 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2017, 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(
|
|
|
|
["../src/FixedController"],
|
|
|
|
function (FixedController) {
|
|
|
|
|
|
|
|
describe("The Fixed Position controller", function () {
|
|
|
|
var mockScope,
|
2015-02-20 23:53:41 +00:00
|
|
|
mockQ,
|
|
|
|
mockDialogService,
|
2015-09-09 23:52:46 +00:00
|
|
|
mockHandler,
|
2015-02-17 17:03:23 +00:00
|
|
|
mockFormatter,
|
|
|
|
mockDomainObject,
|
2015-09-09 23:52:46 +00:00
|
|
|
mockHandle,
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent,
|
2015-02-17 17:03:23 +00:00
|
|
|
testGrid,
|
|
|
|
testModel,
|
|
|
|
testValues,
|
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,
|
2015-02-17 17:03:23 +00:00
|
|
|
controller;
|
|
|
|
|
|
|
|
// Utility function; find a watch for a given expression
|
|
|
|
function findWatch(expr) {
|
|
|
|
var watch;
|
|
|
|
mockScope.$watch.calls.forEach(function (call) {
|
|
|
|
if (call.args[0] === expr) {
|
|
|
|
watch = call.args[1];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return watch;
|
|
|
|
}
|
|
|
|
|
2015-02-17 18:50:02 +00:00
|
|
|
// As above, but for $on calls
|
|
|
|
function findOn(expr) {
|
|
|
|
var on;
|
|
|
|
mockScope.$on.calls.forEach(function (call) {
|
|
|
|
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: {
|
|
|
|
key: "domainObject-" + id
|
|
|
|
},
|
|
|
|
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-09-09 23:52:46 +00:00
|
|
|
mockHandler = jasmine.createSpyObj(
|
|
|
|
'telemetryHandler',
|
2016-05-19 18:29:13 +00:00
|
|
|
['handle']
|
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
|
|
|
);
|
2017-03-29 19:18:11 +00:00
|
|
|
mockFormatter.format.andCallFake(function (value) {
|
|
|
|
return "Formatted " + value;
|
|
|
|
});
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
2017-03-29 19:18:11 +00:00
|
|
|
['getId', 'getModel', 'getCapability', 'useCapability']
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2017-03-29 19:18:11 +00:00
|
|
|
|
2015-09-09 23:52:46 +00:00
|
|
|
mockHandle = jasmine.createSpyObj(
|
2015-02-17 17:03:23 +00:00
|
|
|
'subscription',
|
2015-09-09 23:52:46 +00:00
|
|
|
[
|
|
|
|
'unsubscribe',
|
|
|
|
'getDomainValue',
|
|
|
|
'getTelemetryObjects',
|
|
|
|
'getRangeValue',
|
2015-09-16 22:23:08 +00:00
|
|
|
'getDatum',
|
|
|
|
'request'
|
2015-09-09 23:52:46 +00:00
|
|
|
]
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
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
|
|
|
]);
|
|
|
|
mockConductor.bounds.andReturn({});
|
|
|
|
mockTimeSystem = {
|
|
|
|
metadata: {
|
|
|
|
key: 'key'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mockConductor.timeSystem.andReturn(mockTimeSystem);
|
|
|
|
|
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',
|
|
|
|
'canProvideTelemetry',
|
|
|
|
'getMetadata',
|
|
|
|
'limitEvaluator',
|
|
|
|
'getValueFormatter'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockTelemetryAPI.canProvideTelemetry.andReturn(true);
|
|
|
|
mockTelemetryAPI.request.andReturn(Promise.resolve([]));
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
testValues = { a: 10, b: 42, c: 31.42 };
|
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);
|
|
|
|
mockCompositionCollection = jasmine.createSpyObj('compositionCollection',
|
|
|
|
[
|
|
|
|
'load'
|
|
|
|
]
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2017-03-29 19:18:11 +00:00
|
|
|
mockCompositionAPI = jasmine.createSpyObj('composition',
|
|
|
|
[
|
|
|
|
'get'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockCompositionAPI.get.andReturn(mockCompositionCollection);
|
|
|
|
mockCompositionCollection.load.andReturn(
|
|
|
|
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;
|
2015-03-04 02:47:44 +00:00
|
|
|
mockScope.selection = jasmine.createSpyObj(
|
|
|
|
'selection',
|
2016-05-19 18:29:13 +00:00
|
|
|
['select', 'get', 'selected', 'deselect', 'proxy']
|
2015-03-04 02:47:44 +00:00
|
|
|
);
|
2015-02-17 17:03:23 +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,
|
|
|
|
composition: mockCompositionAPI
|
|
|
|
};
|
|
|
|
|
|
|
|
mockMetadata = jasmine.createSpyObj('mockMetadata', [
|
|
|
|
'valuesForHints',
|
2017-10-23 17:14:43 +00:00
|
|
|
'value',
|
|
|
|
'values'
|
2017-03-29 19:18:11 +00:00
|
|
|
]);
|
|
|
|
mockMetadata.value.andReturn({
|
|
|
|
key: 'value'
|
|
|
|
});
|
|
|
|
|
|
|
|
mockMetadata.valuesForHints.andCallFake(function (hints) {
|
|
|
|
if (hints === ['domain']) {
|
|
|
|
return [{
|
|
|
|
key: 'time'
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
return [{
|
|
|
|
key: 'value'
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mockLimitEvaluator = jasmine.createSpyObj('limitEvaluator', [
|
|
|
|
'evaluate'
|
|
|
|
]);
|
|
|
|
|
|
|
|
mockLimitEvaluator.evaluate.andReturn({});
|
|
|
|
|
|
|
|
mockTelemetryAPI.getMetadata.andReturn(mockMetadata);
|
|
|
|
mockTelemetryAPI.limitEvaluator.andReturn(mockLimitEvaluator);
|
|
|
|
mockTelemetryAPI.getValueFormatter.andReturn(mockFormatter);
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
controller = new FixedController(
|
|
|
|
mockScope,
|
2015-02-20 23:53:41 +00:00
|
|
|
mockQ,
|
|
|
|
mockDialogService,
|
2017-03-29 19:18:11 +00:00
|
|
|
mockOpenMCT
|
2015-02-17 17:03:23 +00:00
|
|
|
);
|
2016-02-27 00:19:14 +00:00
|
|
|
|
2016-11-08 22:59:09 +00:00
|
|
|
findWatch("model.layoutGrid")(testModel.layoutGrid);
|
2016-02-27 00:19:14 +00:00
|
|
|
findWatch("selection")(mockScope.selection);
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("subscribes when a domain object is available", function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
var dunzo = false;
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
2017-03-29 19:18:11 +00:00
|
|
|
findWatch("domainObject")(mockDomainObject).then(function () {
|
|
|
|
dunzo = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return dunzo;
|
|
|
|
}, "Telemetry fetched", 200);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
mockChildren.forEach(function (child) {
|
|
|
|
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(
|
|
|
|
child,
|
|
|
|
jasmine.any(Function),
|
|
|
|
jasmine.any(Object)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("releases subscriptions when domain objects change", function () {
|
2017-03-29 19:18:11 +00:00
|
|
|
var dunzo = false;
|
|
|
|
var unsubscribe = jasmine.createSpy('unsubscribe');
|
|
|
|
|
|
|
|
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
2017-03-29 19:18:11 +00:00
|
|
|
findWatch("domainObject")(mockDomainObject).then(function () {
|
|
|
|
dunzo = true;
|
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
waitsFor(function () {
|
|
|
|
return dunzo;
|
|
|
|
}, "Telemetry fetched", 200);
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
runs(function () {
|
|
|
|
expect(unsubscribe).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
dunzo = false;
|
|
|
|
|
|
|
|
findWatch("domainObject")(mockDomainObject).then(function () {
|
|
|
|
dunzo = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return dunzo;
|
|
|
|
}, "Telemetry fetched", 200);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(unsubscribe.calls.length).toBe(mockChildren.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("exposes visible elements based on configuration", function () {
|
|
|
|
var elements;
|
|
|
|
|
2015-02-17 17:03:23 +00:00
|
|
|
mockScope.model = testModel;
|
2015-02-20 00:24:45 +00:00
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
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 () {
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
controller.select(elements[1]);
|
2015-03-04 02:47:44 +00:00
|
|
|
expect(mockScope.selection.select)
|
|
|
|
.toHaveBeenCalledWith(elements[1]);
|
2015-02-20 00:24:45 +00:00
|
|
|
});
|
|
|
|
|
2015-02-24 18:12:33 +00:00
|
|
|
it("allows selection retrieval", function () {
|
|
|
|
// selected with no arguments should give the current
|
|
|
|
// selection
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
controller.select(elements[1]);
|
2015-03-04 23:08:11 +00:00
|
|
|
mockScope.selection.get.andReturn(elements[1]);
|
2015-02-24 18:12:33 +00:00
|
|
|
expect(controller.selected()).toEqual(elements[1]);
|
|
|
|
});
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
it("allows selections to be cleared", function () {
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
controller.select(elements[1]);
|
|
|
|
controller.clearSelection();
|
|
|
|
expect(controller.selected(elements[1])).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("retains selections during refresh", function () {
|
|
|
|
// Get elements; remove one of them; trigger refresh.
|
|
|
|
// Same element (at least by index) should still be selected.
|
|
|
|
var elements;
|
|
|
|
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
controller.select(elements[1]);
|
|
|
|
|
2015-03-04 02:47:44 +00:00
|
|
|
// Verify precondition
|
|
|
|
expect(mockScope.selection.select.calls.length).toEqual(1);
|
|
|
|
|
|
|
|
// Mimic selection behavior
|
|
|
|
mockScope.selection.get.andReturn(elements[1]);
|
|
|
|
|
2015-02-20 00:24:45 +00:00
|
|
|
elements[2].remove();
|
|
|
|
testModel.modified = 2;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
|
|
|
|
elements = controller.getElements();
|
|
|
|
// Verify removal, as test assumes this
|
|
|
|
expect(elements.length).toEqual(2);
|
|
|
|
|
2015-03-04 02:47:44 +00:00
|
|
|
expect(mockScope.selection.select.calls.length).toEqual(2);
|
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'
|
|
|
|
}
|
|
|
|
};
|
2017-05-01 23:19:11 +00:00
|
|
|
mockConductor.clock.andReturn({});
|
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
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
controller.subscribeToObjects([telemetryObject]);
|
|
|
|
mockTelemetryAPI.subscribe.mostRecentCall.args[1](mockTelemetry);
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
waitsFor(function () {
|
|
|
|
return controller.digesting === false;
|
|
|
|
}, "digest to complete", 100);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// Get elements that controller is now exposing
|
|
|
|
elements = controller.getElements();
|
|
|
|
|
|
|
|
// Formatted values should be available
|
|
|
|
expect(elements[0].value).toEqual("Formatted 200");
|
|
|
|
});
|
2015-02-20 00:24:45 +00:00
|
|
|
|
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 () {
|
|
|
|
var originalLeft;
|
2015-02-17 17:03:23 +00:00
|
|
|
|
2015-06-25 17:58:01 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
2015-02-17 17:03:23 +00:00
|
|
|
mockScope.model = testModel;
|
2015-06-25 17:58:01 +00:00
|
|
|
findWatch("domainObject")(mockDomainObject);
|
|
|
|
findWatch("model.modified")(1);
|
2015-02-17 18:34:13 +00:00
|
|
|
findWatch("model.composition")(mockScope.model.composition);
|
2015-06-25 17:58:01 +00:00
|
|
|
findWatch("model.layoutGrid")([10, 10]);
|
|
|
|
originalLeft = controller.getElements()[0].style.left;
|
|
|
|
findWatch("model.layoutGrid")([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');
|
|
|
|
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
|
|
|
// Should have triggered commit (provided by
|
|
|
|
// EditRepresenter) with some message.
|
|
|
|
expect(mockScope.commit)
|
|
|
|
.toHaveBeenCalledWith(jasmine.any(String));
|
|
|
|
});
|
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 dunzo = false;
|
|
|
|
var unsubscribe = jasmine.createSpy('unsubscribe');
|
|
|
|
|
|
|
|
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
|
|
|
|
|
|
|
|
mockScope.domainObject = mockDomainObject;
|
|
|
|
findWatch("domainObject")(mockDomainObject).then(function () {
|
|
|
|
dunzo = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return dunzo;
|
|
|
|
}, "Telemetry fetched", 200);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(unsubscribe).not.toHaveBeenCalled();
|
|
|
|
// Destroy the scope
|
|
|
|
findOn('$destroy')();
|
|
|
|
|
|
|
|
//Check that the same unsubscribe function returned by the
|
|
|
|
expect(unsubscribe.calls.length).toBe(mockChildren.length);
|
|
|
|
});
|
2015-02-20 00:24:45 +00:00
|
|
|
});
|
2015-02-20 23:59:22 +00:00
|
|
|
|
|
|
|
it("exposes its grid size", function () {
|
2015-06-25 17:58:01 +00:00
|
|
|
findWatch('model.layoutGrid')(testGrid);
|
2015-02-20 23:59:22 +00:00
|
|
|
// Template needs to be able to pass this into line
|
|
|
|
// elements to size SVGs appropriately
|
|
|
|
expect(controller.getGridSize()).toEqual(testGrid);
|
|
|
|
});
|
2015-03-04 02:52:13 +00:00
|
|
|
|
|
|
|
it("exposes a view-level selection proxy", function () {
|
|
|
|
expect(mockScope.selection.proxy).toHaveBeenCalledWith(
|
|
|
|
jasmine.any(Object)
|
|
|
|
);
|
|
|
|
});
|
2015-03-04 23:08:11 +00:00
|
|
|
|
2015-02-24 18:12:33 +00:00
|
|
|
it("exposes drag handles", function () {
|
|
|
|
var handles;
|
|
|
|
|
|
|
|
// Select something so that drag handles are expected
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
controller.select(controller.getElements()[1]);
|
|
|
|
|
|
|
|
// Should have a non-empty array of handles
|
|
|
|
handles = controller.handles();
|
|
|
|
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 () {
|
|
|
|
var handle;
|
|
|
|
|
|
|
|
// Select something so that drag handles are expected
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
controller.select(controller.getElements()[1]);
|
|
|
|
|
|
|
|
// Should have a move handle
|
|
|
|
handle = controller.moveHandle();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// Select something so that drag handles are expected
|
|
|
|
testModel.modified = 1;
|
|
|
|
findWatch("model.modified")(testModel.modified);
|
|
|
|
controller.select(controller.getElements()[1]);
|
2015-03-04 23:08:11 +00:00
|
|
|
mockScope.selection.get.andReturn(controller.getElements()[1]);
|
2015-02-24 20:02:43 +00:00
|
|
|
|
|
|
|
// Get style
|
|
|
|
oldStyle = controller.selected().style;
|
|
|
|
|
|
|
|
// Start a drag gesture
|
|
|
|
controller.moveHandle().startDrag();
|
|
|
|
|
|
|
|
// Haven't moved yet; style shouldn't have updated yet
|
|
|
|
expect(controller.selected().style).toEqual(oldStyle);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
expect(controller.selected().style).not.toEqual(oldStyle);
|
|
|
|
});
|
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 };
|
2017-03-29 19:18:11 +00:00
|
|
|
boundsChangeCallback = mockConductor.on.mostRecentCall.args[1];
|
|
|
|
objectOne = {};
|
|
|
|
objectTwo = {};
|
|
|
|
controller.telemetryObjects = [
|
|
|
|
objectOne,
|
|
|
|
objectTwo
|
|
|
|
];
|
|
|
|
spyOn(controller, "fetchHistoricalData");
|
|
|
|
controller.fetchHistoricalData.andCallThrough();
|
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 () {
|
2017-05-01 23:19:11 +00:00
|
|
|
mockConductor.clock.andReturn(undefined);
|
2017-03-29 19:18:11 +00:00
|
|
|
boundsChangeCallback(testBounds);
|
|
|
|
expect(mockTelemetryAPI.request.calls.length).toBe(2);
|
2015-12-30 17:29:24 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockTelemetryAPI.request.calls.forEach(function (call) {
|
|
|
|
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);
|
2017-03-29 19:18:11 +00:00
|
|
|
expect(mockTelemetryAPI.request.calls.length).toBe(0);
|
|
|
|
});
|
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");
|
|
|
|
controller.updateView.andCallThrough();
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
mockTelemetryAPI.request.andReturn(Promise.resolve([{
|
|
|
|
time: 100,
|
|
|
|
value: testValue
|
|
|
|
}]));
|
|
|
|
|
|
|
|
controller.fetchHistoricalData([mockTelemetryObject]);
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return controller.digesting === false;
|
2015-12-07 20:33:29 +00:00
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
runs(function () {
|
|
|
|
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 () {
|
|
|
|
mockMetadata.valuesForHints.andReturn([
|
|
|
|
{
|
|
|
|
key: 'range',
|
|
|
|
source: 'range'
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
var key = controller.chooseTelemetryKeyToDisplay(mockMetadata);
|
|
|
|
expect(key).toEqual('range');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selects the first non-domain value to display, if no range available", function () {
|
|
|
|
mockMetadata.valuesForHints.andReturn([]);
|
|
|
|
mockMetadata.values.andReturn([
|
|
|
|
{
|
|
|
|
key: 'domain',
|
|
|
|
source: 'domain',
|
|
|
|
hints: {
|
|
|
|
domain: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'image',
|
|
|
|
source: 'image',
|
|
|
|
hints: {
|
|
|
|
image: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
var key = controller.chooseTelemetryKeyToDisplay(mockMetadata);
|
|
|
|
expect(key).toEqual('image');
|
|
|
|
});
|
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
it("reflects limit status", function () {
|
|
|
|
mockLimitEvaluator.evaluate.andReturn({cssClass: "alarm-a"});
|
|
|
|
controller.updateView(mockTelemetryObject, [{
|
|
|
|
time: 100,
|
|
|
|
value: testValue
|
|
|
|
}]);
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
waitsFor(function () {
|
|
|
|
return controller.digesting === false;
|
|
|
|
});
|
2015-12-07 20:33:29 +00:00
|
|
|
|
2017-03-29 19:18:11 +00:00
|
|
|
runs(function () {
|
|
|
|
// Limit-based CSS classes should be available
|
|
|
|
expect(controller.getElements()[0].cssClass).toEqual("alarm-a");
|
|
|
|
});
|
|
|
|
});
|
2015-12-07 20:33:29 +00:00
|
|
|
});
|
2015-02-17 17:03:23 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-23 20:43:00 +00:00
|
|
|
);
|