salix/front/core/directives/specs/acl.spec.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

describe('Directive acl', () => {
let scope;
let element;
let compile;
let $timeout;
beforeEach(ngModule('vnCore'));
compile = (hasPermissions, _element) => {
inject(($compile, $rootScope, aclService, _$timeout_) => {
spyOn(aclService, 'hasAny').and.returnValue(hasPermissions);
scope = $rootScope.$new();
$timeout = _$timeout_;
element = angular.element(_element);
$compile(element)(scope);
scope.$digest();
});
};
it('should not disable the input element as the user has permision', () => {
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
compile(true, html);
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', () => {
let html = `<container><div vn-acl="administrative,client" vn-acl-action="anything but disabled"><input/></div></container>`;
compile(false, html);
expect(element.children().length).toEqual(0);
});
it('should disable the element as the action is to disable it but the user has no permission but present', () => {
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
compile(false, html);
let input = element.find('input');
$timeout.flush();
expect(input).toBeDefined();
expect(input.attr('disabled')).toBeTruthy();
});
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>`;
compile(false, html);
expect(element.find('vn-drop-down').length).toBe(0);
});
});