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-25 01:01:37 +00:00
|
|
|
|
|
|
|
define(
|
2016-02-27 01:12:35 +00:00
|
|
|
["../../src/controllers/EditObjectController"],
|
|
|
|
function (EditObjectController) {
|
2014-11-25 01:01:37 +00:00
|
|
|
|
|
|
|
describe("The Edit mode controller", function () {
|
2014-11-25 01:29:42 +00:00
|
|
|
var mockScope,
|
|
|
|
mockObject,
|
2015-06-17 17:16:59 +00:00
|
|
|
mockType,
|
2016-02-27 01:12:35 +00:00
|
|
|
mockLocation,
|
|
|
|
mockStatusCapability,
|
|
|
|
mockCapabilities,
|
2016-03-01 01:22:13 +00:00
|
|
|
mockPolicyService,
|
2014-11-25 01:29:42 +00:00
|
|
|
controller;
|
|
|
|
|
2016-02-27 01:12:35 +00:00
|
|
|
// Utility function; look for a $watch on scope and fire it
|
|
|
|
function fireWatch(expr, value) {
|
|
|
|
mockScope.$watch.calls.forEach(function (call) {
|
|
|
|
if (call.args[0] === expr) {
|
|
|
|
call.args[1](value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-25 01:29:42 +00:00
|
|
|
beforeEach(function () {
|
2016-03-01 01:22:13 +00:00
|
|
|
mockPolicyService = jasmine.createSpyObj(
|
|
|
|
"policyService",
|
|
|
|
[
|
|
|
|
"allow"
|
|
|
|
]
|
|
|
|
);
|
2014-11-25 01:29:42 +00:00
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
2016-02-27 01:12:35 +00:00
|
|
|
[ "$on", "$watch" ]
|
2014-11-25 01:29:42 +00:00
|
|
|
);
|
|
|
|
mockObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2016-02-27 01:12:35 +00:00
|
|
|
[ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]
|
2014-11-25 01:29:42 +00:00
|
|
|
);
|
2015-06-17 17:16:59 +00:00
|
|
|
mockType = jasmine.createSpyObj(
|
|
|
|
"type",
|
|
|
|
[ "hasFeature" ]
|
2014-11-25 01:29:42 +00:00
|
|
|
);
|
2016-02-27 01:12:35 +00:00
|
|
|
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
|
|
|
["get"]
|
|
|
|
);
|
|
|
|
|
|
|
|
mockCapabilities = {
|
|
|
|
"type" : mockType,
|
|
|
|
"status": mockStatusCapability
|
|
|
|
};
|
|
|
|
|
|
|
|
mockLocation = jasmine.createSpyObj('$location',
|
|
|
|
["search"]
|
|
|
|
);
|
|
|
|
mockLocation.search.andReturn({"view": "fixed"});
|
2014-11-25 01:29:42 +00:00
|
|
|
|
|
|
|
mockObject.getId.andReturn("test");
|
|
|
|
mockObject.getModel.andReturn({ name: "Test object" });
|
2015-06-17 17:16:59 +00:00
|
|
|
mockObject.getCapability.andCallFake(function (key) {
|
2016-02-27 01:12:35 +00:00
|
|
|
return mockCapabilities[key];
|
2015-06-17 17:16:59 +00:00
|
|
|
});
|
|
|
|
mockType.hasFeature.andReturn(true);
|
2014-11-25 01:29:42 +00:00
|
|
|
|
2016-02-27 01:12:35 +00:00
|
|
|
mockScope.domainObject = mockObject;
|
2014-11-25 01:29:42 +00:00
|
|
|
|
2016-02-27 01:12:35 +00:00
|
|
|
controller = new EditObjectController(
|
|
|
|
mockScope,
|
2016-03-02 18:14:25 +00:00
|
|
|
mockLocation,
|
|
|
|
mockPolicyService
|
2014-11-25 01:29:42 +00:00
|
|
|
);
|
|
|
|
});
|
2014-11-25 01:01:37 +00:00
|
|
|
|
2015-03-31 22:58:13 +00:00
|
|
|
it("exposes a warning message for unload", function () {
|
2016-03-04 20:56:14 +00:00
|
|
|
var errorMessage = "Unsaved changes";
|
2015-03-31 22:58:13 +00:00
|
|
|
|
|
|
|
// Normally, should be undefined
|
|
|
|
expect(controller.getUnloadWarning()).toBeUndefined();
|
|
|
|
|
2016-03-02 18:14:25 +00:00
|
|
|
// Override the policy service to prevent navigation
|
|
|
|
mockPolicyService.allow.andCallFake(function(category, object, context, callback){
|
|
|
|
callback(errorMessage);
|
|
|
|
});
|
2015-03-31 22:58:13 +00:00
|
|
|
|
|
|
|
// Should have some warning message here now
|
2016-03-02 18:14:25 +00:00
|
|
|
expect(controller.getUnloadWarning()).toEqual(errorMessage);
|
2015-03-31 22:58:13 +00:00
|
|
|
});
|
|
|
|
|
2016-02-27 01:12:35 +00:00
|
|
|
|
|
|
|
it("sets the active view from query parameters", function () {
|
|
|
|
var testViews = [
|
|
|
|
{ key: 'abc' },
|
|
|
|
{ key: 'def', someKey: 'some value' },
|
|
|
|
{ key: 'xyz' }
|
|
|
|
];
|
|
|
|
|
|
|
|
mockObject.useCapability.andCallFake(function (c) {
|
|
|
|
return (c === 'view') && testViews;
|
|
|
|
});
|
|
|
|
mockLocation.search.andReturn({ view: 'def' });
|
|
|
|
|
|
|
|
fireWatch('domainObject', mockObject);
|
|
|
|
expect(mockScope.representation.selected)
|
|
|
|
.toEqual(testViews[1]);
|
|
|
|
});
|
|
|
|
|
2014-11-25 01:01:37 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-17 17:16:59 +00:00
|
|
|
);
|