describe('Directive acl', () => {
let $scope;
let $element;
let element;
let compile;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($httpBackend, aclService) => {
$httpBackend.whenGET('Accounts/acl')
.respond({
user: {id: 1, name: 'myUser'},
roles: [
{role: {name: 'myRole'}},
{role: {name: 'myOtherRole'}}
]
});
aclService.load();
$httpBackend.flush();
}));
afterEach(() => {
$element.remove();
$scope.$destroy();
});
compile = html => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
$element = $compile(html)($scope);
$scope.$digest();
element = $element[0];
});
};
it('should not disable the input element as the user owns the role', () => {
let html = `
`;
compile(html);
let input = element.querySelector('input');
expect(input.disabled).toBeFalsy();
});
it('should disable the element as the action is to disable and the user does not own the role', () => {
let html = `
`;
compile(html);
let input = element.querySelector('input');
expect(input.disabled).toBeTruthy();
});
it('should keep the element as the action is to remove and the user owns the role', () => {
let html = `
`;
compile(html);
let div = element.querySelector('div');
expect(div).not.toBeNull();
});
it('should delete the element as the action is to remove and the user does not own the role', () => {
let html = `
`;
compile(html);
let div = element.querySelector('div');
expect(div).toBeNull();
});
});