mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-06-02 17:34:51 +00:00
[ACA-2270] allow add comments on folder (#1018)
* [ACA-2270] allow add comments on folder * [ACA-2270] fix return on else * [ACA-2270] add unit tests
This commit is contained in:
parent
147924f6c3
commit
4508b862b9
@ -24,9 +24,90 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CommentsTabComponent } from './comments-tab.component';
|
import { CommentsTabComponent } from './comments-tab.component';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { NodePermissionService } from '../../../services/node-permission.service';
|
||||||
|
|
||||||
describe('CommentsTabComponent', () => {
|
describe('CommentsTabComponent', () => {
|
||||||
it('should be defined', () => {
|
let component: CommentsTabComponent;
|
||||||
expect(CommentsTabComponent).toBeDefined();
|
let fixture: ComponentFixture<CommentsTabComponent>;
|
||||||
|
const permissionsMock = {
|
||||||
|
check: jasmine.createSpy('check')
|
||||||
|
};
|
||||||
|
let checked;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [AppTestingModule],
|
||||||
|
declarations: [CommentsTabComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: NodePermissionService, useValue: permissionsMock }
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(CommentsTabComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
|
checked = null;
|
||||||
|
permissionsMock.check.and.callFake((source, permissions) => {
|
||||||
|
checked = permissions;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('canUpdateNode', () => {
|
||||||
|
it('should return [false] if no node selected', () => {
|
||||||
|
component.node = null;
|
||||||
|
expect(component.canUpdateNode).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return [false] if node selected is neither file or folder', () => {
|
||||||
|
const testNode = {
|
||||||
|
id: 'test-node-id',
|
||||||
|
isFile: false,
|
||||||
|
isFolder: false
|
||||||
|
};
|
||||||
|
component.node = <any>testNode;
|
||||||
|
expect(component.canUpdateNode).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return [false] if node selected is a locked file', () => {
|
||||||
|
const testNode = {
|
||||||
|
id: 'test-node-id',
|
||||||
|
isFile: true,
|
||||||
|
isFolder: false,
|
||||||
|
isLocked: true
|
||||||
|
};
|
||||||
|
component.node = <any>testNode;
|
||||||
|
expect(component.canUpdateNode).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check [update] permission if node selected is a not locked file', () => {
|
||||||
|
const testNode = {
|
||||||
|
id: 'test-node-id',
|
||||||
|
isFile: true,
|
||||||
|
isFolder: false
|
||||||
|
};
|
||||||
|
component.node = <any>testNode;
|
||||||
|
expect(component.canUpdateNode).toBe(true);
|
||||||
|
expect(checked).toContain('update');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check [update] permission if node selected is a folder', () => {
|
||||||
|
const testNode = {
|
||||||
|
id: 'test-node-id',
|
||||||
|
isFile: false,
|
||||||
|
isFolder: true
|
||||||
|
};
|
||||||
|
component.node = <any>testNode;
|
||||||
|
expect(component.canUpdateNode).toBe(true);
|
||||||
|
expect(checked).toContain('update');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -44,10 +44,16 @@ export class CommentsTabComponent {
|
|||||||
constructor(private permission: NodePermissionService) {}
|
constructor(private permission: NodePermissionService) {}
|
||||||
|
|
||||||
get canUpdateNode(): boolean {
|
get canUpdateNode(): boolean {
|
||||||
if (this.node && this.node.isFile && !isLocked({ entry: this.node })) {
|
if (!this.node) {
|
||||||
return this.permission.check(this.node, ['update']);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.node.isFolder ||
|
||||||
|
(this.node.isFile && !isLocked({ entry: this.node }))
|
||||||
|
) {
|
||||||
|
return this.permission.check(this.node, ['update']);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user