From cd2b19eb1e8ce899121ec77df58256a92b14cf8e Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 20 Jan 2016 20:52:26 -0800 Subject: [PATCH] [New Edit Mode] Fixed failing tests, and added new test in CreateWizard [New Edit Mode] #480 fixed JSLint errors [New Edit Mode] #480 do not show locator for sub objects [New Edit Mode] Modified persistence in SaveAction Removed redundant variable Fixed Failing Test Fixed JSLint errors Improved some documentation --- .../commonUI/browse/src/creation/AddAction.js | 11 ++++-- .../browse/src/creation/AddActionProvider.js | 2 +- .../browse/src/creation/CreateWizard.js | 25 +++++++++----- .../test/creation/AddActionProviderSpec.js | 2 +- .../browse/test/creation/CreateWizardSpec.js | 34 +++++++++++++++++-- .../commonUI/edit/src/actions/SaveAction.js | 18 ++++++---- .../capabilities/EditableLookupCapability.js | 5 +-- .../edit/src/capabilities/EditorCapability.js | 4 +-- .../controllers/swimlane/TimelineProxySpec.js | 2 +- 9 files changed, 75 insertions(+), 28 deletions(-) diff --git a/platform/commonUI/browse/src/creation/AddAction.js b/platform/commonUI/browse/src/creation/AddAction.js index 31d158e7bd..3832280130 100644 --- a/platform/commonUI/browse/src/creation/AddAction.js +++ b/platform/commonUI/browse/src/creation/AddAction.js @@ -22,7 +22,7 @@ /*global define,Promise*/ /** - * Module defining CreateAction. Created by vwoeltje on 11/10/14. + * Module defining AddAction. Created by ahenry on 01/21/16. */ define( [ @@ -66,9 +66,14 @@ define( this.dialogService = dialogService; this.policyService = policyService; } + /** + * * Create a new object of the given type. * This will prompt for user input first. + * + * @returns {Promise} that will be resolved with the object that the + * action was originally invoked on (ie. the 'parent') */ AddAction.prototype.perform = function () { var newModel = this.type.getInitialModel(), @@ -106,10 +111,10 @@ define( } return this.dialogService - .getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue()) + .getUserInput(wizard.getFormStructure(false), wizard.getInitialFormValue()) .then(populateObjectFromInput) .then(save) - .then(addToParent) + .then(addToParent); }; diff --git a/platform/commonUI/browse/src/creation/AddActionProvider.js b/platform/commonUI/browse/src/creation/AddActionProvider.js index 6f799b8d9b..0ac97c0013 100644 --- a/platform/commonUI/browse/src/creation/AddActionProvider.js +++ b/platform/commonUI/browse/src/creation/AddActionProvider.js @@ -22,7 +22,7 @@ /*global define,Promise*/ /** - * Module defining CreateActionProvider.js. Created by vwoeltje on 11/10/14. + * Module defining AddActionProvider.js. Created by ahenry on 01/21/16. */ define( ["./AddAction"], diff --git a/platform/commonUI/browse/src/creation/CreateWizard.js b/platform/commonUI/browse/src/creation/CreateWizard.js index 8bf4c5a2f1..f4a29d42ac 100644 --- a/platform/commonUI/browse/src/creation/CreateWizard.js +++ b/platform/commonUI/browse/src/creation/CreateWizard.js @@ -49,11 +49,14 @@ define( * Get the form model for this wizard; this is a description * that will be rendered to an HTML form. See the * platform/forms bundle - * + * @param {boolean} includeLocation if true, a 'location' section + * will be included that will allow the user to select the location + * of the newly created object, otherwise the .location property of + * the model will be used. * @return {FormModel} formModel the form model to * show in the create dialog */ - CreateWizard.prototype.getFormStructure = function () { + CreateWizard.prototype.getFormStructure = function (includeLocation) { var sections = [], type = this.type, policyService = this.policyService; @@ -87,12 +90,16 @@ define( }); // Ensure there is always a "save in" section - sections.push({ name: 'Location', rows: [{ - name: "Save In", - control: "locator", - validate: validateLocation, - key: "createParent" - }]}); + if (includeLocation) { + sections.push({ + name: 'Location', rows: [{ + name: "Save In", + control: "locator", + validate: validateLocation, + key: "createParent" + }] + }); + } return { sections: sections, @@ -115,7 +122,7 @@ define( return formModel; }); return this.domainObject; - } + }; /** * Get the initial value for the form being described. diff --git a/platform/commonUI/browse/test/creation/AddActionProviderSpec.js b/platform/commonUI/browse/test/creation/AddActionProviderSpec.js index 938067e72a..aaa83af8e9 100644 --- a/platform/commonUI/browse/test/creation/AddActionProviderSpec.js +++ b/platform/commonUI/browse/test/creation/AddActionProviderSpec.js @@ -22,7 +22,7 @@ /*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,xit,xdescribe*/ /** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. + * MCTRepresentationSpec. Created by ahenry on 01/21/14. */ define( ["../../src/creation/AddActionProvider"], diff --git a/platform/commonUI/browse/test/creation/CreateWizardSpec.js b/platform/commonUI/browse/test/creation/CreateWizardSpec.js index c4453e7432..fbb2a735e6 100644 --- a/platform/commonUI/browse/test/creation/CreateWizardSpec.js +++ b/platform/commonUI/browse/test/creation/CreateWizardSpec.js @@ -35,6 +35,7 @@ define( mockProperties, mockPolicyService, testModel, + mockDomainObject, wizard; function createMockProperty(name) { @@ -81,8 +82,18 @@ define( mockType.getInitialModel.andReturn(testModel); mockType.getProperties.andReturn(mockProperties); + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + ['getCapability', 'useCapability', 'getModel'] + ); + + //Mocking the getCapability('type') call + mockDomainObject.getCapability.andReturn(mockType); + mockDomainObject.useCapability.andReturn(); + mockDomainObject.getModel.andReturn(testModel); + wizard = new CreateWizard( - mockType, + mockDomainObject, mockParent, mockPolicyService ); @@ -130,6 +141,18 @@ define( }); }); + it("populates the model on the associated object", function () { + var formValue = { + "A": "ValueA", + "B": "ValueB", + "C": "ValueC" + }, + compareModel = wizard.createModel(formValue); + wizard.populateObjectFromInput(formValue); + expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function)); + expect(mockDomainObject.useCapability.mostRecentCall.args[1]()).toEqual(compareModel); + }); + it("validates selection types using policy", function () { var mockDomainObject = jasmine.createSpyObj( 'domainObject', @@ -139,7 +162,8 @@ define( 'otherType', ['getKey'] ), - structure = wizard.getFormStructure(), + //Create a form structure with location + structure = wizard.getFormStructure(true), sections = structure.sections, rows = structure.sections[sections.length - 1].rows, locationRow = rows[rows.length - 1]; @@ -156,6 +180,12 @@ define( ); }); + it("creates a form model without a location if not requested", function () { + expect(wizard.getFormStructure(false).sections.some(function(section){ + return section.name === 'Location'; + })).toEqual(false); + }); + }); } diff --git a/platform/commonUI/edit/src/actions/SaveAction.js b/platform/commonUI/edit/src/actions/SaveAction.js index 4cc71e56ee..073beeb4df 100644 --- a/platform/commonUI/edit/src/actions/SaveAction.js +++ b/platform/commonUI/edit/src/actions/SaveAction.js @@ -82,17 +82,20 @@ define( wizard = new CreateWizard(domainObject, parent, self.policyService); return self.dialogService - .getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue()) + .getUserInput(wizard.getFormStructure(true), wizard.getInitialFormValue()) .then(function(formValue){ - wizard.populateObjectFromInput(formValue, domainObject) + return wizard.populateObjectFromInput(formValue, domainObject); }); } function persistObject(object){ - return ((object.hasCapability('editor') && object.getCapability('editor').save()) || - object.getCapability('persistence').persist()) - .then(resolveWith(object)); + + //Persist first to mark dirty + return object.getCapability('persistence').persist().then(function(){ + //then save permanently + return object.getCapability('editor').save(); + }); } function fetchObject(objectId){ @@ -107,7 +110,9 @@ define( function locateObjectInParent(parent){ parent.getCapability('composition').add(domainObject.getId()); - return parent; + return parent.getCapability('persistence').persist().then(function() { + return parent; + }); } function doNothing() { @@ -129,7 +134,6 @@ define( .then(getParent)//Parent may have changed based // on user selection .then(locateObjectInParent) - .then(persistObject) .then(function(){ return fetchObject(domainObject.getId()); }) diff --git a/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js b/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js index 8193b0182d..dae2df3d83 100644 --- a/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js @@ -45,7 +45,8 @@ define( cache, idempotent ) { - var capability = Object.create(contextCapability); + var capability = Object.create(contextCapability), + method; // Check for domain object interface. If something has these // three methods, we assume it's a domain object. @@ -114,7 +115,7 @@ define( } // Wrap all methods; return only editable domain objects. - for (var method in contextCapability){ + for (method in contextCapability) { wrapMethod(method); } diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index 97fc2f9a56..0818eebf6d 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -110,8 +110,8 @@ define( } //Return the original (non-editable) object return returnPromise.then(function() { - return domainObject; - }) + return domainObject.getOriginalObject ? domainObject.getOriginalObject() : domainObject; + }); }; /** diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js index 0ecd073219..7d137fa6e4 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js @@ -74,7 +74,7 @@ define( expect(mockDomainObject.getCapability) .toHaveBeenCalledWith('action'); expect(mockActionCapability.getActions) - .toHaveBeenCalledWith('create'); + .toHaveBeenCalledWith('add'); }); it("invokes the action on the selection, if any", function () {