mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[ADF-3530] Share file dialog - AC update (#3847)
* AC update * use simple-snack-bar selector * toContain matcher * use fakeAsync for dialog content * spy on snackbar component * test NotificationService call * tick * use fixture whenStable
This commit is contained in:
parent
ea916a63a9
commit
4ca80e13f1
@ -12,7 +12,7 @@
|
||||
|
||||
<mat-slide-toggle
|
||||
color="primary"
|
||||
id="adf-share-toggle"
|
||||
data-automation-id="adf-share-toggle"
|
||||
[checked]="isFileShared"
|
||||
[disabled]="!canUpdate || isDisabled"
|
||||
(change)="onSlideShareChange($event)">
|
||||
@ -48,4 +48,12 @@
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
|
||||
<div mat-dialog-actions>
|
||||
<button
|
||||
data-automation-id="adf-share-dialog-close"
|
||||
mat-button color="primary" mat-dialog-close>
|
||||
{{ 'SHARE.CLOSE' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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) });
|
||||
|
@ -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<ShareDialogComponent>,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user