[ADF-2671] added permission check on permissions (#3521)

* [ADF-2671] start adding permission check for changing permissions

* [ADF-2671] added permission check for inherit button and permission dialog

* [ADF-2671] added permission check for inherit button and permission dialog

* [ADF-2671] start fixing and adding test for new permission check

* ]
[ADF-2671] improved check for node-permission directive

* [ADF-2671] fixed and added more test for permission on permissions

* [ADF-2671] reverting change on node-permission directive

* [ADF-2671] fixing test for permission check
This commit is contained in:
Vito
2018-06-27 15:15:57 +01:00
committed by Eugenio Romano
parent 7563f91665
commit 9fef181155
8 changed files with 170 additions and 60 deletions

View File

@@ -19,7 +19,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AddPermissionComponent } from './add-permission.component';
import { AddPermissionPanelComponent } from './add-permission-panel.component';
import { By } from '@angular/platform-browser';
import { setupTestBed } from '@alfresco/adf-core';
import { setupTestBed, NodesApiService } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
import { fakeAuthorityResults } from '../../../mock/add-permission.component.mock';
import { ContentTestingModule } from '../../../testing/content.testing.module';
@@ -30,6 +30,7 @@ describe('AddPermissionComponent', () => {
let fixture: ComponentFixture<AddPermissionComponent>;
let element: HTMLElement;
let nodePermissionService: NodePermissionService;
let nodeApiService: NodesApiService;
setupTestBed({
imports: [
@@ -38,6 +39,8 @@ describe('AddPermissionComponent', () => {
});
beforeEach(() => {
nodeApiService = TestBed.get(NodesApiService);
spyOn(nodeApiService, 'getNode').and.returnValue(Observable.of({ id: 'fake-node', allowableOperations: ['updatePermissions']}));
fixture = TestBed.createComponent(AddPermissionComponent);
element = fixture.nativeElement;
nodePermissionService = TestBed.get(NodePermissionService);
@@ -67,12 +70,24 @@ describe('AddPermissionComponent', () => {
});
}));
it('should emit a success event when the node is updated', async(() => {
it('should NOT enable the ADD button when a selection is sent but the user does not have the permissions', async(() => {
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
fixture.componentInstance.currentNode = {id: 'fake-node-id'};
fixture.whenStable().then(() => {
fixture.detectChanges();
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
expect(addButton.disabled).toBeTruthy();
});
}));
it('should emit a success event when the node is updated', (done) => {
fixture.componentInstance.selectedItems = fakeAuthorityResults;
spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(Observable.of({ id: 'fake-node-id'}));
fixture.componentInstance.success.subscribe((node) => {
expect(node.id).toBe('fake-node-id');
done();
});
fixture.detectChanges();
@@ -81,14 +96,25 @@ describe('AddPermissionComponent', () => {
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
addButton.click();
});
}));
});
it('should emit an error event when the node update fail', async(() => {
it('should NOT emit a success event when the user does not have permission to update the node', () => {
fixture.componentInstance.selectedItems = fakeAuthorityResults;
fixture.componentInstance.currentNode = { id: 'fake-node-id' };
spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(Observable.of({ id: 'fake-node-id' }));
let spySuccess = spyOn(fixture.componentInstance, 'success');
fixture.componentInstance.applySelection();
expect(spySuccess).not.toHaveBeenCalled();
});
it('should emit an error event when the node update fail', (done) => {
fixture.componentInstance.selectedItems = fakeAuthorityResults;
spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(Observable.throw({ error: 'errored'}));
fixture.componentInstance.error.subscribe((error) => {
expect(error.error).toBe('errored');
done();
});
fixture.detectChanges();
@@ -97,6 +123,6 @@ describe('AddPermissionComponent', () => {
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
addButton.click();
});
}));
});
});