[ADF-2710] removed default shared link creation at the opening (#3430)

This commit is contained in:
Vito
2018-06-05 09:56:50 +01:00
committed by Eugenio Romano
parent 71d5259cb4
commit a41ad9ce00
2 changed files with 26 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ describe('ShareDialogComponent', () => {
let fixture: ComponentFixture<ShareDialogComponent>;
let spyCreate: any;
let spyDelete: any;
let component: ShareDialogComponent;
let sharedLinksApiService: SharedLinksApiService;
const dialogRef = {
@@ -54,6 +55,7 @@ describe('ShareDialogComponent', () => {
fixture.detectChanges();
spyCreate = spyOn(sharedLinksApiService, 'createSharedLinks').and.returnValue(Observable.of({ entry: { id: 'test-sharedId' } }));
spyDelete = spyOn(sharedLinksApiService, 'deleteSharedLink').and.returnValue(Observable.of({}));
});
it('should init the dialog with the file name and baseShareUrl', async(() => {
@@ -83,7 +85,7 @@ describe('ShareDialogComponent', () => {
expect(spyCreate).not.toHaveBeenCalled();
});
it('should create the public link if is not present in the node', () => {
it('should not create the public link if is not present in the node', () => {
component.data = {
node: { entry: { properties: {}, name: 'example-name' } },
baseShareUrl: 'baseShareUrl-example'
@@ -91,20 +93,34 @@ describe('ShareDialogComponent', () => {
component.ngOnInit();
expect(spyCreate).toHaveBeenCalled();
expect(spyCreate).not.toHaveBeenCalled();
});
it('should update the data structure after created the link', async(() => {
it('should be able to delete the shared link', async(() => {
component.data = {
node: { entry: { name: 'example-name', properties: {} } },
node: { entry: { name: 'example-name', properties: { 'qshare:sharedId': 'example-link' } } },
baseShareUrl: 'baseShareUrl-example'
};
component.ngOnInit();
fixture.detectChanges();
fixture.nativeElement.querySelector('#adf-share-toggle-input').click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.data.node.entry.properties['qshare:sharedId']).toBe('test-sharedId');
expect(spyDelete).toHaveBeenCalled();
expect(component.data.node.entry.properties['qshare:sharedId']).toBeNull();
});
}));
it('should show the toggle disabled when the shareid property is null', async(() => {
component.data = {
node: { entry: { name: 'example-name', properties: { 'qshare:sharedId': null } } },
baseShareUrl: 'baseShareUrl-example'
};
component.ngOnInit();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.nativeElement.querySelector('#adf-share-toggle')).not.toBeNull();
expect(fixture.nativeElement.querySelector('#adf-share-toggle.mat-checked')).toBeNull();
});
}));
});

View File

@@ -52,7 +52,8 @@ export class ShareDialogComponent implements OnInit {
this.sharedId = this.data.node.entry.properties['qshare:sharedId'];
this.isFileShared = true;
} else {
this.createSharedLinks(this.data.node.entry.id);
this.isFileShared = false;
this.isDisabled = false;
}
}
}
@@ -87,6 +88,7 @@ export class ShareDialogComponent implements OnInit {
deleteSharedLink(sharedId: string) {
this.sharedLinksApiService.deleteSharedLink(sharedId).subscribe(() => {
this.data.node.entry.properties['qshare:sharedId'] = null;
this.isFileShared = false;
this.isDisabled = false;
},