client side unit test for acl directive, comment added about directive behavior.
This commit is contained in:
parent
d9da2e5874
commit
94bfe50818
|
@ -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(`<div><input vn-acl="administrative,client" vn-acl-action="${action}"/></div>`);
|
||||
$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();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue