salix/client/core/src/directives/specs/acl.spec.js

56 lines
2.0 KiB
JavaScript
Raw Normal View History

describe('Directive acl', () => {
let scope;
let element;
let compile;
let $timeout;
beforeEach(() => {
angular.mock.module('client');
});
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({});
spyOn(aclService, 'aclPermission').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);
});
});