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.
|
|
|
|
*****************************************************************************/
|
2014-12-05 23:39:07 +00:00
|
|
|
|
|
|
|
define(
|
2017-12-07 21:04:46 +00:00
|
|
|
[
|
|
|
|
"../src/LayoutController",
|
|
|
|
"zepto"
|
|
|
|
],
|
|
|
|
function (
|
|
|
|
LayoutController,
|
|
|
|
$
|
|
|
|
) {
|
2014-12-05 23:39:07 +00:00
|
|
|
|
|
|
|
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,
|
2015-11-24 21:05:00 +00:00
|
|
|
controller,
|
|
|
|
mockCompositionCapability,
|
2015-11-26 02:53:37 +00:00
|
|
|
mockComposition,
|
2017-12-07 21:04:46 +00:00
|
|
|
mockCompositionObjects,
|
|
|
|
mockOpenMCT,
|
|
|
|
mockSelection,
|
|
|
|
mockDomainObjectCapability,
|
|
|
|
$element = [],
|
|
|
|
selectable = [];
|
2015-11-24 21:05:00 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
function mockPromise(value) {
|
2015-11-24 21:05:00 +00:00
|
|
|
return {
|
|
|
|
then: function (thenFunc) {
|
|
|
|
return mockPromise(thenFunc(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
function mockDomainObject(id) {
|
2015-11-24 21:05:00 +00:00
|
|
|
return {
|
2016-05-19 18:29:13 +00:00
|
|
|
getId: function () {
|
2015-11-24 21:05:00 +00:00
|
|
|
return id;
|
|
|
|
},
|
2016-05-19 18:29:13 +00:00
|
|
|
useCapability: function () {
|
2015-11-24 21:05:00 +00:00
|
|
|
return mockCompositionCapability;
|
2017-08-18 23:28:41 +00:00
|
|
|
},
|
|
|
|
getModel: function () {
|
|
|
|
if (id === 'b') {
|
|
|
|
return {
|
|
|
|
type : 'hyperlink'
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {};
|
|
|
|
}
|
2017-12-07 21:04:46 +00:00
|
|
|
},
|
|
|
|
getCapability: function () {
|
|
|
|
return mockDomainObjectCapability;
|
|
|
|
},
|
|
|
|
hasCapability: function (param) {
|
|
|
|
if (param === 'composition') {
|
|
|
|
return id !== 'b';
|
|
|
|
}
|
2015-11-24 21:05:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2014-12-06 00:53:53 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
2016-05-19 18:29:13 +00:00
|
|
|
["$watch", "$watchCollection", "$on", "commit"]
|
2014-12-06 00:53:53 +00:00
|
|
|
);
|
2015-06-25 18:35:18 +00:00
|
|
|
mockEvent = jasmine.createSpyObj(
|
|
|
|
'event',
|
2017-08-18 23:28:41 +00:00
|
|
|
['preventDefault', 'stopPropagation']
|
2015-06-25 18:35:18 +00:00
|
|
|
);
|
2014-12-06 00:53:53 +00:00
|
|
|
|
2015-11-24 21:05:00 +00:00
|
|
|
testModel = {};
|
|
|
|
|
|
|
|
mockComposition = ["a", "b", "c"];
|
2015-11-26 02:53:37 +00:00
|
|
|
mockCompositionObjects = mockComposition.map(mockDomainObject);
|
2014-12-06 00:53:53 +00:00
|
|
|
|
|
|
|
testConfiguration = {
|
|
|
|
panels: {
|
|
|
|
a: {
|
|
|
|
position: [20, 10],
|
|
|
|
dimensions: [5, 5]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-12-07 21:04:46 +00:00
|
|
|
mockDomainObjectCapability = jasmine.createSpyObj('capability',
|
|
|
|
['inEditContext']
|
|
|
|
);
|
2015-11-26 02:53:37 +00:00
|
|
|
mockCompositionCapability = mockPromise(mockCompositionObjects);
|
2015-11-24 21:05:00 +00:00
|
|
|
|
|
|
|
mockScope.domainObject = mockDomainObject("mockDomainObject");
|
2014-12-06 00:53:53 +00:00
|
|
|
mockScope.model = testModel;
|
|
|
|
mockScope.configuration = testConfiguration;
|
2017-12-07 21:04:46 +00:00
|
|
|
|
|
|
|
selectable[0] = {
|
|
|
|
context: {
|
|
|
|
oldItem: mockScope.domainObject
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mockSelection = jasmine.createSpyObj("selection", [
|
|
|
|
'select',
|
|
|
|
'on',
|
|
|
|
'off',
|
|
|
|
'get'
|
|
|
|
]);
|
|
|
|
mockSelection.get.andReturn(selectable);
|
|
|
|
mockOpenMCT = {
|
|
|
|
selection: mockSelection
|
|
|
|
};
|
|
|
|
|
|
|
|
$element = $('<div></div>');
|
|
|
|
$(document).find('body').append($element);
|
|
|
|
spyOn($element[0], 'click');
|
2017-08-18 23:28:41 +00:00
|
|
|
|
2015-11-24 21:05:00 +00:00
|
|
|
spyOn(mockScope.domainObject, "useCapability").andCallThrough();
|
2014-12-06 00:53:53 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
controller = new LayoutController(mockScope, $element, mockOpenMCT);
|
2015-11-24 21:05:00 +00:00
|
|
|
spyOn(controller, "layoutPanels").andCallThrough();
|
2017-08-18 23:28:41 +00:00
|
|
|
|
|
|
|
jasmine.Clock.useMock();
|
2014-12-06 00:53:53 +00:00
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
afterEach(function () {
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("listens for selection change events", function () {
|
|
|
|
expect(mockOpenMCT.selection.on).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("cleans up on scope destroy", function () {
|
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith(
|
|
|
|
'$destroy',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
|
|
|
mockScope.$on.calls[0].args[1]();
|
|
|
|
|
|
|
|
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-12-06 00:53:53 +00:00
|
|
|
// 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 () {
|
2015-11-24 21:05:00 +00:00
|
|
|
expect(mockScope.$watchCollection).toHaveBeenCalledWith(
|
2015-01-27 18:22:50 +00:00
|
|
|
"model.composition",
|
2014-12-06 00:53:53 +00:00
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-11-24 21:05:00 +00:00
|
|
|
it("Retrieves updated composition from composition capability", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
expect(mockScope.domainObject.useCapability).toHaveBeenCalledWith(
|
|
|
|
"composition"
|
|
|
|
);
|
|
|
|
expect(controller.layoutPanels).toHaveBeenCalledWith(
|
|
|
|
mockComposition
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-11-26 02:53:37 +00:00
|
|
|
it("Is robust to concurrent changes to composition", function () {
|
|
|
|
var secondMockComposition = ["a", "b", "c", "d"],
|
|
|
|
secondMockCompositionObjects = secondMockComposition.map(mockDomainObject),
|
|
|
|
firstCompositionCB,
|
|
|
|
secondCompositionCB;
|
|
|
|
|
|
|
|
spyOn(mockCompositionCapability, "then");
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
|
|
|
|
firstCompositionCB = mockCompositionCapability.then.calls[0].args[0];
|
|
|
|
secondCompositionCB = mockCompositionCapability.then.calls[1].args[0];
|
|
|
|
|
|
|
|
//Resolve promises in reverse order
|
|
|
|
secondCompositionCB(secondMockCompositionObjects);
|
|
|
|
firstCompositionCB(mockCompositionObjects);
|
|
|
|
|
|
|
|
//Expect the promise call that was initiated most recently to
|
|
|
|
// be the one used to populate scope, irrespective of order that
|
|
|
|
// it was eventually resolved
|
|
|
|
expect(mockScope.composition).toBe(secondMockCompositionObjects);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-12-06 00:53:53 +00:00
|
|
|
it("provides styles for frames, from configuration", function () {
|
2015-11-24 21:05:00 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
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-11-24 21:05:00 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
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-11-24 21:05:00 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
2014-12-06 00:53:53 +00:00
|
|
|
|
2016-09-03 13:16:54 +00:00
|
|
|
// Verify precondition
|
2014-12-06 00:53:53 +00:00
|
|
|
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-11-24 21:05:00 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
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
|
|
|
|
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
|
|
|
|
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 () {
|
2016-03-04 20:56:14 +00:00
|
|
|
var styleB;
|
2015-08-03 19:18:49 +00:00
|
|
|
|
|
|
|
// Start with a very small frame size
|
2016-05-19 18:29:13 +00:00
|
|
|
testModel.layoutGrid = [1, 1];
|
2015-08-03 19:18:49 +00:00
|
|
|
|
|
|
|
// White-boxy; we know which watch is which
|
|
|
|
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
|
2015-11-24 21:05:00 +00:00
|
|
|
mockScope.$watchCollection.calls[0].args[1](testModel.composition);
|
2015-08-03 19:18:49 +00:00
|
|
|
|
|
|
|
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
|
2016-05-19 18:29:13 +00:00
|
|
|
testModel.layoutGrid = [1, 1];
|
2015-11-10 01:48:58 +00:00
|
|
|
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
|
|
|
|
|
|
|
|
// Notify that a drop occurred
|
|
|
|
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);
|
|
|
|
});
|
2015-12-08 23:04:34 +00:00
|
|
|
|
|
|
|
it("updates positions of existing objects on a drop", function () {
|
|
|
|
var oldStyle;
|
|
|
|
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
|
|
|
|
oldStyle = controller.getFrameStyle("b");
|
|
|
|
|
|
|
|
expect(oldStyle).toBeDefined();
|
|
|
|
|
|
|
|
// ...drop event...
|
|
|
|
mockScope.$on.mostRecentCall
|
|
|
|
.args[1](mockEvent, 'b', { x: 300, y: 100 });
|
|
|
|
|
|
|
|
expect(controller.getFrameStyle("b"))
|
|
|
|
.not.toEqual(oldStyle);
|
|
|
|
});
|
2017-08-18 23:28:41 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("allows objects to be selected", function () {
|
2017-08-18 23:28:41 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[0];
|
2017-12-07 21:04:46 +00:00
|
|
|
selectable[0].context.oldItem = childObj;
|
|
|
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
2017-08-18 23:28:41 +00:00
|
|
|
|
|
|
|
expect(controller.selected(childObj)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("prevents event bubbling while drag is in progress", function () {
|
2017-08-18 23:28:41 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[0];
|
|
|
|
|
|
|
|
// Do a drag
|
2017-12-07 21:04:46 +00:00
|
|
|
controller.startDrag(childObj.getId(), [1, 1], [0, 0]);
|
2017-08-18 23:28:41 +00:00
|
|
|
controller.continueDrag([100, 100]);
|
|
|
|
controller.endDrag();
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
// Because mouse position could cause the parent object to be selected, this should be ignored.
|
|
|
|
controller.bypassSelection(mockEvent);
|
2017-08-18 23:28:41 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
expect(mockEvent.stopPropagation).toHaveBeenCalled();
|
2017-08-18 23:28:41 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
// Shoud be able to select another object when dragging is done.
|
2017-08-18 23:28:41 +00:00
|
|
|
jasmine.Clock.tick(0);
|
2017-12-07 21:04:46 +00:00
|
|
|
mockEvent.stopPropagation.reset();
|
|
|
|
controller.bypassSelection(mockEvent);
|
2017-08-18 23:28:41 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
expect(mockEvent.stopPropagation).not.toHaveBeenCalled();
|
2017-08-18 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("shows frames by default", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
|
|
|
|
expect(controller.hasFrame(mockCompositionObjects[0])).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hyperlinks hide frame by default", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
|
|
|
|
expect(controller.hasFrame(mockCompositionObjects[1])).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides frame when selected object has frame ", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[0];
|
2017-12-07 21:04:46 +00:00
|
|
|
selectable[0].context.oldItem = childObj;
|
|
|
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
|
|
|
var toolbarObj = controller.getToolbar(childObj.getId(), childObj);
|
2017-08-18 23:28:41 +00:00
|
|
|
|
|
|
|
expect(controller.hasFrame(childObj)).toBe(true);
|
2017-12-07 21:04:46 +00:00
|
|
|
expect(toolbarObj.hideFrame).toBeDefined();
|
|
|
|
expect(toolbarObj.hideFrame).toEqual(jasmine.any(Function));
|
2017-08-18 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("shows frame when selected object has no frame", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[1];
|
2017-12-07 21:04:46 +00:00
|
|
|
selectable[0].context.oldItem = childObj;
|
|
|
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
|
|
|
var toolbarObj = controller.getToolbar(childObj.getId(), childObj);
|
2017-08-18 23:28:41 +00:00
|
|
|
|
|
|
|
expect(controller.hasFrame(childObj)).toBe(false);
|
2017-12-07 21:04:46 +00:00
|
|
|
expect(toolbarObj.showFrame).toBeDefined();
|
|
|
|
expect(toolbarObj.showFrame).toEqual(jasmine.any(Function));
|
2017-08-18 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("selects the parent object when selected object is removed", function () {
|
2017-10-02 20:49:12 +00:00
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[0];
|
2017-12-07 21:04:46 +00:00
|
|
|
selectable[0].context.oldItem = childObj;
|
|
|
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
2017-10-02 20:49:12 +00:00
|
|
|
|
|
|
|
var composition = ["b", "c"];
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1](composition);
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
expect($element[0].click).toHaveBeenCalled();
|
2017-10-02 20:49:12 +00:00
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("allows objects to be drilled-in only when editing", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[0];
|
|
|
|
childObj.getCapability().inEditContext.andReturn(false);
|
|
|
|
controller.drill(mockEvent, childObj);
|
|
|
|
|
|
|
|
expect(controller.isDrilledIn(childObj)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows objects to be drilled-in only if it has sub objects", function () {
|
|
|
|
mockScope.$watchCollection.mostRecentCall.args[1]();
|
|
|
|
var childObj = mockCompositionObjects[1];
|
|
|
|
childObj.getCapability().inEditContext.andReturn(true);
|
|
|
|
controller.drill(mockEvent, childObj);
|
|
|
|
|
|
|
|
expect(controller.isDrilledIn(childObj)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selects a newly-dropped object", function () {
|
|
|
|
mockScope.$on.mostRecentCall.args[1](
|
|
|
|
mockEvent,
|
|
|
|
'd',
|
|
|
|
{ x: 300, y: 100 }
|
|
|
|
);
|
|
|
|
|
|
|
|
var childObj = mockDomainObject("d");
|
2017-12-20 21:32:07 +00:00
|
|
|
var testElement = $("<div data-layout-id='some-id'></div>");
|
2017-12-07 21:04:46 +00:00
|
|
|
$element.append(testElement);
|
|
|
|
spyOn(testElement[0], 'click');
|
|
|
|
|
2017-12-20 21:32:07 +00:00
|
|
|
controller.selectIfNew('some-id', childObj);
|
2017-12-07 21:04:46 +00:00
|
|
|
jasmine.Clock.tick(0);
|
|
|
|
|
|
|
|
expect(testElement[0].click).toHaveBeenCalled();
|
|
|
|
});
|
2014-12-05 23:39:07 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-25 18:35:18 +00:00
|
|
|
);
|