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 = `
`; 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 = `
`; 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 = `
`; 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 = `
`; compile(false, html); expect(element.find('vn-drop-down').length).toBe(0); }); });