2015-10-19 19:08:49 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2016, United States Government
|
2015-10-19 19:08:49 +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-10-19 19:08:49 +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-10-19 19:08:49 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-06-30 18:41:15 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
[
|
|
|
|
'../../src/capabilities/LocationCapability',
|
2015-08-06 21:41:32 +00:00
|
|
|
'../DomainObjectFactory',
|
|
|
|
'../ControlledPromise'
|
2015-06-30 18:41:15 +00:00
|
|
|
],
|
2015-08-06 21:41:32 +00:00
|
|
|
function (LocationCapability, domainObjectFactory, ControlledPromise) {
|
2015-06-30 18:41:15 +00:00
|
|
|
|
|
|
|
describe("LocationCapability", function () {
|
|
|
|
|
|
|
|
describe("instantiated with domain object", function () {
|
|
|
|
var locationCapability,
|
2015-08-06 21:41:32 +00:00
|
|
|
mutationPromise,
|
2015-10-06 23:08:48 +00:00
|
|
|
mockQ,
|
|
|
|
mockInjector,
|
|
|
|
mockObjectService,
|
2015-06-30 18:41:15 +00:00
|
|
|
domainObject;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
domainObject = domainObjectFactory({
|
2015-10-06 23:47:37 +00:00
|
|
|
id: "testObject",
|
2015-06-30 18:41:15 +00:00
|
|
|
capabilities: {
|
|
|
|
context: {
|
2015-10-06 23:08:48 +00:00
|
|
|
getParent: function () {
|
2015-08-06 21:41:32 +00:00
|
|
|
return domainObjectFactory({id: 'root'});
|
2015-06-30 18:41:15 +00:00
|
|
|
}
|
2015-08-06 21:41:32 +00:00
|
|
|
},
|
|
|
|
mutation: jasmine.createSpyObj(
|
|
|
|
'mutationCapability',
|
|
|
|
['invoke']
|
|
|
|
)
|
2015-06-30 18:41:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-06 23:08:48 +00:00
|
|
|
mockQ = jasmine.createSpyObj("$q", ["when"]);
|
|
|
|
mockInjector = jasmine.createSpyObj("$injector", ["get"]);
|
|
|
|
mockObjectService =
|
|
|
|
jasmine.createSpyObj("objectService", ["getObjects"]);
|
|
|
|
|
2015-08-06 21:41:32 +00:00
|
|
|
mutationPromise = new ControlledPromise();
|
|
|
|
domainObject.capabilities.mutation.invoke.andCallFake(
|
|
|
|
function (mutator) {
|
|
|
|
return mutationPromise.then(function () {
|
|
|
|
mutator(domainObject.model);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-06 23:08:48 +00:00
|
|
|
locationCapability = new LocationCapability(
|
|
|
|
mockQ,
|
2015-10-06 23:47:37 +00:00
|
|
|
mockInjector,
|
2015-10-06 23:08:48 +00:00
|
|
|
domainObject
|
|
|
|
);
|
2015-06-30 18:41:15 +00:00
|
|
|
});
|
|
|
|
|
2015-08-19 18:28:58 +00:00
|
|
|
it("returns contextual location", function () {
|
|
|
|
expect(locationCapability.getContextualLocation())
|
2015-08-06 21:41:32 +00:00
|
|
|
.toBe('root');
|
2015-06-30 18:41:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("knows when the object is an original", function () {
|
2015-08-06 21:41:32 +00:00
|
|
|
domainObject.model.location = 'root';
|
2015-06-30 18:41:15 +00:00
|
|
|
expect(locationCapability.isOriginal()).toBe(true);
|
|
|
|
expect(locationCapability.isLink()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("knows when the object is a link.", function () {
|
2015-08-06 21:41:32 +00:00
|
|
|
domainObject.model.location = 'different-root';
|
2015-06-30 18:41:15 +00:00
|
|
|
expect(locationCapability.isLink()).toBe(true);
|
|
|
|
expect(locationCapability.isOriginal()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:55:05 +00:00
|
|
|
it("can mutate location", function () {
|
|
|
|
var result = locationCapability
|
2015-08-19 18:15:09 +00:00
|
|
|
.setPrimaryLocation('root'),
|
2015-08-06 21:41:32 +00:00
|
|
|
whenComplete = jasmine.createSpy('whenComplete');
|
|
|
|
|
2016-05-19 18:55:05 +00:00
|
|
|
result.then(whenComplete);
|
2015-08-06 21:41:32 +00:00
|
|
|
|
|
|
|
expect(domainObject.model.location).not.toBeDefined();
|
|
|
|
mutationPromise.resolve();
|
|
|
|
expect(domainObject.model.location).toBe('root');
|
|
|
|
|
|
|
|
expect(whenComplete).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2015-10-06 23:47:37 +00:00
|
|
|
describe("when used to load an original instance", function () {
|
|
|
|
var objectPromise,
|
|
|
|
qPromise,
|
|
|
|
originalObjects,
|
|
|
|
mockCallback;
|
|
|
|
|
|
|
|
function resolvePromises() {
|
|
|
|
if (mockQ.when.calls.length > 0) {
|
|
|
|
qPromise.resolve(mockQ.when.mostRecentCall.args[0]);
|
|
|
|
}
|
|
|
|
if (mockObjectService.getObjects.calls.length > 0) {
|
|
|
|
objectPromise.resolve(originalObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
objectPromise = new ControlledPromise();
|
|
|
|
qPromise = new ControlledPromise();
|
|
|
|
originalObjects = {
|
|
|
|
testObject: domainObjectFactory()
|
|
|
|
};
|
|
|
|
|
|
|
|
mockInjector.get.andCallFake(function (key) {
|
|
|
|
return key === 'objectService' && mockObjectService;
|
|
|
|
});
|
|
|
|
mockObjectService.getObjects.andReturn(objectPromise);
|
|
|
|
mockQ.when.andReturn(qPromise);
|
|
|
|
|
|
|
|
mockCallback = jasmine.createSpy('callback');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("provides originals directly", function () {
|
|
|
|
domainObject.model.location = 'root';
|
|
|
|
locationCapability.getOriginal().then(mockCallback);
|
|
|
|
expect(mockCallback).not.toHaveBeenCalled();
|
|
|
|
resolvePromises();
|
|
|
|
expect(mockCallback)
|
|
|
|
.toHaveBeenCalledWith(domainObject);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("loads from the object service for links", function () {
|
|
|
|
domainObject.model.location = 'some-other-root';
|
|
|
|
locationCapability.getOriginal().then(mockCallback);
|
|
|
|
expect(mockCallback).not.toHaveBeenCalled();
|
|
|
|
resolvePromises();
|
|
|
|
expect(mockCallback)
|
|
|
|
.toHaveBeenCalledWith(originalObjects.testObject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-06-30 18:41:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|