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
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2017-10-19 13:40:00 +00:00
|
|
|
|
2017-10-19 17:11:49 +00:00
|
|
|
compile = (hasPermissions, _element) => {
|
2018-12-22 10:59:26 +00:00
|
|
|
inject(($compile, $rootScope, aclService, _$timeout_) => {
|
2019-01-23 12:11:44 +00:00
|
|
|
spyOn(aclService, 'hasAny').and.returnValue(hasPermissions);
|
2017-10-19 13:40:00 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|