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
|
|
|
/*global define,describe,it,expect,beforeEach,jasmine*/
|
|
|
|
|
|
|
|
define(
|
2015-02-27 01:05:13 +00:00
|
|
|
["../../src/controllers/EditController"],
|
2014-11-25 01:01:37 +00:00
|
|
|
function (EditController) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("The Edit mode controller", function () {
|
2014-11-25 01:29:42 +00:00
|
|
|
var mockScope,
|
2015-03-24 23:31:14 +00:00
|
|
|
mockQ,
|
2014-11-25 01:29:42 +00:00
|
|
|
mockNavigationService,
|
|
|
|
mockObject,
|
2015-06-17 17:16:59 +00:00
|
|
|
mockType,
|
2014-11-25 01:29:42 +00:00
|
|
|
controller;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
|
|
|
[ "$on" ]
|
|
|
|
);
|
2015-03-24 23:31:14 +00:00
|
|
|
mockQ = jasmine.createSpyObj('$q', ['when', 'all']);
|
2014-11-25 01:29:42 +00:00
|
|
|
mockNavigationService = jasmine.createSpyObj(
|
|
|
|
"navigationService",
|
|
|
|
[ "getNavigation", "addListener", "removeListener" ]
|
|
|
|
);
|
|
|
|
mockObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
2015-04-06 16:30:42 +00:00
|
|
|
[ "getId", "getModel", "getCapability", "hasCapability" ]
|
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
|
|
|
);
|
|
|
|
|
|
|
|
mockNavigationService.getNavigation.andReturn(mockObject);
|
|
|
|
mockObject.getId.andReturn("test");
|
|
|
|
mockObject.getModel.andReturn({ name: "Test object" });
|
2015-06-17 17:16:59 +00:00
|
|
|
mockObject.getCapability.andCallFake(function (key) {
|
|
|
|
return key === 'type' && mockType;
|
|
|
|
});
|
|
|
|
mockType.hasFeature.andReturn(true);
|
2014-11-25 01:29:42 +00:00
|
|
|
|
|
|
|
controller = new EditController(
|
|
|
|
mockScope,
|
2015-03-24 23:31:14 +00:00
|
|
|
mockQ,
|
2014-11-25 01:29:42 +00:00
|
|
|
mockNavigationService
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-03-31 22:58:13 +00:00
|
|
|
it("exposes the currently-navigated object", function () {
|
|
|
|
expect(controller.navigatedObject()).toBeDefined();
|
|
|
|
expect(controller.navigatedObject().getId()).toEqual("test");
|
2014-11-25 01:29:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("adds an editor capability to the navigated object", function () {
|
|
|
|
// Should provide an editor capability...
|
2015-03-31 22:58:13 +00:00
|
|
|
expect(controller.navigatedObject().getCapability("editor"))
|
2014-11-25 01:29:42 +00:00
|
|
|
.toBeDefined();
|
|
|
|
// Shouldn't have been the mock capability we provided
|
2015-03-31 22:58:13 +00:00
|
|
|
expect(controller.navigatedObject().getCapability("editor"))
|
2015-06-17 17:16:59 +00:00
|
|
|
.not.toEqual(mockType);
|
2014-11-25 01:29:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("detaches its navigation listener when destroyed", function () {
|
|
|
|
var navCallback = mockNavigationService
|
|
|
|
.addListener.mostRecentCall.args[0];
|
|
|
|
|
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith(
|
|
|
|
"$destroy",
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify precondition
|
|
|
|
expect(mockNavigationService.removeListener)
|
|
|
|
.not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
// Trigger destroy
|
|
|
|
mockScope.$on.mostRecentCall.args[1]();
|
|
|
|
|
|
|
|
// Listener should have been removed
|
|
|
|
expect(mockNavigationService.removeListener)
|
|
|
|
.toHaveBeenCalledWith(navCallback);
|
|
|
|
});
|
2014-11-25 01:01:37 +00:00
|
|
|
|
2015-03-31 22:58:13 +00:00
|
|
|
it("exposes a warning message for unload", function () {
|
|
|
|
var obj = controller.navigatedObject(),
|
|
|
|
mockEditor = jasmine.createSpyObj('editor', ['dirty']);
|
|
|
|
|
|
|
|
// Normally, should be undefined
|
|
|
|
expect(controller.getUnloadWarning()).toBeUndefined();
|
|
|
|
|
|
|
|
// Override the object's editor capability, make it look
|
|
|
|
// like there are unsaved changes.
|
|
|
|
obj.getCapability = jasmine.createSpy();
|
|
|
|
obj.getCapability.andReturn(mockEditor);
|
|
|
|
mockEditor.dirty.andReturn(true);
|
|
|
|
|
|
|
|
// Should have some warning message here now
|
|
|
|
expect(controller.getUnloadWarning()).toEqual(jasmine.any(String));
|
|
|
|
});
|
|
|
|
|
2014-11-25 01:01:37 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-17 17:16:59 +00:00
|
|
|
);
|