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.
|
|
|
|
*****************************************************************************/
|
2015-12-09 18:04:49 +00:00
|
|
|
/*global define,describe,it,expect,beforeEach,jasmine,xit,xdescribe*/
|
2014-11-25 01:01:37 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
["../../src/actions/CancelAction"],
|
|
|
|
function (CancelAction) {
|
|
|
|
"use strict";
|
|
|
|
|
2015-12-08 23:15:54 +00:00
|
|
|
//TODO: Disabled for NEM Beta
|
|
|
|
xdescribe("The Cancel action", function () {
|
2014-11-25 17:35:55 +00:00
|
|
|
var mockLocation,
|
|
|
|
mockDomainObject,
|
|
|
|
mockEditorCapability,
|
2015-06-25 21:07:02 +00:00
|
|
|
mockUrlService,
|
2014-11-25 17:35:55 +00:00
|
|
|
actionContext,
|
|
|
|
action;
|
2014-11-25 01:01:37 +00:00
|
|
|
|
2014-11-25 17:35:55 +00:00
|
|
|
function mockPromise(value) {
|
|
|
|
return {
|
|
|
|
then: function (callback) {
|
|
|
|
return mockPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockLocation = jasmine.createSpyObj(
|
|
|
|
"$location",
|
|
|
|
[ "path" ]
|
|
|
|
);
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[ "getCapability", "hasCapability" ]
|
|
|
|
);
|
|
|
|
mockEditorCapability = jasmine.createSpyObj(
|
|
|
|
"editor",
|
|
|
|
[ "save", "cancel" ]
|
|
|
|
);
|
2015-06-25 21:07:02 +00:00
|
|
|
mockUrlService = jasmine.createSpyObj(
|
|
|
|
"urlService",
|
|
|
|
["urlForLocation"]
|
|
|
|
);
|
2014-11-25 17:35:55 +00:00
|
|
|
|
|
|
|
actionContext = {
|
|
|
|
domainObject: mockDomainObject
|
|
|
|
};
|
|
|
|
|
|
|
|
mockDomainObject.hasCapability.andReturn(true);
|
|
|
|
mockDomainObject.getCapability.andReturn(mockEditorCapability);
|
|
|
|
mockEditorCapability.cancel.andReturn(mockPromise(true));
|
|
|
|
|
2015-06-25 21:07:02 +00:00
|
|
|
action = new CancelAction(mockLocation, mockUrlService, actionContext);
|
2014-11-25 17:35:55 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("only applies to domain object with an editor capability", function () {
|
|
|
|
expect(CancelAction.appliesTo(actionContext)).toBeTruthy();
|
|
|
|
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
|
|
|
|
|
|
|
mockDomainObject.hasCapability.andReturn(false);
|
|
|
|
mockDomainObject.getCapability.andReturn(undefined);
|
|
|
|
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("invokes the editor capability's save functionality when performed", function () {
|
|
|
|
// Verify precondition
|
|
|
|
expect(mockEditorCapability.cancel).not.toHaveBeenCalled();
|
|
|
|
action.perform();
|
|
|
|
|
|
|
|
// Should have called cancel
|
|
|
|
expect(mockEditorCapability.cancel).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// Definitely shouldn't call save!
|
|
|
|
expect(mockEditorCapability.save).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns to browse when performed", function () {
|
|
|
|
action.perform();
|
2015-06-25 21:07:02 +00:00
|
|
|
expect(mockLocation.path).toHaveBeenCalledWith(
|
|
|
|
mockUrlService.urlForLocation("browse", mockDomainObject)
|
|
|
|
);
|
2014-11-25 17:35:55 +00:00
|
|
|
});
|
2014-11-25 01:01:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|