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-11-26 02:30:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../../src/creation/CreateAction"],
|
|
|
|
function (CreateAction) {
|
|
|
|
|
|
|
|
describe("The create action", function () {
|
2014-11-26 04:26:37 +00:00
|
|
|
var mockType,
|
|
|
|
mockParent,
|
|
|
|
mockContext,
|
2016-05-24 17:23:48 +00:00
|
|
|
mockDomainObject,
|
|
|
|
capabilities = {},
|
|
|
|
mockEditAction,
|
|
|
|
mockSaveAction,
|
2014-11-26 04:26:37 +00:00
|
|
|
action;
|
|
|
|
|
|
|
|
function mockPromise(value) {
|
|
|
|
return {
|
|
|
|
then: function (callback) {
|
|
|
|
return mockPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockType = jasmine.createSpyObj(
|
|
|
|
"type",
|
|
|
|
[
|
|
|
|
"getKey",
|
|
|
|
"getGlyph",
|
|
|
|
"getName",
|
|
|
|
"getDescription",
|
|
|
|
"getProperties",
|
|
|
|
"getInitialModel"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockParent = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[
|
|
|
|
"getId",
|
|
|
|
"getModel",
|
2016-05-24 17:23:48 +00:00
|
|
|
"getCapability",
|
|
|
|
"useCapability"
|
2014-11-26 04:26:37 +00:00
|
|
|
]
|
|
|
|
);
|
2016-05-24 17:23:48 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[
|
|
|
|
"getId",
|
|
|
|
"getModel",
|
|
|
|
"getCapability",
|
|
|
|
"hasCapability",
|
|
|
|
"useCapability"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockDomainObject.hasCapability.andCallFake(function (name) {
|
2016-05-25 19:10:39 +00:00
|
|
|
return !!capabilities[name];
|
2016-05-24 17:23:48 +00:00
|
|
|
});
|
|
|
|
mockDomainObject.getCapability.andCallFake(function (name) {
|
2016-05-25 19:10:39 +00:00
|
|
|
return capabilities[name];
|
2016-05-24 17:23:48 +00:00
|
|
|
});
|
|
|
|
mockSaveAction = jasmine.createSpyObj(
|
|
|
|
"saveAction",
|
|
|
|
[
|
|
|
|
"perform"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
capabilities.action = jasmine.createSpyObj(
|
|
|
|
"actionCapability",
|
|
|
|
[
|
|
|
|
"getActions",
|
|
|
|
"perform"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
capabilities.editor = jasmine.createSpyObj(
|
|
|
|
"editorCapability",
|
|
|
|
[
|
|
|
|
"edit",
|
|
|
|
"save",
|
|
|
|
"cancel"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
mockEditAction = jasmine.createSpyObj(
|
|
|
|
"editAction",
|
|
|
|
[
|
|
|
|
"perform"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2014-11-26 04:26:37 +00:00
|
|
|
mockContext = {
|
|
|
|
domainObject: mockParent
|
|
|
|
};
|
2016-05-24 17:23:48 +00:00
|
|
|
mockParent.useCapability.andReturn(mockDomainObject);
|
2014-11-26 04:26:37 +00:00
|
|
|
|
|
|
|
mockType.getKey.andReturn("test");
|
|
|
|
mockType.getGlyph.andReturn("T");
|
|
|
|
mockType.getDescription.andReturn("a test type");
|
|
|
|
mockType.getName.andReturn("Test");
|
|
|
|
mockType.getProperties.andReturn([]);
|
|
|
|
mockType.getInitialModel.andReturn({});
|
|
|
|
|
|
|
|
action = new CreateAction(
|
|
|
|
mockType,
|
|
|
|
mockParent,
|
2016-05-24 17:23:48 +00:00
|
|
|
mockContext
|
2014-11-26 04:26:37 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("exposes type-appropriate metadata", function () {
|
|
|
|
var metadata = action.getMetadata();
|
|
|
|
|
|
|
|
expect(metadata.name).toEqual("Test");
|
|
|
|
expect(metadata.description).toEqual("a test type");
|
|
|
|
expect(metadata.glyph).toEqual("T");
|
|
|
|
});
|
|
|
|
|
2016-05-24 17:23:48 +00:00
|
|
|
describe("the perform function", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
capabilities.action.getActions.andReturn([mockEditAction]);
|
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2016-05-24 17:23:48 +00:00
|
|
|
it("uses the instantiation capability when performed", function () {
|
|
|
|
action.perform();
|
|
|
|
expect(mockParent.useCapability).toHaveBeenCalledWith("instantiation", jasmine.any(Object));
|
2014-11-26 04:26:37 +00:00
|
|
|
});
|
|
|
|
|
2016-05-24 17:23:48 +00:00
|
|
|
it("uses the edit action if available", function () {
|
|
|
|
action.perform();
|
|
|
|
expect(mockEditAction.perform).toHaveBeenCalled();
|
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2016-05-24 17:23:48 +00:00
|
|
|
it("uses the save action if object does not have an edit action" +
|
|
|
|
" available", function () {
|
|
|
|
capabilities.action.getActions.andReturn([]);
|
|
|
|
capabilities.action.perform.andReturn(mockPromise(undefined));
|
|
|
|
action.perform();
|
|
|
|
expect(capabilities.action.perform).toHaveBeenCalledWith("save");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("uses to editor capability", function () {
|
|
|
|
var promise = jasmine.createSpyObj("promise", ["then"]);
|
2016-05-25 19:10:39 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
capabilities.action.getActions.andReturn([]);
|
|
|
|
capabilities.action.perform.andReturn(promise);
|
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2016-05-24 17:23:48 +00:00
|
|
|
it("to save the edit if user saves dialog", function () {
|
|
|
|
action.perform();
|
|
|
|
expect(promise.then).toHaveBeenCalled();
|
|
|
|
promise.then.mostRecentCall.args[0]();
|
|
|
|
expect(capabilities.editor.save).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("to cancel the edit if user cancels dialog", function () {
|
|
|
|
action.perform();
|
|
|
|
promise.then.mostRecentCall.args[1]();
|
|
|
|
expect(capabilities.editor.cancel).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
});
|
2014-11-26 02:30:30 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|