96 lines
2.5 KiB
JavaScript
96 lines
2.5 KiB
JavaScript
describe('Directive acl', () => {
|
|
let $scope;
|
|
let $element;
|
|
let element;
|
|
let compile;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
beforeEach(inject(($httpBackend, aclService) => {
|
|
$httpBackend.whenGET('VnUsers/acl')
|
|
.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];
|
|
});
|
|
};
|
|
|
|
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');
|
|
|
|
expect(input.disabled).toBeFalsy();
|
|
});
|
|
|
|
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');
|
|
|
|
expect(input.disabled).toBeTruthy();
|
|
});
|
|
|
|
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');
|
|
|
|
expect(div).not.toBeNull();
|
|
});
|
|
|
|
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');
|
|
|
|
expect(div).toBeNull();
|
|
});
|
|
});
|