2015-11-05 20:45:51 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open MCT Web, Copyright (c) 2009-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.
|
|
|
|
*****************************************************************************/
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
['../../../src/controllers/swimlane/TimelineSwimlaneDropHandler'],
|
|
|
|
function (TimelineSwimlaneDropHandler) {
|
|
|
|
|
|
|
|
describe("A timeline's swimlane drop handler", function () {
|
|
|
|
var mockSwimlane,
|
|
|
|
mockOtherObject,
|
|
|
|
mockActionCapability,
|
2016-05-12 23:14:31 +00:00
|
|
|
mockEditorCapability,
|
2015-09-14 23:45:38 +00:00
|
|
|
mockPersistence,
|
2016-03-22 23:59:09 +00:00
|
|
|
mockContext,
|
|
|
|
mockAction,
|
2015-09-14 23:45:38 +00:00
|
|
|
handler;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2016-03-22 23:59:09 +00:00
|
|
|
var mockPromise = jasmine.createSpyObj('promise', ['then']);
|
|
|
|
|
2016-05-12 23:14:31 +00:00
|
|
|
mockEditorCapability = jasmine.createSpyObj('editorCapability', ['inEditContext']);
|
|
|
|
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane = jasmine.createSpyObj(
|
|
|
|
"swimlane",
|
2016-05-19 18:29:13 +00:00
|
|
|
["highlight", "highlightBottom"]
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
// domainObject, idPath, children, expanded
|
|
|
|
mockSwimlane.domainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-05-19 18:29:13 +00:00
|
|
|
["getId", "getCapability", "useCapability", "hasCapability"]
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
2016-05-19 18:29:13 +00:00
|
|
|
mockSwimlane.idPath = ['a', 'b'];
|
|
|
|
mockSwimlane.children = [{}];
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.expanded = true;
|
|
|
|
|
|
|
|
mockSwimlane.parent = {};
|
|
|
|
mockSwimlane.parent.idPath = ['a'];
|
|
|
|
mockSwimlane.parent.domainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-05-19 18:29:13 +00:00
|
|
|
["getId", "getCapability", "useCapability", "hasCapability"]
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
2016-05-19 18:29:13 +00:00
|
|
|
mockSwimlane.parent.children = [mockSwimlane];
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
mockSwimlane.children[0].domainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-05-19 18:29:13 +00:00
|
|
|
["getId", "getCapability", "useCapability", "hasCapability"]
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
|
2016-03-22 23:59:09 +00:00
|
|
|
mockAction = jasmine.createSpyObj('action', ['perform']);
|
|
|
|
mockAction.perform.andReturn(mockPromise);
|
|
|
|
mockPromise.then.andCallFake(function (callback) {
|
|
|
|
callback();
|
|
|
|
});
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
mockOtherObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-05-19 18:29:13 +00:00
|
|
|
["getId", "getCapability", "useCapability", "hasCapability"]
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
mockActionCapability = jasmine.createSpyObj("action", ["perform", "getActions"]);
|
|
|
|
mockPersistence = jasmine.createSpyObj("persistence", ["persist"]);
|
2016-05-19 18:29:13 +00:00
|
|
|
mockContext = jasmine.createSpyObj('context', ['getParent']);
|
2015-09-14 23:45:38 +00:00
|
|
|
|
2016-03-22 23:59:09 +00:00
|
|
|
mockActionCapability.getActions.andReturn([mockAction]);
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.parent.domainObject.getId.andReturn('a');
|
|
|
|
mockSwimlane.domainObject.getId.andReturn('b');
|
|
|
|
mockSwimlane.children[0].domainObject.getId.andReturn('c');
|
|
|
|
mockOtherObject.getId.andReturn('d');
|
|
|
|
|
2016-03-22 23:59:09 +00:00
|
|
|
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.domainObject.getCapability.andCallFake(function (c) {
|
|
|
|
return {
|
|
|
|
action: mockActionCapability,
|
2016-05-12 23:14:31 +00:00
|
|
|
persistence: mockPersistence,
|
|
|
|
editor: mockEditorCapability
|
2015-09-14 23:45:38 +00:00
|
|
|
}[c];
|
|
|
|
});
|
2016-03-22 23:59:09 +00:00
|
|
|
mockSwimlane.parent.domainObject.getCapability.andCallFake(function (c) {
|
|
|
|
return {
|
|
|
|
action: mockActionCapability,
|
2016-05-12 23:14:31 +00:00
|
|
|
persistence: mockPersistence,
|
|
|
|
editor: mockEditorCapability
|
2016-03-22 23:59:09 +00:00
|
|
|
}[c];
|
|
|
|
});
|
|
|
|
mockOtherObject.getCapability.andCallFake(function (c) {
|
|
|
|
return {
|
|
|
|
action: mockActionCapability,
|
2016-05-12 23:14:31 +00:00
|
|
|
context: mockContext,
|
|
|
|
editor: mockEditorCapability
|
2016-03-22 23:59:09 +00:00
|
|
|
}[c];
|
|
|
|
});
|
|
|
|
mockContext.getParent.andReturn(mockOtherObject);
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
mockSwimlane.domainObject.hasCapability.andReturn(true);
|
|
|
|
|
|
|
|
handler = new TimelineSwimlaneDropHandler(mockSwimlane);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("disallows drop outside of edit mode", function () {
|
2016-05-12 23:14:31 +00:00
|
|
|
mockEditorCapability.inEditContext.andReturn(true);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Verify precondition
|
2016-03-22 23:59:09 +00:00
|
|
|
expect(handler.allowDropIn('d', mockSwimlane.domainObject))
|
|
|
|
.toBeTruthy();
|
|
|
|
expect(handler.allowDropAfter('d', mockSwimlane.domainObject))
|
|
|
|
.toBeTruthy();
|
2015-09-14 23:45:38 +00:00
|
|
|
// Act as if we're not in edit mode
|
2016-05-12 23:14:31 +00:00
|
|
|
mockEditorCapability.inEditContext.andReturn(false);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Now, they should be disallowed
|
2016-03-22 23:59:09 +00:00
|
|
|
expect(handler.allowDropIn('d', mockSwimlane.domainObject))
|
|
|
|
.toBeFalsy();
|
|
|
|
expect(handler.allowDropAfter('d', mockSwimlane.domainObject))
|
|
|
|
.toBeFalsy();
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
// Verify that editor capability was really checked for
|
|
|
|
expect(mockSwimlane.domainObject.hasCapability)
|
|
|
|
.toHaveBeenCalledWith('editor');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("disallows dropping of parents", function () {
|
2016-03-22 23:59:09 +00:00
|
|
|
var mockParent = mockSwimlane.parent.domainObject;
|
|
|
|
expect(handler.allowDropIn('a', mockParent)).toBeFalsy();
|
|
|
|
expect(handler.allowDropAfter('a', mockParent)).toBeFalsy();
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does not drop when no highlight state is present", function () {
|
|
|
|
// If there's no hover highlight, there's no drop allowed
|
|
|
|
handler.drop('d', mockOtherObject);
|
|
|
|
expect(mockOtherObject.getCapability)
|
|
|
|
.not.toHaveBeenCalled();
|
|
|
|
expect(mockSwimlane.domainObject.useCapability)
|
|
|
|
.not.toHaveBeenCalled();
|
|
|
|
expect(mockSwimlane.parent.domainObject.useCapability)
|
|
|
|
.not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("inserts into when highlighted", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testModel = { composition: ['c'] };
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.highlight.andReturn(true);
|
2016-03-22 23:59:09 +00:00
|
|
|
handler.drop('d', mockOtherObject);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Should have mutated
|
|
|
|
expect(mockSwimlane.domainObject.useCapability)
|
|
|
|
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
|
|
|
// Run the mutator
|
|
|
|
mockSwimlane.domainObject.useCapability.mostRecentCall
|
|
|
|
.args[1](testModel);
|
|
|
|
expect(testModel.composition).toEqual(['c', 'd']);
|
|
|
|
// Finally, should also have persisted
|
|
|
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("inserts after as a peer when highlighted at the bottom", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testModel = { composition: ['x', 'b', 'y'] };
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.highlightBottom.andReturn(true);
|
|
|
|
mockSwimlane.expanded = false;
|
2016-03-22 23:59:09 +00:00
|
|
|
handler.drop('d', mockOtherObject);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Should have mutated
|
|
|
|
expect(mockSwimlane.parent.domainObject.useCapability)
|
|
|
|
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
|
|
|
// Run the mutator
|
|
|
|
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
|
|
|
|
.args[1](testModel);
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("inserts into when highlighted at the bottom and expanded", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testModel = { composition: ['c'] };
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.highlightBottom.andReturn(true);
|
|
|
|
mockSwimlane.expanded = true;
|
2016-03-22 23:59:09 +00:00
|
|
|
handler.drop('d', mockOtherObject);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Should have mutated
|
|
|
|
expect(mockSwimlane.domainObject.useCapability)
|
|
|
|
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
|
|
|
// Run the mutator
|
|
|
|
mockSwimlane.domainObject.useCapability.mostRecentCall
|
|
|
|
.args[1](testModel);
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(testModel.composition).toEqual(['d', 'c']);
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("inserts after as a peer when highlighted at the bottom and childless", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testModel = { composition: ['x', 'b', 'y'] };
|
2015-09-14 23:45:38 +00:00
|
|
|
mockSwimlane.highlightBottom.andReturn(true);
|
|
|
|
mockSwimlane.expanded = true;
|
|
|
|
mockSwimlane.children = [];
|
2016-03-22 23:59:09 +00:00
|
|
|
handler.drop('d', mockOtherObject);
|
2015-09-14 23:45:38 +00:00
|
|
|
// Should have mutated
|
|
|
|
expect(mockSwimlane.parent.domainObject.useCapability)
|
|
|
|
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
|
|
|
// Run the mutator
|
|
|
|
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
|
|
|
|
.args[1](testModel);
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
|
2016-03-23 00:06:58 +00:00
|
|
|
it("allows reordering within a parent", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testModel = { composition: ['x', 'b', 'y', 'd'] };
|
2016-03-30 02:41:43 +00:00
|
|
|
|
2016-03-23 00:06:58 +00:00
|
|
|
mockSwimlane.highlightBottom.andReturn(true);
|
|
|
|
mockSwimlane.expanded = true;
|
|
|
|
mockSwimlane.children = [];
|
|
|
|
mockContext.getParent
|
|
|
|
.andReturn(mockSwimlane.parent.domainObject);
|
|
|
|
handler.drop('d', mockOtherObject);
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return mockSwimlane.parent.domainObject.useCapability
|
|
|
|
.calls.length > 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
|
|
|
|
.args[1](testModel);
|
2016-05-19 18:29:13 +00:00
|
|
|
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
|
2016-03-23 00:06:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-30 02:41:43 +00:00
|
|
|
it("does not invoke an action when reordering", function () {
|
|
|
|
mockSwimlane.highlightBottom.andReturn(true);
|
|
|
|
mockSwimlane.expanded = true;
|
|
|
|
mockSwimlane.children = [];
|
|
|
|
mockContext.getParent
|
|
|
|
.andReturn(mockSwimlane.parent.domainObject);
|
|
|
|
handler.drop('d', mockOtherObject);
|
|
|
|
expect(mockAction.perform).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
}
|
2016-03-22 23:59:09 +00:00
|
|
|
);
|