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.
|
|
|
|
*****************************************************************************/
|
2014-11-26 02:30:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../../src/creation/CreateActionProvider"],
|
|
|
|
function (CreateActionProvider) {
|
|
|
|
|
|
|
|
describe("The create action provider", function () {
|
2014-11-26 04:26:37 +00:00
|
|
|
var mockTypeService,
|
2015-12-02 19:28:49 +00:00
|
|
|
mockPolicyService,
|
|
|
|
mockCreationPolicy,
|
|
|
|
mockPolicyMap = {},
|
2015-01-22 00:24:13 +00:00
|
|
|
mockTypes,
|
2014-11-26 04:26:37 +00:00
|
|
|
provider;
|
2014-11-26 02:30:30 +00:00
|
|
|
|
2014-11-26 04:26:37 +00:00
|
|
|
function createMockType(name) {
|
|
|
|
var mockType = jasmine.createSpyObj(
|
|
|
|
"type" + name,
|
|
|
|
[
|
|
|
|
"getKey",
|
|
|
|
"getGlyph",
|
|
|
|
"getName",
|
|
|
|
"getDescription",
|
|
|
|
"getProperties",
|
2015-01-22 00:24:13 +00:00
|
|
|
"getInitialModel",
|
|
|
|
"hasFeature"
|
2014-11-26 04:26:37 +00:00
|
|
|
]
|
|
|
|
);
|
2015-01-22 00:24:13 +00:00
|
|
|
mockType.hasFeature.andReturn(true);
|
2014-11-26 04:26:37 +00:00
|
|
|
mockType.getName.andReturn(name);
|
|
|
|
return mockType;
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockTypeService = jasmine.createSpyObj(
|
|
|
|
"typeService",
|
2016-05-19 18:29:13 +00:00
|
|
|
["listTypes"]
|
2014-11-26 04:26:37 +00:00
|
|
|
);
|
2015-12-02 19:28:49 +00:00
|
|
|
mockPolicyService = jasmine.createSpyObj(
|
|
|
|
"policyService",
|
2016-05-19 18:29:13 +00:00
|
|
|
["allow"]
|
2015-12-02 19:28:49 +00:00
|
|
|
);
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockTypes = ["A", "B", "C"].map(createMockType);
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockTypes.forEach(function (type) {
|
2015-12-02 19:28:49 +00:00
|
|
|
mockPolicyMap[type.getName()] = true;
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockCreationPolicy = function (type) {
|
2015-12-02 19:28:49 +00:00
|
|
|
return mockPolicyMap[type.getName()];
|
|
|
|
};
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
mockPolicyService.allow.andCallFake(function (category, type) {
|
2015-12-02 19:28:49 +00:00
|
|
|
return category === "creation" && mockCreationPolicy(type) ? true : false;
|
|
|
|
});
|
|
|
|
|
2015-01-22 00:24:13 +00:00
|
|
|
mockTypeService.listTypes.andReturn(mockTypes);
|
2014-11-26 04:26:37 +00:00
|
|
|
|
|
|
|
provider = new CreateActionProvider(
|
|
|
|
mockTypeService,
|
2015-12-02 19:28:49 +00:00
|
|
|
mockPolicyService
|
2014-11-26 04:26:37 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-21 02:49:39 +00:00
|
|
|
it("exposes one create action per type", function () {
|
2014-11-26 04:26:37 +00:00
|
|
|
expect(provider.getActions({
|
|
|
|
key: "create",
|
|
|
|
domainObject: {}
|
|
|
|
}).length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("exposes no non-create actions", function () {
|
|
|
|
expect(provider.getActions({
|
|
|
|
key: "somethingElse",
|
|
|
|
domainObject: {}
|
|
|
|
}).length).toEqual(0);
|
|
|
|
});
|
2015-01-22 00:24:13 +00:00
|
|
|
|
2016-01-21 02:49:39 +00:00
|
|
|
it("does not expose non-creatable types", function () {
|
2015-01-22 00:24:13 +00:00
|
|
|
// One of the types won't have the creation feature...
|
2015-12-02 19:28:49 +00:00
|
|
|
mockPolicyMap[mockTypes[0].getName()] = false;
|
2015-01-22 00:24:13 +00:00
|
|
|
// ...so it should have been filtered out.
|
|
|
|
expect(provider.getActions({
|
|
|
|
key: "create",
|
|
|
|
domainObject: {}
|
|
|
|
}).length).toEqual(2);
|
|
|
|
// Make sure it was creation which was used to check
|
2015-12-02 19:28:49 +00:00
|
|
|
expect(mockPolicyService.allow)
|
|
|
|
.toHaveBeenCalledWith("creation", mockTypes[0]);
|
2015-01-22 00:24:13 +00:00
|
|
|
});
|
2014-11-26 02:30:30 +00:00
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|