mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-2995] Permissions - Consumer should be able to upload a new version for his file on a private site (#3326)
* check node permission instead of parent * tests
This commit is contained in:
committed by
Eugenio Romano
parent
35ee120d5c
commit
374c5a3fed
@@ -20,7 +20,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ContentService, UploadService, TranslationService, setupTestBed, CoreModule } from '@alfresco/adf-core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { TranslationMock } from '@alfresco/adf-core';
|
||||
import { TranslationMock, PermissionsEnum } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('UploadButtonComponent', () => {
|
||||
@@ -100,6 +100,22 @@ describe('UploadButtonComponent', () => {
|
||||
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should disable uploadFolder button if disabled is true', () => {
|
||||
component.disabled = true;
|
||||
component.uploadFolders = true;
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#uploadFolder').getAttribute('disabled')).toBe('true');
|
||||
});
|
||||
|
||||
it('should disable upload-single-file button if disabled is true', () => {
|
||||
component.disabled = true;
|
||||
component.multipleFiles = false;
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#upload-single-file').getAttribute('disabled')).toBe('true');
|
||||
});
|
||||
|
||||
it('should call uploadFile with the default root folder', () => {
|
||||
component.rootFolderId = '-root-';
|
||||
component.success = null;
|
||||
@@ -130,6 +146,18 @@ describe('UploadButtonComponent', () => {
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('should not call uploadFiles if rootFolderId is null', () => {
|
||||
component.rootFolderId = null;
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, null, true) });
|
||||
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create a folder and emit an File uploaded event', (done) => {
|
||||
component.rootFolderId = '-my-';
|
||||
|
||||
@@ -312,4 +340,88 @@ describe('UploadButtonComponent', () => {
|
||||
expect(addToQueueSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('uploadFiles permission', () => {
|
||||
let fakeNodeWithNoPermission;
|
||||
|
||||
beforeEach(() => {
|
||||
fakeNodeWithNoPermission = {
|
||||
entry: {}
|
||||
};
|
||||
});
|
||||
|
||||
it('should not call uploadFiles for node without permission', () => {
|
||||
component.rootFolderId = 'nodeId';
|
||||
|
||||
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeNodeWithNoPermission));
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
|
||||
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call uploadFiles when getNode fails', () => {
|
||||
component.rootFolderId = 'nodeId';
|
||||
|
||||
spyOn(contentService, 'getNode').and.returnValue(Observable.throw('error'));
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
|
||||
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit an error message when getNode fails', (done) => {
|
||||
component.rootFolderId = 'nodeId';
|
||||
|
||||
spyOn(contentService, 'getNode').and.returnValue(Observable.throw('error'));
|
||||
|
||||
component.error.subscribe((value) => {
|
||||
expect(value).toBe('error');
|
||||
done();
|
||||
});
|
||||
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
});
|
||||
|
||||
it('should not call uploadFiles for node with other permissions', () => {
|
||||
component.rootFolderId = 'nodeId';
|
||||
|
||||
fakeNodeWithNoPermission.entry.allowableOperations = ['other'];
|
||||
|
||||
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeNodeWithNoPermission));
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
|
||||
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call uploadFiles when node has CREATE', () => {
|
||||
component.rootFolderId = 'nodeId';
|
||||
|
||||
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
|
||||
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
|
||||
|
||||
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user