mirror of
https://github.com/nasa/openmct.git
synced 2025-05-08 03:28:33 +00:00
[Creation] Use instantiate service
...from instantiation capability.
This commit is contained in:
parent
d059116782
commit
81b136eab1
@ -38,20 +38,6 @@ define(
|
|||||||
this.$injector = $injector;
|
this.$injector = $injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Alias of `capabilityService.getCapabilities`; handles lazy loading
|
|
||||||
* of `capabilityService`, since it cannot be declared as a
|
|
||||||
* dependency directly without creating a cycle.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
CreationCapability.prototype.getCapabilities = function (model) {
|
|
||||||
if (!this.capabilityService) {
|
|
||||||
this.capabilityService =
|
|
||||||
this.$injector.get('capabilityService');
|
|
||||||
}
|
|
||||||
return this.capabilityService.getCapabilities(model);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a new domain object with the provided model.
|
* Instantiate a new domain object with the provided model.
|
||||||
*
|
*
|
||||||
@ -62,9 +48,8 @@ define(
|
|||||||
* @returns {DomainObject} the new domain object
|
* @returns {DomainObject} the new domain object
|
||||||
*/
|
*/
|
||||||
CreationCapability.prototype.instantiate = function (model) {
|
CreationCapability.prototype.instantiate = function (model) {
|
||||||
var id = uuid(),
|
this.instantiate = this.$injector.get("instantiate");
|
||||||
capabilities = this.getCapabilities(model);
|
return this.instantiate(model);
|
||||||
return new DomainObjectImpl(id, model, capabilities);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
/*global define,Promise,describe,it,xdescribe,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContextCapability. Created by vwoeltje on 11/6/14.
|
* ContextCapability. Created by vwoeltje on 11/6/14.
|
||||||
@ -31,19 +31,16 @@ define(
|
|||||||
|
|
||||||
describe("The 'instantiation' capability", function () {
|
describe("The 'instantiation' capability", function () {
|
||||||
var mockInjector,
|
var mockInjector,
|
||||||
mockCapabilityService,
|
mockInstantiate,
|
||||||
instantiation;
|
instantiation;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockInjector = jasmine.createSpyObj("$injector", ["get"]);
|
mockInjector = jasmine.createSpyObj("$injector", ["get"]);
|
||||||
mockCapabilityService = jasmine.createSpyObj(
|
mockInstantiate = jasmine.createSpy("instantiate");
|
||||||
"capabilityService",
|
|
||||||
[ "getCapabilities" ]
|
|
||||||
);
|
|
||||||
|
|
||||||
mockInjector.get.andCallFake(function (key) {
|
mockInjector.get.andCallFake(function (key) {
|
||||||
return key === 'capabilityService' ?
|
return key === 'instantiate' ?
|
||||||
mockCapabilityService : undefined;
|
mockInstantiate : undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
instantiation = new InstantiationCapability(mockInjector);
|
instantiation = new InstantiationCapability(mockInjector);
|
||||||
@ -54,7 +51,22 @@ define(
|
|||||||
expect(instantiation.invoke).toBe(instantiation.instantiate);
|
expect(instantiation.invoke).toBe(instantiation.instantiate);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when creating an object", function () {
|
it("uses the instantiate service to create domain objects", function () {
|
||||||
|
var mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||||
|
'getId',
|
||||||
|
'getModel',
|
||||||
|
'getCapability',
|
||||||
|
'useCapability',
|
||||||
|
'hasCapability'
|
||||||
|
]), testModel = { someKey: "some value" };
|
||||||
|
mockInstantiate.andReturn(mockDomainObject);
|
||||||
|
expect(instantiation.instantiate(testModel))
|
||||||
|
.toBe(mockDomainObject);
|
||||||
|
expect(mockInstantiate).toHaveBeenCalledWith(testModel);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Move to instantiate service
|
||||||
|
xdescribe("when creating an object", function () {
|
||||||
var mockCapabilityConstructor,
|
var mockCapabilityConstructor,
|
||||||
mockCapabilityInstance,
|
mockCapabilityInstance,
|
||||||
mockCapabilities,
|
mockCapabilities,
|
||||||
@ -64,9 +76,9 @@ define(
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockCapabilityConstructor = jasmine.createSpy('capability');
|
mockCapabilityConstructor = jasmine.createSpy('capability');
|
||||||
mockCapabilityInstance = {};
|
mockCapabilityInstance = {};
|
||||||
mockCapabilityService.getCapabilities.andReturn({
|
// mockCapabilityService.getCapabilities.andReturn({
|
||||||
something: mockCapabilityConstructor
|
// something: mockCapabilityConstructor
|
||||||
});
|
// });
|
||||||
mockCapabilityConstructor.andReturn(mockCapabilityInstance);
|
mockCapabilityConstructor.andReturn(mockCapabilityInstance);
|
||||||
|
|
||||||
testModel = { someKey: "some value" };
|
testModel = { someKey: "some value" };
|
||||||
@ -75,8 +87,8 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("loads capabilities from the capability service", function () {
|
it("loads capabilities from the capability service", function () {
|
||||||
expect(mockCapabilityService.getCapabilities)
|
// expect(mockCapabilityService.getCapabilities)
|
||||||
.toHaveBeenCalledWith(testModel);
|
// .toHaveBeenCalledWith(testModel);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("exposes loaded capabilities from the created object", function () {
|
it("exposes loaded capabilities from the created object", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user