[Core] Complete specs for type service components

Complete specs for type service components, and supporting
classes. WTD-573.
This commit is contained in:
Victor Woeltjen 2014-11-21 18:14:26 -08:00
parent b9b164ab31
commit 84c7f3d71d
5 changed files with 104 additions and 18 deletions

View File

@ -46,9 +46,10 @@ define(
return propertyPath.length > 1 ?
lookupValue(value, propertyPath.slice(1)) :
value;
} else {
return undefined;
}
// Fallback; property path was empty
return undefined;
}
function specifyValue(object, propertyPath, value) {
@ -79,13 +80,9 @@ define(
var property = propertyDefinition.property ||
propertyDefinition.key;
if (property) {
return conversion.toFormValue(
lookupValue(model, property)
);
} else {
return undefined;
}
return property ? conversion.toFormValue(
lookupValue(model, property)
) : undefined;
},
/**
* Set a value associated with this property in
@ -97,11 +94,9 @@ define(
value = conversion.toModelValue(value);
if (property) {
return specifyValue(model, property, value);
} else {
return undefined;
}
return property ?
specifyValue(model, property, value) :
undefined;
},
/**
* Get the raw definition for this property.

View File

@ -5,11 +5,40 @@
*/
define(
["../../src/types/MergeModels"],
function (MergeModels) {
function (mergeModels) {
"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"
});
});
});
}
);

View File

@ -9,6 +9,32 @@ define(
"use strict";
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");
});
});
}

View File

@ -15,7 +15,10 @@ define(
name: 'Test Type',
description: 'A type, for testing',
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);
});
@ -67,6 +70,19 @@ define(
expect(type.instanceOf()).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);
});
});
}
);

View File

@ -56,6 +56,26 @@ define(
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();
});
});
}
);