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) => {
|
2018-01-30 13:48:21 +00:00
|
|
|
inject(($compile, $rootScope, aclService, _$timeout_, _$httpBackend_) => {
|
|
|
|
_$httpBackend_.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
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();
|
|
|
|
});
|
|
|
|
|
2018-10-11 07:41:30 +00:00
|
|
|
it('should delete any element with the tag vn-drop-down', () => {
|
|
|
|
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><vn-drop-down></vn-drop-down><input/></div>`;
|
2017-10-19 17:11:49 +00:00
|
|
|
compile(false, html);
|
|
|
|
|
2018-10-11 07:41:30 +00:00
|
|
|
expect(element.find('vn-drop-down').length).toBe(0);
|
2017-10-19 13:40:00 +00:00
|
|
|
});
|
|
|
|
});
|