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-12-04 01:07:01 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
['../../src/actions/PropertiesAction'],
|
|
|
|
function (PropertiesAction) {
|
|
|
|
|
|
|
|
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: {
|
2016-05-19 18:29:13 +00:00
|
|
|
getProperties: function () {
|
|
|
|
return [];
|
|
|
|
},
|
2015-01-27 21:09:23 +00:00
|
|
|
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 = {
|
2016-05-19 18:29:13 +00:00
|
|
|
getId: function () {
|
|
|
|
return 'test-id';
|
|
|
|
},
|
|
|
|
getCapability: function (k) {
|
|
|
|
return capabilities[k];
|
|
|
|
},
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|