mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 03:06:54 +00:00
[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
This commit is contained in:
parent
c65096f166
commit
cd2b19eb1e
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
@ -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"],
|
||||
|
@ -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.
|
||||
|
@ -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"],
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -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());
|
||||
})
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,8 @@ define(
|
||||
}
|
||||
//Return the original (non-editable) object
|
||||
return returnPromise.then(function() {
|
||||
return domainObject;
|
||||
})
|
||||
return domainObject.getOriginalObject ? domainObject.getOriginalObject() : domainObject;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user