2015-05-13 23:42:35 +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.
|
|
|
|
*****************************************************************************/
|
2014-12-05 23:39:07 +00:00
|
|
|
/*global define,describe,it,expect,beforeEach,jasmine*/
|
|
|
|
|
|
|
|
define(
|
|
|
|
["../src/LayoutController"],
|
|
|
|
function (LayoutController) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("The Layout controller", function () {
|
2014-12-06 00:53:53 +00:00
|
|
|
var mockScope,
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent,
|
2014-12-06 00:53:53 +00:00
|
|
|
testModel,
|
|
|
|
testConfiguration,
|
|
|
|
controller;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
2015-02-17 18:50:02 +00:00
|
|
|
[ "$watch", "$on", "commit" ]
|
2014-12-06 00:53:53 +00:00
|
|
|
);
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent = jasmine.createSpyObj(
|
|
|
|
'event',
|
2015-06-26 18:53:45 +00:00
|
|
|
[ 'preventDefault' ]
|
2015-06-25 18:35:18 +00:00
|
|
|
);
|
2014-12-06 00:53:53 +00:00
|
|
|
|
|
|
|
testModel = {
|
|
|
|
composition: [ "a", "b", "c" ]
|
|
|
|
};
|
|
|
|
|
|
|
|
testConfiguration = {
|
|
|
|
panels: {
|
|
|
|
a: {
|
|
|
|
position: [20, 10],
|
|
|
|
dimensions: [5, 5]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mockScope.model = testModel;
|
|
|
|
mockScope.configuration = testConfiguration;
|
|
|
|
|
|
|
|
controller = new LayoutController(mockScope);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Model changes will indicate that panel positions
|
|
|
|
// may have changed, for instance.
|
2015-01-27 18:22:50 +00:00
|
|
|
it("watches for changes to composition", function () {
|
2014-12-06 00:53:53 +00:00
|
|
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
2015-01-27 18:22:50 +00:00
|
|
|
"model.composition",
|
2014-12-06 00:53:53 +00:00
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("provides styles for frames, from configuration", function () {
|
2015-01-27 18:22:50 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](testModel.composition);
|
2014-12-06 00:53:53 +00:00
|
|
|
expect(controller.getFrameStyle("a")).toEqual({
|
|
|
|
top: "320px",
|
|
|
|
left: "640px",
|
|
|
|
width: "160px",
|
|
|
|
height: "160px"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("provides default styles for frames", function () {
|
|
|
|
var styleB, styleC;
|
|
|
|
|
|
|
|
// b and c do not have configured positions
|
2015-01-27 18:22:50 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](testModel.composition);
|
2014-12-06 00:53:53 +00:00
|
|
|
|
|
|
|
styleB = controller.getFrameStyle("b");
|
|
|
|
styleC = controller.getFrameStyle("c");
|
|
|
|
|
|
|
|
// Should have a position, but we don't care what
|
|
|
|
expect(styleB.left).toBeDefined();
|
|
|
|
expect(styleB.top).toBeDefined();
|
|
|
|
expect(styleC.left).toBeDefined();
|
|
|
|
expect(styleC.top).toBeDefined();
|
|
|
|
|
|
|
|
// Should have ensured some difference in position
|
|
|
|
expect(styleB).not.toEqual(styleC);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows panels to be dragged", function () {
|
|
|
|
// Populate scope
|
2015-01-27 18:22:50 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](testModel.composition);
|
2014-12-06 00:53:53 +00:00
|
|
|
|
|
|
|
// Verify precondtion
|
|
|
|
expect(testConfiguration.panels.b).not.toBeDefined();
|
|
|
|
|
|
|
|
// Do a drag
|
|
|
|
controller.startDrag("b", [1, 1], [0, 0]);
|
|
|
|
controller.continueDrag([100, 100]);
|
|
|
|
controller.endDrag();
|
|
|
|
|
|
|
|
// We do not look closely at the details here;
|
|
|
|
// that is tested in LayoutDragSpec. Just make sure
|
|
|
|
// that a configuration for b has been defined.
|
|
|
|
expect(testConfiguration.panels.b).toBeDefined();
|
|
|
|
});
|
2014-12-06 17:45:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
it("invokes commit after drag", function () {
|
|
|
|
// Populate scope
|
2015-01-27 18:22:50 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](testModel.composition);
|
2014-12-06 17:45:41 +00:00
|
|
|
|
|
|
|
// Do a drag
|
|
|
|
controller.startDrag("b", [1, 1], [0, 0]);
|
|
|
|
controller.continueDrag([100, 100]);
|
|
|
|
controller.endDrag();
|
|
|
|
|
|
|
|
// Should have triggered commit (provided by
|
|
|
|
// EditRepresenter) with some message.
|
|
|
|
expect(mockScope.commit)
|
|
|
|
.toHaveBeenCalledWith(jasmine.any(String));
|
|
|
|
});
|
2015-02-17 18:50:02 +00:00
|
|
|
|
|
|
|
it("listens for drop events", function () {
|
|
|
|
// 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
|
|
|
|
expect(testConfiguration.panels.d).not.toBeDefined();
|
|
|
|
|
|
|
|
// Notify that a drop occurred
|
|
|
|
testModel.composition.push('d');
|
|
|
|
mockScope.$on.mostRecentCall.args[1](
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent,
|
2015-02-17 18:50:02 +00:00
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
|
|
|
expect(testConfiguration.panels.d).toBeDefined();
|
2015-06-25 18:35:18 +00:00
|
|
|
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-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');
|
|
|
|
mockScope.$on.mostRecentCall.args[1](
|
|
|
|
mockEvent,
|
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
|
|
|
expect(testConfiguration.panels.d).not.toBeDefined();
|
|
|
|
});
|
2015-08-03 19:18:49 +00:00
|
|
|
|
|
|
|
it("ensures a minimum frame size", function () {
|
|
|
|
var styleB, styleC;
|
|
|
|
|
|
|
|
// Start with a very small frame size
|
|
|
|
testModel.layoutGrid = [ 1, 1 ];
|
|
|
|
|
|
|
|
// White-boxy; we know which watch is which
|
|
|
|
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
|
|
|
|
mockScope.$watch.calls[1].args[1](testModel.composition);
|
|
|
|
|
|
|
|
styleB = controller.getFrameStyle("b");
|
|
|
|
|
|
|
|
// Resulting size should still be reasonably large pixel-size
|
|
|
|
expect(parseInt(styleB.width, 10)).toBeGreaterThan(63);
|
|
|
|
expect(parseInt(styleB.width, 10)).toBeGreaterThan(31);
|
|
|
|
});
|
2015-11-10 01:48:58 +00:00
|
|
|
|
|
|
|
it("ensures a minimum frame size on drop", function () {
|
|
|
|
var style;
|
|
|
|
|
|
|
|
// Start with a very small frame size
|
|
|
|
testModel.layoutGrid = [ 1, 1 ];
|
|
|
|
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
|
|
|
|
|
|
|
|
// Notify that a drop occurred
|
|
|
|
testModel.composition.push('d');
|
|
|
|
mockScope.$on.mostRecentCall.args[1](
|
|
|
|
mockEvent,
|
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
|
|
|
mockScope.$watch.calls[0].args[1](['d']);
|
|
|
|
|
|
|
|
style = controller.getFrameStyle("d");
|
|
|
|
|
|
|
|
// Resulting size should still be reasonably large pixel-size
|
|
|
|
expect(parseInt(style.width, 10)).toBeGreaterThan(63);
|
|
|
|
expect(parseInt(style.height, 10)).toBeGreaterThan(31);
|
|
|
|
});
|
2014-12-05 23:39:07 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-25 18:35:18 +00:00
|
|
|
);
|