mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 12:18:16 +00:00
[Core] Complete specs for type service components
Complete specs for type service components, and supporting classes. WTD-573.
This commit is contained in:
@ -46,9 +46,10 @@ define(
|
|||||||
return propertyPath.length > 1 ?
|
return propertyPath.length > 1 ?
|
||||||
lookupValue(value, propertyPath.slice(1)) :
|
lookupValue(value, propertyPath.slice(1)) :
|
||||||
value;
|
value;
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback; property path was empty
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function specifyValue(object, propertyPath, value) {
|
function specifyValue(object, propertyPath, value) {
|
||||||
@ -79,13 +80,9 @@ define(
|
|||||||
var property = propertyDefinition.property ||
|
var property = propertyDefinition.property ||
|
||||||
propertyDefinition.key;
|
propertyDefinition.key;
|
||||||
|
|
||||||
if (property) {
|
return property ? conversion.toFormValue(
|
||||||
return conversion.toFormValue(
|
lookupValue(model, property)
|
||||||
lookupValue(model, property)
|
) : undefined;
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Set a value associated with this property in
|
* Set a value associated with this property in
|
||||||
@ -97,11 +94,9 @@ define(
|
|||||||
|
|
||||||
value = conversion.toModelValue(value);
|
value = conversion.toModelValue(value);
|
||||||
|
|
||||||
if (property) {
|
return property ?
|
||||||
return specifyValue(model, property, value);
|
specifyValue(model, property, value) :
|
||||||
} else {
|
undefined;
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get the raw definition for this property.
|
* Get the raw definition for this property.
|
||||||
|
@ -5,11 +5,40 @@
|
|||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
["../../src/types/MergeModels"],
|
["../../src/types/MergeModels"],
|
||||||
function (MergeModels) {
|
function (mergeModels) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("", function () {
|
describe("Model merger", function () {
|
||||||
|
it("merges models", function () {
|
||||||
|
expect(mergeModels(
|
||||||
|
{
|
||||||
|
"a": "property a",
|
||||||
|
"b": [ 1, 2, 3 ],
|
||||||
|
"c": {
|
||||||
|
x: 42,
|
||||||
|
z: [ 0 ]
|
||||||
|
},
|
||||||
|
"d": "should be ignored"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"b": [ 4 ],
|
||||||
|
"c": {
|
||||||
|
y: "property y",
|
||||||
|
z: [ "h" ]
|
||||||
|
},
|
||||||
|
"d": "property d"
|
||||||
|
}
|
||||||
|
)).toEqual({
|
||||||
|
"a": "property a",
|
||||||
|
"b": [ 1, 2, 3, 4 ],
|
||||||
|
"c": {
|
||||||
|
x: 42,
|
||||||
|
y: "property y",
|
||||||
|
z: [ 0, "h" ]
|
||||||
|
},
|
||||||
|
"d": "property d"
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -9,6 +9,32 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The type capability", function () {
|
describe("The type capability", function () {
|
||||||
|
var mockTypeService,
|
||||||
|
mockDomainObject,
|
||||||
|
mockType,
|
||||||
|
type;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockTypeService = jasmine.createSpyObj(
|
||||||
|
"typeService",
|
||||||
|
[ "getType" ]
|
||||||
|
);
|
||||||
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[ "getId", "getModel", "getCapability" ]
|
||||||
|
);
|
||||||
|
mockType = { someKey: "some value" };
|
||||||
|
|
||||||
|
mockTypeService.getType.andReturn(mockType);
|
||||||
|
mockDomainObject.getModel.andReturn({type: "mockType"});
|
||||||
|
|
||||||
|
type = new TypeCapability(mockTypeService, mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("looks up an object's type from type service", function () {
|
||||||
|
expect(type).toEqual(mockType);
|
||||||
|
expect(mockTypeService.getType).toHaveBeenCalledWith("mockType");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,10 @@ define(
|
|||||||
name: 'Test Type',
|
name: 'Test Type',
|
||||||
description: 'A type, for testing',
|
description: 'A type, for testing',
|
||||||
glyph: 't',
|
glyph: 't',
|
||||||
inherits: ['test-parent-1', 'test-parent-2']
|
inherits: ['test-parent-1', 'test-parent-2'],
|
||||||
|
features: ['test-feature-1'],
|
||||||
|
properties: [ {} ],
|
||||||
|
model: {someKey: "some value"}
|
||||||
};
|
};
|
||||||
type = typeImpl(testTypeDef);
|
type = typeImpl(testTypeDef);
|
||||||
});
|
});
|
||||||
@ -67,6 +70,19 @@ define(
|
|||||||
expect(type.instanceOf()).toBeTruthy();
|
expect(type.instanceOf()).toBeTruthy();
|
||||||
expect(type.instanceOf({ getKey: function () {} })).toBeTruthy();
|
expect(type.instanceOf({ getKey: function () {} })).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("allows features to be exposed", function () {
|
||||||
|
expect(type.hasFeature('test-feature-1')).toBeTruthy();
|
||||||
|
expect(type.hasFeature('test-feature-2')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides an initial model, if defined", function () {
|
||||||
|
expect(type.getInitialModel().someKey).toEqual("some value");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides type properties", function () {
|
||||||
|
expect(type.getProperties().length).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -56,6 +56,26 @@ define(
|
|||||||
expect(property.getValue(model)).toEqual("some value");
|
expect(property.getValue(model)).toEqual("some value");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stops looking for properties when a path is invalid", function () {
|
||||||
|
var definition = {
|
||||||
|
key: "someKey",
|
||||||
|
property: [ "some", "property" ]
|
||||||
|
},
|
||||||
|
property = new TypeProperty(definition);
|
||||||
|
expect(property.getValue(undefined)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gives undefined for empty paths", function () {
|
||||||
|
var definition = {
|
||||||
|
key: "someKey",
|
||||||
|
property: []
|
||||||
|
},
|
||||||
|
model = { some: { property: "some value" } },
|
||||||
|
property = new TypeProperty(definition);
|
||||||
|
expect(property.getValue(model)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
Reference in New Issue
Block a user