2017-10-19 13:40:00 +00:00
|
|
|
describe('Directive acl', () => {
|
2019-10-18 19:36:30 +00:00
|
|
|
let $scope;
|
|
|
|
let $element;
|
2017-10-19 13:40:00 +00:00
|
|
|
let element;
|
|
|
|
let compile;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
beforeEach(inject(($httpBackend, aclService) => {
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET('Accounts/acl')
|
2019-10-18 19:36:30 +00:00
|
|
|
.respond({
|
|
|
|
user: {id: 1, name: 'myUser'},
|
|
|
|
roles: [
|
|
|
|
{role: {name: 'myRole'}},
|
|
|
|
{role: {name: 'myOtherRole'}}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
aclService.load();
|
|
|
|
$httpBackend.flush();
|
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
$scope.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
compile = html => {
|
|
|
|
inject(($compile, $rootScope) => {
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$element = $compile(html)($scope);
|
|
|
|
$scope.$digest();
|
|
|
|
element = $element[0];
|
2017-10-19 17:11:49 +00:00
|
|
|
});
|
2017-10-19 13:40:00 +00:00
|
|
|
};
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
it('should not disable the input element as the user owns the role', () => {
|
|
|
|
let html = `
|
|
|
|
<div
|
|
|
|
vn-acl="randomRole, myRole"
|
|
|
|
vn-acl-action="disable">
|
|
|
|
<input/>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
compile(html);
|
|
|
|
let input = element.querySelector('input');
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
expect(input.disabled).toBeFalsy();
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
it('should disable the element as the action is to disable and the user does not own the role', () => {
|
|
|
|
let html = `
|
|
|
|
<div
|
|
|
|
vn-acl="unownedRole, randomRole"
|
|
|
|
vn-acl-action="disable">
|
|
|
|
<input/>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
compile(html);
|
|
|
|
let input = element.querySelector('input');
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
expect(input.disabled).toBeTruthy();
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
it('should keep the element as the action is to remove and the user owns the role', () => {
|
|
|
|
let html = `
|
|
|
|
<section>
|
|
|
|
<div
|
|
|
|
vn-acl="myOtherRole, randomRole"
|
|
|
|
vn-acl-action="remove">
|
|
|
|
<input/>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
compile(html);
|
|
|
|
let div = element.querySelector('div');
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
expect(div).not.toBeNull();
|
2017-10-19 17:11:49 +00:00
|
|
|
});
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
it('should delete the element as the action is to remove and the user does not own the role', () => {
|
|
|
|
let html = `
|
|
|
|
<section>
|
|
|
|
<div
|
|
|
|
vn-acl="unownedRole, randomRole"
|
|
|
|
vn-acl-action="remove">
|
|
|
|
<input/>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
compile(html);
|
|
|
|
let div = element.querySelector('div');
|
2017-10-19 17:11:49 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
expect(div).toBeNull();
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
});
|