diff --git a/lib/content-services/content-node-share/content-node-share.dialog.html b/lib/content-services/content-node-share/content-node-share.dialog.html index 096e99dace..d70fb6ac16 100644 --- a/lib/content-services/content-node-share/content-node-share.dialog.html +++ b/lib/content-services/content-node-share/content-node-share.dialog.html @@ -12,7 +12,7 @@ @@ -48,4 +48,12 @@ + +
+ +
diff --git a/lib/content-services/content-node-share/content-node-share.dialog.spec.ts b/lib/content-services/content-node-share/content-node-share.dialog.spec.ts index d233edd708..c1f6195780 100644 --- a/lib/content-services/content-node-share/content-node-share.dialog.spec.ts +++ b/lib/content-services/content-node-share/content-node-share.dialog.spec.ts @@ -16,10 +16,16 @@ */ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { TestBed, fakeAsync } from '@angular/core/testing'; +import { TestBed, fakeAsync, async } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material'; import { of } from 'rxjs'; -import { setupTestBed, CoreModule, SharedLinksApiService, NodesApiService } from '@alfresco/adf-core'; +import { + setupTestBed, + CoreModule, + SharedLinksApiService, + NodesApiService, + NotificationService +} from '@alfresco/adf-core'; import { ContentNodeShareModule } from './content-node-share.module'; import { ShareDialogComponent } from './content-node-share.dialog'; import moment from 'moment-es6'; @@ -27,6 +33,9 @@ import moment from 'moment-es6'; describe('ShareDialogComponent', () => { let node; let matDialog: MatDialog; + let notificationServiceMock = { + openSnackMessage: jasmine.createSpy('openSnackMessage') + }; let sharedLinksApiService: SharedLinksApiService; let nodesApiService: NodesApiService; let fixture; @@ -41,6 +50,7 @@ describe('ShareDialogComponent', () => { providers: [ NodesApiService, SharedLinksApiService, + { provide: NotificationService, useValue: notificationServiceMock }, { provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: {} } ] @@ -103,29 +113,7 @@ describe('ShareDialogComponent', () => { expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked'); }); - it(`should copy shared link automatically and notify`, () => { - jasmine.clock().uninstall(); - jasmine.clock().install(); - - spyOn(document, 'execCommand'); - - node.entry.properties['qshare:sharedId'] = 'sharedId'; - component.data = { - node, - baseShareUrl: 'some-url/' - }; - - fixture.detectChanges(); - jasmine.clock().tick(100); - - expect(document.execCommand).toHaveBeenCalledWith('copy'); - expect(document.body.querySelector('snack-bar-container span').innerHTML) - .toBe('SHARE.CLIPBOARD-MESSAGE'); - - jasmine.clock().uninstall(); - }); - - it(`should copy shared link and notify on button event`, () => { + it(`should copy shared link and notify on button event`, async(() => { node.entry.properties['qshare:sharedId'] = 'sharedId'; spyOn(document, 'execCommand').and.callThrough(); @@ -136,15 +124,18 @@ describe('ShareDialogComponent', () => { fixture.detectChanges(); - fixture.nativeElement.querySelector('.input-action') + fixture.whenStable().then(() => { + fixture.detectChanges(); + + fixture.nativeElement.querySelector('.input-action') .dispatchEvent(new MouseEvent('click')); - fixture.detectChanges(); + fixture.detectChanges(); - expect(document.execCommand).toHaveBeenCalledWith('copy'); - expect(document.body.querySelector('snack-bar-container span').innerHTML) - .toBe('SHARE.CLIPBOARD-MESSAGE'); - }); + expect(document.execCommand).toHaveBeenCalledWith('copy'); + expect(notificationServiceMock.openSnackMessage).toHaveBeenCalledWith('SHARE.CLIPBOARD-MESSAGE'); + }); + })); it('should open a confirmation dialog when unshare button is triggered', () => { spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) }); diff --git a/lib/content-services/content-node-share/content-node-share.dialog.ts b/lib/content-services/content-node-share/content-node-share.dialog.ts index aaadcf2d0a..52dd441f53 100644 --- a/lib/content-services/content-node-share/content-node-share.dialog.ts +++ b/lib/content-services/content-node-share/content-node-share.dialog.ts @@ -29,9 +29,7 @@ import { FormGroup, FormControl } from '@angular/forms'; import { Subscription, Observable } from 'rxjs'; import { tap, skip } from 'rxjs/operators'; import { - TranslationService, SharedLinksApiService, - ClipboardService, NodesApiService, ContentService } from '@alfresco/adf-core'; @@ -67,9 +65,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy { private dialogRef: MatDialogRef, private dialog: MatDialog, private nodesApiService: NodesApiService, - private clipboardService: ClipboardService, private contentService: ContentService, - private translation: TranslationService, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -103,7 +99,6 @@ export class ShareDialogComponent implements OnInit, OnDestroy { this.isFileShared = true; this.updateForm(); - this.copyToClipboard(); } } } @@ -164,7 +159,6 @@ export class ShareDialogComponent implements OnInit, OnDestroy { this.isFileShared = true; this.updateForm(); - this.copyToClipboard(); } }, @@ -188,13 +182,6 @@ export class ShareDialogComponent implements OnInit, OnDestroy { }); } - private copyToClipboard() { - setTimeout(() => this.clipboardService.copyToClipboard( - this.sharedLinkInput.nativeElement, - this.translation.instant('SHARE.CLIPBOARD-MESSAGE') - ), 0); - } - private updateForm() { const { entry } = this.data.node; const expiryDate = entry.properties['qshare:expiryDate']; @@ -210,7 +197,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy { this.data.node.entry.id, { properties: { - 'qshare:expiryDate': updates.time ? updates.time.toDate() : null + 'qshare:expiryDate': updates.time ? updates.time.format() : null } } ); @@ -220,7 +207,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy { const { properties } = this.data.node.entry; properties['qshare:expiryDate'] = updates.time - ? updates.time.toDate() + ? updates.time.format() : null; } } diff --git a/lib/content-services/i18n/en.json b/lib/content-services/i18n/en.json index c440b6a15b..569bd45353 100644 --- a/lib/content-services/i18n/en.json +++ b/lib/content-services/i18n/en.json @@ -260,6 +260,7 @@ "TITLE": "Link to share", "EXPIRES": "Expires on", "CLIPBOARD-MESSAGE": "Link copied to the clipboard", + "CLOSE": "Close", "CONFIRMATION": { "DIALOG-TITLE": "Remove this shared link", "MESSAGE": "This link will be deleted and a new link will be created next time this file is shared",