diff --git a/demo-shell/src/app/components/log/log.component.ts b/demo-shell/src/app/components/log/log.component.ts index 52033f384e..1db5c71141 100644 --- a/demo-shell/src/app/components/log/log.component.ts +++ b/demo-shell/src/app/components/log/log.component.ts @@ -32,11 +32,13 @@ export class LogComponent { constructor(public logService: LogService) { logService.onMessage.subscribe((message) => { - this.logs.push({ type: message.type, text: JSON.stringify(message.text) }); - this.logsData = new ObjectDataTableAdapter(this.logs, [ - { type: 'text', key: 'type', title: 'Log level', sortable: true }, - { type: 'text', key: 'text', title: 'Message', sortable: false } - ]); + if (typeof message.text === 'string') { + this.logs.push({ type: message.type, text: JSON.stringify(message.text) }); + this.logsData = new ObjectDataTableAdapter(this.logs, [ + { type: 'text', key: 'type', title: 'Log level', sortable: true }, + { type: 'text', key: 'text', title: 'Message', sortable: false } + ]); + } }); } diff --git a/lib/content-services/dialogs/share.dialog.html b/lib/content-services/dialogs/share.dialog.html index 8b445c7516..c1e9cde367 100644 --- a/lib/content-services/dialogs/share.dialog.html +++ b/lib/content-services/dialogs/share.dialog.html @@ -1,22 +1,22 @@ -

{{ 'SHARE.TITLE' | translate }} {{fileName}}

+

{{ 'SHARE.TITLE' | translate }} {{fileName}}

- + {{ 'SHARE.ACTIONS.SHARE' | translate }} - . -

{{ 'SHARE.DESCRIPTION' | translate }}

{{ 'SHARE.ALERT' | translate }}
- + link
diff --git a/lib/content-services/dialogs/share.dialog.spec.ts b/lib/content-services/dialogs/share.dialog.spec.ts index afcf0cfb8e..34de90d2a1 100644 --- a/lib/content-services/dialogs/share.dialog.spec.ts +++ b/lib/content-services/dialogs/share.dialog.spec.ts @@ -15,18 +15,20 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { async, TestBed } from '@angular/core/testing'; import { ComponentFixture } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { Observable } from 'rxjs/Observable'; import { ShareDialogComponent } from './share.dialog'; import { ContentTestingModule } from '../testing/content.testing.module'; -import { setupTestBed } from '@alfresco/adf-core'; +import { SharedLinksApiService, setupTestBed } from '@alfresco/adf-core'; describe('ShareDialogComponent', () => { let fixture: ComponentFixture; + let spyCreate: any; let component: ShareDialogComponent; + let sharedLinksApiService: SharedLinksApiService; const dialogRef = { close: jasmine.createSpy('close') }; @@ -46,36 +48,44 @@ describe('ShareDialogComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ShareDialogComponent); + sharedLinksApiService = TestBed.get(SharedLinksApiService); component = fixture.componentInstance; fixture.detectChanges(); + + spyCreate = spyOn(sharedLinksApiService, 'createSharedLinks').and.returnValue(Observable.of({ entry: { id: 'test-sharedId' } })); }); - it('should init the dialog with the file name and baseShareUrl', () => { - expect(component.fileName).toBe('example-name'); - expect(component.baseShareUrl).toBe('baseShareUrl-example'); - }); + it('should init the dialog with the file name and baseShareUrl', async(() => { + component.data = { + baseShareUrl: 'base-url/', + node: { entry: { properties: { 'qshare:sharedId': 'example-link' }, name: 'example-name' } } + }; + + component.ngOnInit(); + + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(fixture.nativeElement.querySelector('#adf-share-link').value).toBe('base-url/example-link'); + }); + })); describe('public link creation', () => { it('should not create the public link if it already present in the node', () => { - let spyCreate = spyOn(component, 'createSharedLinks').and.returnValue(Observable.of('')); + component.data = { + node: { entry: { properties: { 'qshare:sharedId': 'example-link' }, name: 'example-name' } } + }; component.ngOnInit(); expect(spyCreate).not.toHaveBeenCalled(); }); - it('should not create the public link if it already present in the node', () => { + it('should create the public link if is not present in the node', () => { component.data = { - node: { entry: { name: 'example-name' } }, - baseShareUrl: 'baseShareUrl-example' - }; - - let spyCreate = spyOn(component, 'createSharedLinks').and.returnValue(Observable.of('')); - - data = { - node: { entry: { name: 'example-name' } }, + node: { entry: { properties: {}, name: 'example-name' } }, baseShareUrl: 'baseShareUrl-example' }; @@ -83,6 +93,20 @@ describe('ShareDialogComponent', () => { expect(spyCreate).toHaveBeenCalled(); }); + + it('should update the data structure after created the link', async(() => { + component.data = { + node: { entry: { name: 'example-name', properties: {} } }, + baseShareUrl: 'baseShareUrl-example' + }; + component.ngOnInit(); + + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(component.data.node.entry.properties['qshare:sharedId']).toBe('test-sharedId'); + }); + })); }); }); diff --git a/lib/content-services/dialogs/share.dialog.ts b/lib/content-services/dialogs/share.dialog.ts index 3b43a79726..42b0d26a75 100644 --- a/lib/content-services/dialogs/share.dialog.ts +++ b/lib/content-services/dialogs/share.dialog.ts @@ -74,6 +74,7 @@ export class ShareDialogComponent implements OnInit { this.sharedLinksApiService.createSharedLinks(nodeId).subscribe((sharedLink: SharedLinkEntry) => { if (sharedLink.entry) { this.sharedId = sharedLink.entry.id; + this.data.node.entry.properties['qshare:sharedId'] = this.sharedId; this.isFileShared = true; this.isDisabled = false; }