2017-10-19 13:40:00 +00:00
|
|
|
describe('Directive acl', () => {
|
|
|
|
let scope;
|
|
|
|
let element;
|
|
|
|
let compile;
|
2017-10-19 17:11:49 +00:00
|
|
|
let $timeout;
|
2017-10-19 13:40:00 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
2017-10-19 17:11:49 +00:00
|
|
|
compile = (hasPermissions, _element) => {
|
|
|
|
inject(($compile, $rootScope, aclService, _$timeout_) => {
|
2017-10-19 13:40:00 +00:00
|
|
|
spyOn(aclService, 'aclPermission').and.returnValue(hasPermissions);
|
|
|
|
scope = $rootScope.$new();
|
2017-10-19 17:11:49 +00:00
|
|
|
$timeout = _$timeout_;
|
|
|
|
element = angular.element(_element);
|
2017-10-19 13:40:00 +00:00
|
|
|
$compile(element)(scope);
|
|
|
|
scope.$digest();
|
2017-10-19 17:11:49 +00:00
|
|
|
});
|
2017-10-19 13:40:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should not disable the input element as the user has permision', () => {
|
2017-10-19 17:11:49 +00:00
|
|
|
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
|
|
|
|
compile(true, html);
|
2017-10-19 13:40:00 +00:00
|
|
|
let input = element.find('input');
|
|
|
|
|
|
|
|
expect(input).toBeDefined();
|
|
|
|
expect(input.attr('disabled')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the element as the user does not have permission and there is no action', () => {
|
2017-10-19 17:11:49 +00:00
|
|
|
let html = `<container><div vn-acl="administrative,client" vn-acl-action="anything but disabled"><input/></div></container>`;
|
|
|
|
compile(false, html);
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2017-10-19 17:11:49 +00:00
|
|
|
expect(element.children().length).toEqual(0);
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should disable the element as the action is to disable it but the user has no permission but present', () => {
|
2017-10-19 17:11:49 +00:00
|
|
|
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
|
|
|
|
compile(false, html);
|
2017-10-19 13:40:00 +00:00
|
|
|
let input = element.find('input');
|
2017-10-19 17:11:49 +00:00
|
|
|
$timeout.flush();
|
2017-10-19 13:40:00 +00:00
|
|
|
|
|
|
|
expect(input).toBeDefined();
|
2017-10-19 17:11:49 +00:00
|
|
|
expect(input.attr('disabled')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete any element with the tag i and vn-drop-down', () => {
|
|
|
|
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><label><i/></label><input/></div>`;
|
|
|
|
compile(false, html);
|
|
|
|
|
|
|
|
expect(element.find('i').length).toBe(0);
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
});
|