diff --git a/platform/core/src/types/TypeProperty.js b/platform/core/src/types/TypeProperty.js index 8bd12fc42f..bf843f7891 100644 --- a/platform/core/src/types/TypeProperty.js +++ b/platform/core/src/types/TypeProperty.js @@ -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. diff --git a/platform/core/test/types/MergeModelsSpec.js b/platform/core/test/types/MergeModelsSpec.js index c9c7f738f2..59d12a314a 100644 --- a/platform/core/test/types/MergeModelsSpec.js +++ b/platform/core/test/types/MergeModelsSpec.js @@ -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" + }); + }); }); } ); \ No newline at end of file diff --git a/platform/core/test/types/TypeCapabilitySpec.js b/platform/core/test/types/TypeCapabilitySpec.js index 84b31a4ccd..5b671f71c0 100644 --- a/platform/core/test/types/TypeCapabilitySpec.js +++ b/platform/core/test/types/TypeCapabilitySpec.js @@ -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"); + }); }); } diff --git a/platform/core/test/types/TypeImplSpec.js b/platform/core/test/types/TypeImplSpec.js index ea0c846bb3..8872d0e428 100644 --- a/platform/core/test/types/TypeImplSpec.js +++ b/platform/core/test/types/TypeImplSpec.js @@ -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); + }); }); } ); \ No newline at end of file diff --git a/platform/core/test/types/TypePropertySpec.js b/platform/core/test/types/TypePropertySpec.js index a1345b7192..09a55e35a0 100644 --- a/platform/core/test/types/TypePropertySpec.js +++ b/platform/core/test/types/TypePropertySpec.js @@ -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(); + }); + + }); } ); \ No newline at end of file