mirror of
https://github.com/nasa/openmct.git
synced 2025-05-15 06:53:23 +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*/
|
/*global define,Promise*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module defining CreateAction. Created by vwoeltje on 11/10/14.
|
* Module defining AddAction. Created by ahenry on 01/21/16.
|
||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
@ -66,9 +66,14 @@ define(
|
|||||||
this.dialogService = dialogService;
|
this.dialogService = dialogService;
|
||||||
this.policyService = policyService;
|
this.policyService = policyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* Create a new object of the given type.
|
* Create a new object of the given type.
|
||||||
* This will prompt for user input first.
|
* 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 () {
|
AddAction.prototype.perform = function () {
|
||||||
var newModel = this.type.getInitialModel(),
|
var newModel = this.type.getInitialModel(),
|
||||||
@ -106,10 +111,10 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.dialogService
|
return this.dialogService
|
||||||
.getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue())
|
.getUserInput(wizard.getFormStructure(false), wizard.getInitialFormValue())
|
||||||
.then(populateObjectFromInput)
|
.then(populateObjectFromInput)
|
||||||
.then(save)
|
.then(save)
|
||||||
.then(addToParent)
|
.then(addToParent);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
/*global define,Promise*/
|
/*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(
|
define(
|
||||||
["./AddAction"],
|
["./AddAction"],
|
||||||
|
@ -49,11 +49,14 @@ define(
|
|||||||
* Get the form model for this wizard; this is a description
|
* Get the form model for this wizard; this is a description
|
||||||
* that will be rendered to an HTML form. See the
|
* that will be rendered to an HTML form. See the
|
||||||
* platform/forms bundle
|
* 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
|
* @return {FormModel} formModel the form model to
|
||||||
* show in the create dialog
|
* show in the create dialog
|
||||||
*/
|
*/
|
||||||
CreateWizard.prototype.getFormStructure = function () {
|
CreateWizard.prototype.getFormStructure = function (includeLocation) {
|
||||||
var sections = [],
|
var sections = [],
|
||||||
type = this.type,
|
type = this.type,
|
||||||
policyService = this.policyService;
|
policyService = this.policyService;
|
||||||
@ -87,12 +90,16 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Ensure there is always a "save in" section
|
// Ensure there is always a "save in" section
|
||||||
sections.push({ name: 'Location', rows: [{
|
if (includeLocation) {
|
||||||
|
sections.push({
|
||||||
|
name: 'Location', rows: [{
|
||||||
name: "Save In",
|
name: "Save In",
|
||||||
control: "locator",
|
control: "locator",
|
||||||
validate: validateLocation,
|
validate: validateLocation,
|
||||||
key: "createParent"
|
key: "createParent"
|
||||||
}]});
|
}]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sections: sections,
|
sections: sections,
|
||||||
@ -115,7 +122,7 @@ define(
|
|||||||
return formModel;
|
return formModel;
|
||||||
});
|
});
|
||||||
return this.domainObject;
|
return this.domainObject;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the initial value for the form being described.
|
* Get the initial value for the form being described.
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,xit,xdescribe*/
|
/*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(
|
define(
|
||||||
["../../src/creation/AddActionProvider"],
|
["../../src/creation/AddActionProvider"],
|
||||||
|
@ -35,6 +35,7 @@ define(
|
|||||||
mockProperties,
|
mockProperties,
|
||||||
mockPolicyService,
|
mockPolicyService,
|
||||||
testModel,
|
testModel,
|
||||||
|
mockDomainObject,
|
||||||
wizard;
|
wizard;
|
||||||
|
|
||||||
function createMockProperty(name) {
|
function createMockProperty(name) {
|
||||||
@ -81,8 +82,18 @@ define(
|
|||||||
mockType.getInitialModel.andReturn(testModel);
|
mockType.getInitialModel.andReturn(testModel);
|
||||||
mockType.getProperties.andReturn(mockProperties);
|
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(
|
wizard = new CreateWizard(
|
||||||
mockType,
|
mockDomainObject,
|
||||||
mockParent,
|
mockParent,
|
||||||
mockPolicyService
|
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 () {
|
it("validates selection types using policy", function () {
|
||||||
var mockDomainObject = jasmine.createSpyObj(
|
var mockDomainObject = jasmine.createSpyObj(
|
||||||
'domainObject',
|
'domainObject',
|
||||||
@ -139,7 +162,8 @@ define(
|
|||||||
'otherType',
|
'otherType',
|
||||||
['getKey']
|
['getKey']
|
||||||
),
|
),
|
||||||
structure = wizard.getFormStructure(),
|
//Create a form structure with location
|
||||||
|
structure = wizard.getFormStructure(true),
|
||||||
sections = structure.sections,
|
sections = structure.sections,
|
||||||
rows = structure.sections[sections.length - 1].rows,
|
rows = structure.sections[sections.length - 1].rows,
|
||||||
locationRow = rows[rows.length - 1];
|
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);
|
wizard = new CreateWizard(domainObject, parent, self.policyService);
|
||||||
|
|
||||||
return self.dialogService
|
return self.dialogService
|
||||||
.getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue())
|
.getUserInput(wizard.getFormStructure(true), wizard.getInitialFormValue())
|
||||||
.then(function(formValue){
|
.then(function(formValue){
|
||||||
wizard.populateObjectFromInput(formValue, domainObject)
|
return wizard.populateObjectFromInput(formValue, domainObject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function persistObject(object){
|
function persistObject(object){
|
||||||
return ((object.hasCapability('editor') && object.getCapability('editor').save()) ||
|
|
||||||
object.getCapability('persistence').persist())
|
//Persist first to mark dirty
|
||||||
.then(resolveWith(object));
|
return object.getCapability('persistence').persist().then(function(){
|
||||||
|
//then save permanently
|
||||||
|
return object.getCapability('editor').save();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchObject(objectId){
|
function fetchObject(objectId){
|
||||||
@ -107,7 +110,9 @@ define(
|
|||||||
|
|
||||||
function locateObjectInParent(parent){
|
function locateObjectInParent(parent){
|
||||||
parent.getCapability('composition').add(domainObject.getId());
|
parent.getCapability('composition').add(domainObject.getId());
|
||||||
|
return parent.getCapability('persistence').persist().then(function() {
|
||||||
return parent;
|
return parent;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function doNothing() {
|
function doNothing() {
|
||||||
@ -129,7 +134,6 @@ define(
|
|||||||
.then(getParent)//Parent may have changed based
|
.then(getParent)//Parent may have changed based
|
||||||
// on user selection
|
// on user selection
|
||||||
.then(locateObjectInParent)
|
.then(locateObjectInParent)
|
||||||
.then(persistObject)
|
|
||||||
.then(function(){
|
.then(function(){
|
||||||
return fetchObject(domainObject.getId());
|
return fetchObject(domainObject.getId());
|
||||||
})
|
})
|
||||||
|
@ -45,7 +45,8 @@ define(
|
|||||||
cache,
|
cache,
|
||||||
idempotent
|
idempotent
|
||||||
) {
|
) {
|
||||||
var capability = Object.create(contextCapability);
|
var capability = Object.create(contextCapability),
|
||||||
|
method;
|
||||||
|
|
||||||
// Check for domain object interface. If something has these
|
// Check for domain object interface. If something has these
|
||||||
// three methods, we assume it's a domain object.
|
// three methods, we assume it's a domain object.
|
||||||
@ -114,7 +115,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap all methods; return only editable domain objects.
|
// Wrap all methods; return only editable domain objects.
|
||||||
for (var method in contextCapability){
|
for (method in contextCapability) {
|
||||||
wrapMethod(method);
|
wrapMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ define(
|
|||||||
}
|
}
|
||||||
//Return the original (non-editable) object
|
//Return the original (non-editable) object
|
||||||
return returnPromise.then(function() {
|
return returnPromise.then(function() {
|
||||||
return domainObject;
|
return domainObject.getOriginalObject ? domainObject.getOriginalObject() : domainObject;
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +74,7 @@ define(
|
|||||||
expect(mockDomainObject.getCapability)
|
expect(mockDomainObject.getCapability)
|
||||||
.toHaveBeenCalledWith('action');
|
.toHaveBeenCalledWith('action');
|
||||||
expect(mockActionCapability.getActions)
|
expect(mockActionCapability.getActions)
|
||||||
.toHaveBeenCalledWith('create');
|
.toHaveBeenCalledWith('add');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("invokes the action on the selection, if any", function () {
|
it("invokes the action on the selection, if any", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user