mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[Policy] Add spec for policy-driven view decorator
Add spec to allow the applicability of views to be determined by policy decisions, WTD-1062.
This commit is contained in:
parent
facf350648
commit
7915074b10
83
platform/policy/test/PolicyViewDecoratorSpec.js
Normal file
83
platform/policy/test/PolicyViewDecoratorSpec.js
Normal file
@ -0,0 +1,83 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
define(
|
||||
["../src/PolicyViewDecorator"],
|
||||
function (PolicyViewDecorator) {
|
||||
"use strict";
|
||||
|
||||
describe("The policy view decorator", function () {
|
||||
var mockPolicyService,
|
||||
mockViewService,
|
||||
mockDomainObject,
|
||||
testViews,
|
||||
decorator;
|
||||
|
||||
beforeEach(function () {
|
||||
mockPolicyService = jasmine.createSpyObj(
|
||||
'policyService',
|
||||
['allow']
|
||||
);
|
||||
mockViewService = jasmine.createSpyObj(
|
||||
'viewService',
|
||||
['getViews']
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
['getId']
|
||||
);
|
||||
|
||||
// Content of actions should be irrelevant to this
|
||||
// decorator, so just give it some objects to pass
|
||||
// around.
|
||||
testViews = [
|
||||
{ someKey: "a" },
|
||||
{ someKey: "b" },
|
||||
{ someKey: "c" }
|
||||
];
|
||||
|
||||
mockDomainObject.getId.andReturn('xyz');
|
||||
mockViewService.getViews.andReturn(testViews);
|
||||
mockPolicyService.allow.andReturn(true);
|
||||
|
||||
decorator = new PolicyViewDecorator(
|
||||
mockPolicyService,
|
||||
mockViewService
|
||||
);
|
||||
});
|
||||
|
||||
it("delegates to its decorated view service", function () {
|
||||
decorator.getViews(mockDomainObject);
|
||||
expect(mockViewService.getViews)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
it("provides views from its decorated view service", function () {
|
||||
// Mock policy service allows everything by default,
|
||||
// so everything should be returned
|
||||
expect(decorator.getActions(mockDomainObject))
|
||||
.toEqual(testViews);
|
||||
});
|
||||
|
||||
it("consults the policy service for each candidate view", function () {
|
||||
decorator.getViews(mockDomainObject);
|
||||
testViews.forEach(function (testView) {
|
||||
expect(mockPolicyService.allow).toHaveBeenCalledWith(
|
||||
'view',
|
||||
testView,
|
||||
mockDomainObject
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("filters out policy-disallowed views", function () {
|
||||
// Disallow the second action
|
||||
mockPolicyService.allow.andCallFake(function (cat, candidate, ctxt) {
|
||||
return candidate.someKey !== 'b';
|
||||
});
|
||||
expect(decorator.getViews(mockDomainObject))
|
||||
.toEqual([ testViews[0], testViews[2] ]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -1,4 +1,5 @@
|
||||
[
|
||||
"PolicyActionDecorator",
|
||||
"PolicyViewDecorator",
|
||||
"PolicyProvider"
|
||||
]
|
Loading…
Reference in New Issue
Block a user