diff --git a/client/core/src/directives/specs/acl.spec.js b/client/core/src/directives/specs/acl.spec.js new file mode 100644 index 0000000000..a20f66c2bf --- /dev/null +++ b/client/core/src/directives/specs/acl.spec.js @@ -0,0 +1,47 @@ +describe('Directive acl', () => { + let scope; + let element; + let compile; + + beforeEach(angular.mock.module($provide => { + $provide.value('aclService', {aclPermission: () => {}}); + })); + + beforeEach(() => { + angular.mock.module('client'); + }); + + compile = (hasPermissions, action) => { + inject(['$compile', '$rootScope', 'aclService', ($compile, $rootScope, aclService) => { + spyOn(aclService, 'aclPermission').and.returnValue(hasPermissions); + scope = $rootScope.$new(); + element = angular.element(`
`); + $compile(element)(scope); + scope.$digest(); + }]); + }; + + it('should not disable the input element as the user has permision', () => { + compile(true, 'disabled'); + 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', () => { + compile(false); + let input = element.find('input'); + + expect(input.length).toEqual(0); + }); + + // check if the element shouldn't be deleted if the action is to disable it with Juan/Dani + it('should disable the element as the action is to disable it but the user has no permission but present', () => { + compile(false, 'disabled'); + let input = element.find('input'); + + expect(input).toBeDefined(); + expect(input.attr('disabled')).toBeTruthy(); + }); +});