From 7c4436503702ce5408f212464034e01f1544f266 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 27 Jan 2015 11:02:00 -0800 Subject: [PATCH] [Edit] Add model cache spec Add a spec for an editable model cache; this will behave similarly to the existing domain object cache, except that it will cache only models. Use of this will permit multiple instances of editable objects to be created with unique contexts (that is, distinct parent objects accessible via the context capability) which in turn will avoid the ambiguous parentage which results in unexpected behavior of the Remove action in Edit mode, WTD-473. --- .../test/objects/EditableModelCacheSpec.js | 60 +++++++++++++++++++ platform/commonUI/edit/test/suite.json | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 platform/commonUI/edit/test/objects/EditableModelCacheSpec.js diff --git a/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js b/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js new file mode 100644 index 0000000000..85fad1ae70 --- /dev/null +++ b/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js @@ -0,0 +1,60 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/objects/EditableModelCache"], + function (EditableModelCache) { + "use strict"; + + describe("The editable model cache", function () { + var mockObject, + mockOtherObject, + testModel, + testId, + otherModel, + otherId, + cache; + + beforeEach(function () { + testId = "test"; + testModel = { someKey: "some value" }; + otherId = "other"; + otherModel = { someKey: "some other value" }; + + mockObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel" ] + ); + mockOtherObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel" ] + ); + + mockObject.getId.andReturn(testId); + mockObject.getModel.andReturn(testModel); + mockOtherObject.getId.andReturn(otherId); + mockOtherObject.getModel.andReturn(otherModel); + + cache = new EditableModelCache(); + }); + + it("provides clones of domain object models", function () { + var model = cache.getCachedModel(mockObject); + // Should be identical... + expect(model).toEqual(testModel); + // ...but not pointer-identical + expect(model).not.toBe(testModel); + }); + + it("provides only one clone per object", function () { + var model = cache.getCachedModel(mockObject); + expect(cache.getCachedModel(mockObject)).toBe(model); + }); + + it("maintains separate caches per-object", function () { + expect(cache.getCachedModel(mockObject)) + .not.toEqual(cache.getCachedModel(mockOtherObject)); + }); + }); + + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/suite.json b/platform/commonUI/edit/test/suite.json index 98a0d3de00..4bf89661d8 100644 --- a/platform/commonUI/edit/test/suite.json +++ b/platform/commonUI/edit/test/suite.json @@ -12,5 +12,6 @@ "capabilities/EditablePersistenceCapability", "capabilities/EditorCapability", "objects/EditableDomainObject", - "objects/EditableDomainObjectCache" + "objects/EditableDomainObjectCache", + "objects/EditableModelCache" ] \ No newline at end of file