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
|
<mat-slide-toggle
|
||||||
color="primary"
|
color="primary"
|
||||||
id="adf-share-toggle"
|
data-automation-id="adf-share-toggle"
|
||||||
[checked]="isFileShared"
|
[checked]="isFileShared"
|
||||||
[disabled]="!canUpdate || isDisabled"
|
[disabled]="!canUpdate || isDisabled"
|
||||||
(change)="onSlideShareChange($event)">
|
(change)="onSlideShareChange($event)">
|
||||||
@ -48,4 +48,12 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</form>
|
</form>
|
||||||
</mat-dialog-content>
|
</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>
|
</div>
|
||||||
|
@ -16,10 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
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 { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material';
|
||||||
import { of } from 'rxjs';
|
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 { ContentNodeShareModule } from './content-node-share.module';
|
||||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||||
import moment from 'moment-es6';
|
import moment from 'moment-es6';
|
||||||
@ -27,6 +33,9 @@ import moment from 'moment-es6';
|
|||||||
describe('ShareDialogComponent', () => {
|
describe('ShareDialogComponent', () => {
|
||||||
let node;
|
let node;
|
||||||
let matDialog: MatDialog;
|
let matDialog: MatDialog;
|
||||||
|
let notificationServiceMock = {
|
||||||
|
openSnackMessage: jasmine.createSpy('openSnackMessage')
|
||||||
|
};
|
||||||
let sharedLinksApiService: SharedLinksApiService;
|
let sharedLinksApiService: SharedLinksApiService;
|
||||||
let nodesApiService: NodesApiService;
|
let nodesApiService: NodesApiService;
|
||||||
let fixture;
|
let fixture;
|
||||||
@ -41,6 +50,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
NodesApiService,
|
NodesApiService,
|
||||||
SharedLinksApiService,
|
SharedLinksApiService,
|
||||||
|
{ provide: NotificationService, useValue: notificationServiceMock },
|
||||||
{ provide: MatDialogRef, useValue: {} },
|
{ provide: MatDialogRef, useValue: {} },
|
||||||
{ provide: MAT_DIALOG_DATA, useValue: {} }
|
{ provide: MAT_DIALOG_DATA, useValue: {} }
|
||||||
]
|
]
|
||||||
@ -103,29 +113,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked');
|
expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should copy shared link automatically and notify`, () => {
|
it(`should copy shared link and notify on button event`, async(() => {
|
||||||
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`, () => {
|
|
||||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||||
spyOn(document, 'execCommand').and.callThrough();
|
spyOn(document, 'execCommand').and.callThrough();
|
||||||
|
|
||||||
@ -136,15 +124,18 @@ describe('ShareDialogComponent', () => {
|
|||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.nativeElement.querySelector('.input-action')
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.nativeElement.querySelector('.input-action')
|
||||||
.dispatchEvent(new MouseEvent('click'));
|
.dispatchEvent(new MouseEvent('click'));
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(document.execCommand).toHaveBeenCalledWith('copy');
|
expect(document.execCommand).toHaveBeenCalledWith('copy');
|
||||||
expect(document.body.querySelector('snack-bar-container span').innerHTML)
|
expect(notificationServiceMock.openSnackMessage).toHaveBeenCalledWith('SHARE.CLIPBOARD-MESSAGE');
|
||||||
.toBe('SHARE.CLIPBOARD-MESSAGE');
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should open a confirmation dialog when unshare button is triggered', () => {
|
it('should open a confirmation dialog when unshare button is triggered', () => {
|
||||||
spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) });
|
spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) });
|
||||||
|
@ -29,9 +29,7 @@ import { FormGroup, FormControl } from '@angular/forms';
|
|||||||
import { Subscription, Observable } from 'rxjs';
|
import { Subscription, Observable } from 'rxjs';
|
||||||
import { tap, skip } from 'rxjs/operators';
|
import { tap, skip } from 'rxjs/operators';
|
||||||
import {
|
import {
|
||||||
TranslationService,
|
|
||||||
SharedLinksApiService,
|
SharedLinksApiService,
|
||||||
ClipboardService,
|
|
||||||
NodesApiService,
|
NodesApiService,
|
||||||
ContentService
|
ContentService
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
@ -67,9 +65,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
private dialogRef: MatDialogRef<ShareDialogComponent>,
|
private dialogRef: MatDialogRef<ShareDialogComponent>,
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
private nodesApiService: NodesApiService,
|
private nodesApiService: NodesApiService,
|
||||||
private clipboardService: ClipboardService,
|
|
||||||
private contentService: ContentService,
|
private contentService: ContentService,
|
||||||
private translation: TranslationService,
|
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +99,6 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
this.isFileShared = true;
|
this.isFileShared = true;
|
||||||
|
|
||||||
this.updateForm();
|
this.updateForm();
|
||||||
this.copyToClipboard();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +159,6 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
this.isFileShared = true;
|
this.isFileShared = true;
|
||||||
|
|
||||||
this.updateForm();
|
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() {
|
private updateForm() {
|
||||||
const { entry } = this.data.node;
|
const { entry } = this.data.node;
|
||||||
const expiryDate = entry.properties['qshare:expiryDate'];
|
const expiryDate = entry.properties['qshare:expiryDate'];
|
||||||
@ -210,7 +197,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
this.data.node.entry.id,
|
this.data.node.entry.id,
|
||||||
{
|
{
|
||||||
properties: {
|
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;
|
const { properties } = this.data.node.entry;
|
||||||
|
|
||||||
properties['qshare:expiryDate'] = updates.time
|
properties['qshare:expiryDate'] = updates.time
|
||||||
? updates.time.toDate()
|
? updates.time.format()
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,6 +260,7 @@
|
|||||||
"TITLE": "Link to share",
|
"TITLE": "Link to share",
|
||||||
"EXPIRES": "Expires on",
|
"EXPIRES": "Expires on",
|
||||||
"CLIPBOARD-MESSAGE": "Link copied to the clipboard",
|
"CLIPBOARD-MESSAGE": "Link copied to the clipboard",
|
||||||
|
"CLOSE": "Close",
|
||||||
"CONFIRMATION": {
|
"CONFIRMATION": {
|
||||||
"DIALOG-TITLE": "Remove this shared link",
|
"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",
|
"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