diff --git a/src/app/components/info-drawer/comments-tab/comments-tab.component.spec.ts b/src/app/components/info-drawer/comments-tab/comments-tab.component.spec.ts index 8eaf01c68..462fd4f3d 100644 --- a/src/app/components/info-drawer/comments-tab/comments-tab.component.spec.ts +++ b/src/app/components/info-drawer/comments-tab/comments-tab.component.spec.ts @@ -24,9 +24,90 @@ */ 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', () => { - it('should be defined', () => { - expect(CommentsTabComponent).toBeDefined(); + let component: CommentsTabComponent; + let fixture: ComponentFixture; + 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 = 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 = 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 = 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 = testNode; + expect(component.canUpdateNode).toBe(true); + expect(checked).toContain('update'); + }); }); }); diff --git a/src/app/components/info-drawer/comments-tab/comments-tab.component.ts b/src/app/components/info-drawer/comments-tab/comments-tab.component.ts index d7a6825c0..c5a572012 100644 --- a/src/app/components/info-drawer/comments-tab/comments-tab.component.ts +++ b/src/app/components/info-drawer/comments-tab/comments-tab.component.ts @@ -44,10 +44,16 @@ export class CommentsTabComponent { constructor(private permission: NodePermissionService) {} get canUpdateNode(): boolean { - if (this.node && this.node.isFile && !isLocked({ entry: this.node })) { - return this.permission.check(this.node, ['update']); + if (!this.node) { + return false; } + if ( + this.node.isFolder || + (this.node.isFile && !isLocked({ entry: this.node })) + ) { + return this.permission.check(this.node, ['update']); + } return false; } }