mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 22:28:13 +00:00
[Copy] #338 added CreationPolicy and appropriate tests, amended CreateActionProvider, and updated existing tests
This commit is contained in:
@ -33,6 +33,9 @@ define(
|
||||
var mockTypeService,
|
||||
mockDialogService,
|
||||
mockCreationService,
|
||||
mockPolicyService,
|
||||
mockCreationPolicy,
|
||||
mockPolicyMap = {},
|
||||
mockTypes,
|
||||
provider;
|
||||
|
||||
@ -67,14 +70,32 @@ define(
|
||||
"creationService",
|
||||
[ "createObject" ]
|
||||
);
|
||||
mockPolicyService = jasmine.createSpyObj(
|
||||
"policyService",
|
||||
[ "allow" ]
|
||||
);
|
||||
|
||||
mockTypes = [ "A", "B", "C" ].map(createMockType);
|
||||
|
||||
mockTypes.forEach(function(type){
|
||||
mockPolicyMap[type.getName()] = true;
|
||||
});
|
||||
|
||||
mockCreationPolicy = function(type){
|
||||
return mockPolicyMap[type.getName()];
|
||||
};
|
||||
|
||||
mockPolicyService.allow.andCallFake(function(category, type){
|
||||
return category === "creation" && mockCreationPolicy(type) ? true : false;
|
||||
});
|
||||
|
||||
mockTypeService.listTypes.andReturn(mockTypes);
|
||||
|
||||
provider = new CreateActionProvider(
|
||||
mockTypeService,
|
||||
mockDialogService,
|
||||
mockCreationService
|
||||
mockCreationService,
|
||||
mockPolicyService
|
||||
);
|
||||
});
|
||||
|
||||
@ -94,15 +115,15 @@ define(
|
||||
|
||||
it("does not expose non-creatable types", function () {
|
||||
// One of the types won't have the creation feature...
|
||||
mockTypes[1].hasFeature.andReturn(false);
|
||||
mockPolicyMap[mockTypes[0].getName()] = false;
|
||||
// ...so it should have been filtered out.
|
||||
expect(provider.getActions({
|
||||
key: "create",
|
||||
domainObject: {}
|
||||
}).length).toEqual(2);
|
||||
// Make sure it was creation which was used to check
|
||||
expect(mockTypes[1].hasFeature)
|
||||
.toHaveBeenCalledWith("creation");
|
||||
expect(mockPolicyService.allow)
|
||||
.toHaveBeenCalledWith("creation", mockTypes[0]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user