diff --git a/platform/commonUI/edit/src/EditActionController.js b/platform/commonUI/edit/src/EditActionController.js index 4559dc9bb9..691cd3a6d6 100644 --- a/platform/commonUI/edit/src/EditActionController.js +++ b/platform/commonUI/edit/src/EditActionController.js @@ -8,21 +8,23 @@ define( function () { "use strict"; + var ACTION_CONTEXT = { category: 'conclude-editing' }; + /** * Controller which supplies action instances for Save/Cancel. * @constructor */ function EditActionController($scope) { + // Maintain all "conclude-editing" actions in the present + // context. function updateActions() { - if (!$scope.action) { - $scope.editActions = []; - } else { - $scope.editActions = $scope.action.getActions({ - category: 'conclude-editing' - }); - } + $scope.editActions = $scope.action ? + $scope.action.getActions(ACTION_CONTEXT) : + []; } + // Update set of actions whenever the action capability + // changes or becomes available. $scope.$watch("action", updateActions); } diff --git a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js index ccaac78f77..0b7354dc84 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js @@ -79,10 +79,6 @@ define( // Save All. An infinite loop is avoided by marking // objects as clean as we go. - function doSave(editCapability) { - return editCapability.save(); - } - while (Object.keys(dirty).length > 0) { // Pick the first dirty object object = dirty[Object.keys(dirty)[0]]; @@ -91,7 +87,7 @@ define( this.markClean(object); // Invoke its save behavior - object.getCapability('editor.completion').then(doSave); + object.getCapability('editor').save(); } } }; diff --git a/platform/commonUI/edit/test/EditActionControllerSpec.js b/platform/commonUI/edit/test/EditActionControllerSpec.js new file mode 100644 index 0000000000..7b8fc1741c --- /dev/null +++ b/platform/commonUI/edit/test/EditActionControllerSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../src/EditActionController"], + function (EditActionController) { + "use strict"; + + describe("The Edit Action controller", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/EditControllerSpec.js b/platform/commonUI/edit/test/EditControllerSpec.js new file mode 100644 index 0000000000..572eae4110 --- /dev/null +++ b/platform/commonUI/edit/test/EditControllerSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../src/EditController"], + function (EditController) { + "use strict"; + + describe("The Edit mode controller", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/actions/CancelActionSpec.js b/platform/commonUI/edit/test/actions/CancelActionSpec.js new file mode 100644 index 0000000000..6c6ab6ee22 --- /dev/null +++ b/platform/commonUI/edit/test/actions/CancelActionSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/actions/CancelAction"], + function (CancelAction) { + "use strict"; + + describe("The Cancel action", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/actions/EditActionSpec.js b/platform/commonUI/edit/test/actions/EditActionSpec.js new file mode 100644 index 0000000000..dbe57c5570 --- /dev/null +++ b/platform/commonUI/edit/test/actions/EditActionSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/actions/EditAction"], + function (EditAction) { + "use strict"; + + describe("The Edit action", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/actions/RemoveActionSpec.js b/platform/commonUI/edit/test/actions/RemoveActionSpec.js new file mode 100644 index 0000000000..0d3dc9b30d --- /dev/null +++ b/platform/commonUI/edit/test/actions/RemoveActionSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/actions/RemoveAction"], + function (RemoveAction) { + "use strict"; + + describe("The Remove action", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/actions/SaveActionSpec.js b/platform/commonUI/edit/test/actions/SaveActionSpec.js new file mode 100644 index 0000000000..773dc52ed6 --- /dev/null +++ b/platform/commonUI/edit/test/actions/SaveActionSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/actions/SaveAction"], + function (SaveAction) { + "use strict"; + + describe("The Save action", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js new file mode 100644 index 0000000000..1912b31379 --- /dev/null +++ b/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/capabilities/EditablePersistenceCapability"], + function (EditablePersistenceCapability) { + "use strict"; + + describe("An editable persistence capability", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js new file mode 100644 index 0000000000..82137b4ab2 --- /dev/null +++ b/platform/commonUI/edit/test/capabilities/EditorCapabilitySpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/capabilities/EditableContextCapability"], + function (EditableContextCapability) { + "use strict"; + + describe("An editable context capability", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js b/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js new file mode 100644 index 0000000000..4a606606fc --- /dev/null +++ b/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js @@ -0,0 +1,99 @@ +/*global define,describe,it,expect,beforeEach*/ + +define( + ["../../src/objects/EditableDomainObjectCache"], + function (EditableDomainObjectCache) { + 'use strict'; + + describe("Editable domain object cache", function () { + + var captured, + completionCapability, + object, + cache; + + + // Constructors for test objects + function TestObject(id) { + return { + getId: function () { return id; }, + getModel: function () { return {}; }, + getCapability: function (name) { + return completionCapability; + } + }; + } + + function WrapObject(domainObject) { + var result = Object.create(domainObject); + result.wrapped = true; + captured.wraps = (captured.wraps || 0) + 1; + return result; + } + + beforeEach(function () { + captured = {}; + completionCapability = { + save: function () { + captured.saved = (captured.saved || 0) + 1; + } + }; + + cache = new EditableDomainObjectCache(WrapObject); + }); + + it("wraps objects using provided constructor", function () { + var domainObject = new TestObject('test-id'), + wrappedObject = cache.getEditableObject(domainObject); + expect(wrappedObject.wrapped).toBeTruthy(); + expect(wrappedObject.getId()).toEqual(domainObject.getId()); + }); + + it("only wraps objects once", function () { + var domainObject = new TestObject('test-id'), + wrappedObject; + + // Verify precondition + expect(captured.wraps).toBeUndefined(); + + // Invoke a few more times; expect count not to increment + wrappedObject = cache.getEditableObject(domainObject); + expect(captured.wraps).toEqual(1); + wrappedObject = cache.getEditableObject(domainObject); + expect(captured.wraps).toEqual(1); + wrappedObject = cache.getEditableObject(domainObject); + expect(captured.wraps).toEqual(1); + + // Verify that the last call still gave us a wrapped object + expect(wrappedObject.wrapped).toBeTruthy(); + expect(wrappedObject.getId()).toEqual(domainObject.getId()); + }); + + it("saves objects that have been marked dirty", function () { + var objects = ['a', 'b', 'c'].map(TestObject).map(cache.getEditableObject); + + cache.markDirty(objects[0]); + cache.markDirty(objects[2]); + + cache.saveAll(); + + expect(captured.saved).toEqual(2); + }); + + it("does not save objects that have been marked clean", function () { + var objects = ['a', 'b', 'c'].map(TestObject).map(cache.getEditableObject); + + cache.markDirty(objects[0]); + cache.markDirty(objects[2]); + cache.markClean(objects[0]); + + cache.saveAll(); + + expect(captured.saved).toEqual(1); + }); + + + }); + } + +); diff --git a/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js b/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js new file mode 100644 index 0000000000..d99b57355b --- /dev/null +++ b/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js @@ -0,0 +1,12 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/objects/EditableDomainObject"], + function (EditableDomainObject) { + "use strict"; + + describe("Editable domain object", function () { + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/suite.json b/platform/commonUI/edit/test/suite.json new file mode 100644 index 0000000000..ccfc84e53a --- /dev/null +++ b/platform/commonUI/edit/test/suite.json @@ -0,0 +1,13 @@ +[ + "EditActionController", + "EditController", + "actions/CancelAction", + "actions/EditAction", + "actions/RemoveAction", + "actions/SaveAction", + "capabilities/EditableContextCapability", + "capabilities/EditablePersistenceCapability", + "capabilities/EditorCapability", + "objects/EditableDomainObject", + "objects/EditableDomainObjectCache" +] \ No newline at end of file