2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2016, 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-04-11 00:37:11 +00:00
|
|
|
|
|
|
|
define(
|
2016-05-13 20:45:14 +00:00
|
|
|
["../../src/actions/EditAndComposeAction"],
|
|
|
|
function (EditAndComposeAction) {
|
2015-04-11 00:37:11 +00:00
|
|
|
|
|
|
|
describe("The Link action", function () {
|
|
|
|
var mockQ,
|
|
|
|
mockDomainObject,
|
|
|
|
mockParent,
|
|
|
|
mockContext,
|
2015-09-02 16:37:26 +00:00
|
|
|
mockComposition,
|
2015-04-11 00:37:11 +00:00
|
|
|
mockPersistence,
|
2016-05-13 20:45:14 +00:00
|
|
|
mockActionCapability,
|
2016-05-20 17:23:05 +00:00
|
|
|
mockEditAction,
|
2015-04-11 00:37:11 +00:00
|
|
|
mockType,
|
|
|
|
actionContext,
|
|
|
|
model,
|
|
|
|
capabilities,
|
|
|
|
action;
|
|
|
|
|
|
|
|
function mockPromise(value) {
|
|
|
|
return {
|
|
|
|
then: function (callback) {
|
|
|
|
return mockPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
|
|
|
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-05-19 18:29:13 +00:00
|
|
|
["getId", "getCapability"]
|
2015-04-11 00:37:11 +00:00
|
|
|
);
|
|
|
|
mockQ = { when: mockPromise };
|
|
|
|
mockParent = {
|
|
|
|
getModel: function () {
|
|
|
|
return model;
|
|
|
|
},
|
|
|
|
getCapability: function (k) {
|
|
|
|
return capabilities[k];
|
|
|
|
},
|
|
|
|
useCapability: function (k, v) {
|
|
|
|
return capabilities[k].invoke(v);
|
|
|
|
}
|
|
|
|
};
|
2016-05-20 20:09:16 +00:00
|
|
|
mockContext = jasmine.createSpyObj("context", ["getParent"]);
|
|
|
|
mockComposition = jasmine.createSpyObj("composition", ["invoke", "add"]);
|
|
|
|
mockPersistence = jasmine.createSpyObj("persistence", ["persist"]);
|
|
|
|
mockType = jasmine.createSpyObj("type", ["hasFeature", "getKey"]);
|
|
|
|
mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]);
|
2016-05-20 17:23:05 +00:00
|
|
|
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
|
2015-04-11 00:37:11 +00:00
|
|
|
|
|
|
|
mockDomainObject.getId.andReturn("test");
|
|
|
|
mockDomainObject.getCapability.andReturn(mockContext);
|
|
|
|
mockContext.getParent.andReturn(mockParent);
|
|
|
|
mockType.hasFeature.andReturn(true);
|
2016-05-13 20:45:14 +00:00
|
|
|
mockType.getKey.andReturn("layout");
|
2015-09-02 16:37:26 +00:00
|
|
|
mockComposition.invoke.andReturn(mockPromise(true));
|
|
|
|
mockComposition.add.andReturn(mockPromise(true));
|
2016-05-20 17:23:05 +00:00
|
|
|
mockActionCapability.getActions.andReturn([]);
|
2015-04-11 00:37:11 +00:00
|
|
|
|
|
|
|
capabilities = {
|
2015-09-02 16:37:26 +00:00
|
|
|
composition: mockComposition,
|
2015-04-11 00:37:11 +00:00
|
|
|
persistence: mockPersistence,
|
2016-05-13 20:45:14 +00:00
|
|
|
action: mockActionCapability,
|
2015-04-11 00:37:11 +00:00
|
|
|
type: mockType
|
|
|
|
};
|
|
|
|
model = {
|
2016-05-19 18:29:13 +00:00
|
|
|
composition: ["a", "b", "c"]
|
2015-04-11 00:37:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
actionContext = {
|
|
|
|
domainObject: mockParent,
|
|
|
|
selectedObject: mockDomainObject
|
|
|
|
};
|
|
|
|
|
2016-05-13 20:45:14 +00:00
|
|
|
action = new EditAndComposeAction(actionContext);
|
2015-04-11 00:37:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-09-02 16:37:26 +00:00
|
|
|
it("adds to the parent's composition when performed", function () {
|
2015-04-11 00:37:11 +00:00
|
|
|
action.perform();
|
2015-09-02 16:37:26 +00:00
|
|
|
expect(mockComposition.add)
|
|
|
|
.toHaveBeenCalledWith(mockDomainObject);
|
2015-04-11 00:37:11 +00:00
|
|
|
});
|
|
|
|
|
2015-09-02 16:37:26 +00:00
|
|
|
it("persists changes afterward", function () {
|
2015-04-11 00:37:11 +00:00
|
|
|
action.perform();
|
|
|
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2016-05-20 17:23:05 +00:00
|
|
|
it("enables edit mode for objects that have an edit action", function () {
|
|
|
|
mockActionCapability.getActions.andReturn([mockEditAction]);
|
2016-05-13 20:45:14 +00:00
|
|
|
action.perform();
|
2016-05-20 17:23:05 +00:00
|
|
|
expect(mockEditAction.perform).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Does not enable edit mode for objects that do not have an" +
|
|
|
|
" edit action", function () {
|
|
|
|
mockActionCapability.getActions.andReturn([]);
|
|
|
|
action.perform();
|
|
|
|
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
|
|
|
expect(mockComposition.add)
|
|
|
|
.toHaveBeenCalledWith(mockDomainObject);
|
2016-05-13 20:45:14 +00:00
|
|
|
});
|
|
|
|
|
2015-04-11 00:37:11 +00:00
|
|
|
});
|
|
|
|
}
|
2015-09-02 16:37:26 +00:00
|
|
|
);
|