mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 23:20:50 +00:00
Merge remote-tracking branch 'origin/open723' into open-master
This commit is contained in:
commit
107ed51cfc
@ -57,7 +57,11 @@ define(
|
|||||||
* will be performed; should contain a `domainObject` property
|
* will be performed; should contain a `domainObject` property
|
||||||
*/
|
*/
|
||||||
EditAction.appliesTo = function (context) {
|
EditAction.appliesTo = function (context) {
|
||||||
return (context || {}).domainObject !== undefined;
|
var domainObject = (context || {}).domainObject,
|
||||||
|
type = domainObject && domainObject.getCapability('type');
|
||||||
|
|
||||||
|
// Only allow creatable types to be edited
|
||||||
|
return type && type.hasFeature('creation');
|
||||||
};
|
};
|
||||||
|
|
||||||
return EditAction;
|
return EditAction;
|
||||||
|
@ -70,9 +70,14 @@ define(
|
|||||||
* context.
|
* context.
|
||||||
*/
|
*/
|
||||||
PropertiesAction.appliesTo = function (context) {
|
PropertiesAction.appliesTo = function (context) {
|
||||||
return (context || {}).domainObject &&
|
var domainObject = (context || {}).domainObject,
|
||||||
(context || {}).domainObject.hasCapability("type") &&
|
type = domainObject && domainObject.getCapability('type'),
|
||||||
(context || {}).domainObject.hasCapability("persistence");
|
creatable = type && type.hasFeature('creation');
|
||||||
|
|
||||||
|
// Only allow creatable types to be edited
|
||||||
|
return domainObject &&
|
||||||
|
domainObject.hasCapability("persistence") &&
|
||||||
|
creatable;
|
||||||
};
|
};
|
||||||
|
|
||||||
return PropertiesAction;
|
return PropertiesAction;
|
||||||
|
@ -80,9 +80,14 @@ define(
|
|||||||
RemoveAction.appliesTo = function (context) {
|
RemoveAction.appliesTo = function (context) {
|
||||||
var object = (context || {}).domainObject,
|
var object = (context || {}).domainObject,
|
||||||
contextCapability = object && object.getCapability("context"),
|
contextCapability = object && object.getCapability("context"),
|
||||||
parent = contextCapability && contextCapability.getParent();
|
parent = contextCapability && contextCapability.getParent(),
|
||||||
|
parentType = parent && parent.getCapability('type'),
|
||||||
|
parentCreatable = parentType && parentType.hasFeature('creation');
|
||||||
|
|
||||||
|
// Only creatable types should be modifiable
|
||||||
return parent !== undefined &&
|
return parent !== undefined &&
|
||||||
Array.isArray(parent.getModel().composition);
|
Array.isArray(parent.getModel().composition) &&
|
||||||
|
parentCreatable;
|
||||||
};
|
};
|
||||||
|
|
||||||
return RemoveAction;
|
return RemoveAction;
|
||||||
|
@ -10,6 +10,7 @@ define(
|
|||||||
mockNavigationService,
|
mockNavigationService,
|
||||||
mockLog,
|
mockLog,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
|
mockType,
|
||||||
actionContext,
|
actionContext,
|
||||||
action;
|
action;
|
||||||
|
|
||||||
@ -30,6 +31,13 @@ define(
|
|||||||
"domainObject",
|
"domainObject",
|
||||||
[ "getId", "getModel", "getCapability" ]
|
[ "getId", "getModel", "getCapability" ]
|
||||||
);
|
);
|
||||||
|
mockType = jasmine.createSpyObj(
|
||||||
|
"type",
|
||||||
|
[ "hasFeature" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
mockDomainObject.getCapability.andReturn(mockType);
|
||||||
|
mockType.hasFeature.andReturn(true);
|
||||||
|
|
||||||
actionContext = { domainObject: mockDomainObject };
|
actionContext = { domainObject: mockDomainObject };
|
||||||
|
|
||||||
@ -44,6 +52,8 @@ define(
|
|||||||
it("is only applicable when a domain object is present", function () {
|
it("is only applicable when a domain object is present", function () {
|
||||||
expect(EditAction.appliesTo(actionContext)).toBeTruthy();
|
expect(EditAction.appliesTo(actionContext)).toBeTruthy();
|
||||||
expect(EditAction.appliesTo({})).toBeFalsy();
|
expect(EditAction.appliesTo({})).toBeFalsy();
|
||||||
|
// Should have checked for creatability
|
||||||
|
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes URL path to edit mode when performed", function () {
|
it("changes URL path to edit mode when performed", function () {
|
||||||
|
@ -18,7 +18,10 @@ define(
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
capabilities = {
|
capabilities = {
|
||||||
type: { getProperties: function () { return []; } },
|
type: {
|
||||||
|
getProperties: function () { return []; },
|
||||||
|
hasFeature: jasmine.createSpy('hasFeature')
|
||||||
|
},
|
||||||
persistence: jasmine.createSpyObj("persistence", ["persist"]),
|
persistence: jasmine.createSpyObj("persistence", ["persist"]),
|
||||||
mutation: jasmine.createSpy("mutation")
|
mutation: jasmine.createSpy("mutation")
|
||||||
};
|
};
|
||||||
@ -38,6 +41,7 @@ define(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
capabilities.type.hasFeature.andReturn(true);
|
||||||
capabilities.mutation.andReturn(true);
|
capabilities.mutation.andReturn(true);
|
||||||
|
|
||||||
action = new PropertiesAction(dialogService, context);
|
action = new PropertiesAction(dialogService, context);
|
||||||
@ -65,6 +69,8 @@ define(
|
|||||||
it("is only applicable when a domain object is in context", function () {
|
it("is only applicable when a domain object is in context", function () {
|
||||||
expect(PropertiesAction.appliesTo(context)).toBeTruthy();
|
expect(PropertiesAction.appliesTo(context)).toBeTruthy();
|
||||||
expect(PropertiesAction.appliesTo({})).toBeFalsy();
|
expect(PropertiesAction.appliesTo({})).toBeFalsy();
|
||||||
|
// Make sure it checked for creatability
|
||||||
|
expect(capabilities.type.hasFeature).toHaveBeenCalledWith('creation');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ define(
|
|||||||
mockContext,
|
mockContext,
|
||||||
mockMutation,
|
mockMutation,
|
||||||
mockPersistence,
|
mockPersistence,
|
||||||
|
mockType,
|
||||||
actionContext,
|
actionContext,
|
||||||
model,
|
model,
|
||||||
capabilities,
|
capabilities,
|
||||||
@ -47,16 +48,18 @@ define(
|
|||||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||||
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
||||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||||
|
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||||
|
|
||||||
mockDomainObject.getId.andReturn("test");
|
mockDomainObject.getId.andReturn("test");
|
||||||
mockDomainObject.getCapability.andReturn(mockContext);
|
mockDomainObject.getCapability.andReturn(mockContext);
|
||||||
mockContext.getParent.andReturn(mockParent);
|
mockContext.getParent.andReturn(mockParent);
|
||||||
|
mockType.hasFeature.andReturn(true);
|
||||||
|
|
||||||
|
|
||||||
capabilities = {
|
capabilities = {
|
||||||
mutation: mockMutation,
|
mutation: mockMutation,
|
||||||
persistence: mockPersistence
|
persistence: mockPersistence,
|
||||||
|
type: mockType
|
||||||
};
|
};
|
||||||
model = {
|
model = {
|
||||||
composition: [ "a", "test", "b", "c" ]
|
composition: [ "a", "test", "b", "c" ]
|
||||||
@ -73,6 +76,9 @@ define(
|
|||||||
mockContext.getParent.andReturn(undefined);
|
mockContext.getParent.andReturn(undefined);
|
||||||
|
|
||||||
expect(RemoveAction.appliesTo(actionContext)).toBeFalsy();
|
expect(RemoveAction.appliesTo(actionContext)).toBeFalsy();
|
||||||
|
|
||||||
|
// Also verify that creatability was checked
|
||||||
|
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("mutates the parent when performed", function () {
|
it("mutates the parent when performed", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user