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-12-04 01:59:37 +00:00
|
|
|
/*global define,describe,it,xit,expect,beforeEach,jasmine*/
|
2014-12-04 01:07:01 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
['../../src/actions/PropertiesAction'],
|
|
|
|
function (PropertiesAction) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Properties action", function () {
|
2014-12-04 01:59:37 +00:00
|
|
|
var capabilities, model, object, context, input, dialogService, action;
|
2014-12-04 01:07:01 +00:00
|
|
|
|
2014-12-04 01:26:02 +00:00
|
|
|
function mockPromise(value) {
|
|
|
|
return {
|
|
|
|
then: function (callback) {
|
|
|
|
return mockPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-12-04 01:07:01 +00:00
|
|
|
beforeEach(function () {
|
2014-12-04 01:59:37 +00:00
|
|
|
capabilities = {
|
2015-01-27 21:09:23 +00:00
|
|
|
type: {
|
|
|
|
getProperties: function () { return []; },
|
|
|
|
hasFeature: jasmine.createSpy('hasFeature')
|
|
|
|
},
|
2014-12-04 01:59:37 +00:00
|
|
|
persistence: jasmine.createSpyObj("persistence", ["persist"]),
|
|
|
|
mutation: jasmine.createSpy("mutation")
|
2014-12-04 01:07:01 +00:00
|
|
|
};
|
|
|
|
model = {};
|
|
|
|
input = {};
|
|
|
|
object = {
|
|
|
|
getId: function () { return 'test-id'; },
|
2014-12-04 01:26:02 +00:00
|
|
|
getCapability: function (k) { return capabilities[k]; },
|
2014-12-04 01:59:37 +00:00
|
|
|
getModel: function () { return model; },
|
|
|
|
useCapability: function (k, v) { return capabilities[k](v); },
|
|
|
|
hasCapability: function () { return true; }
|
2014-12-04 01:07:01 +00:00
|
|
|
};
|
2014-12-04 01:26:02 +00:00
|
|
|
context = { someKey: "some value", domainObject: object };
|
2014-12-04 01:07:01 +00:00
|
|
|
dialogService = {
|
|
|
|
getUserInput: function () {
|
2014-12-04 01:26:02 +00:00
|
|
|
return mockPromise(input);
|
2014-12-04 01:07:01 +00:00
|
|
|
}
|
|
|
|
};
|
2014-12-04 01:59:37 +00:00
|
|
|
|
2015-01-27 21:09:23 +00:00
|
|
|
capabilities.type.hasFeature.andReturn(true);
|
2014-12-04 01:59:37 +00:00
|
|
|
capabilities.mutation.andReturn(true);
|
|
|
|
|
|
|
|
action = new PropertiesAction(dialogService, context);
|
2014-12-04 01:07:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("persists when an action is performed", function () {
|
2014-12-04 01:59:37 +00:00
|
|
|
action.perform();
|
|
|
|
expect(capabilities.persistence.persist)
|
|
|
|
.toHaveBeenCalled();
|
2014-12-04 01:07:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does not persist any changes upon cancel", function () {
|
2014-12-04 01:59:37 +00:00
|
|
|
input = undefined;
|
|
|
|
action.perform();
|
|
|
|
expect(capabilities.persistence.persist)
|
|
|
|
.not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("mutates an object when performed", function () {
|
|
|
|
action.perform();
|
|
|
|
expect(capabilities.mutation).toHaveBeenCalled();
|
|
|
|
capabilities.mutation.mostRecentCall.args[0]({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("is only applicable when a domain object is in context", function () {
|
|
|
|
expect(PropertiesAction.appliesTo(context)).toBeTruthy();
|
|
|
|
expect(PropertiesAction.appliesTo({})).toBeFalsy();
|
2015-01-27 21:09:23 +00:00
|
|
|
// Make sure it checked for creatability
|
|
|
|
expect(capabilities.type.hasFeature).toHaveBeenCalledWith('creation');
|
2014-12-04 01:07:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|