fix conflict link creation id (#3412)

This commit is contained in:
Eugenio Romano 2018-05-30 13:46:23 +02:00 committed by Denys Vuika
parent bb47e0ce6f
commit 39f76a11c4
4 changed files with 53 additions and 26 deletions

View File

@ -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 }
]);
}
});
}

View File

@ -1,22 +1,22 @@
<h1 mat-dialog-title id="adf-share-title" >{{ 'SHARE.TITLE' | translate }} {{fileName}}</h1>
<h1 mat-dialog-title id="adf-share-title">{{ 'SHARE.TITLE' | translate }} {{fileName}}</h1>
<mat-dialog-content>
<span class="spacer"></span>
<mat-slide-toggle [checked]="isFileShared" [disabled]="isDisabled" (change)="onSlideShareChange($event)">
<mat-slide-toggle id="adf-share-toggle" [checked]="isFileShared" [disabled]="isDisabled"
(change)="onSlideShareChange($event)">
{{ 'SHARE.ACTIONS.SHARE' | translate }}
</mat-slide-toggle>
<span class="spacer"></span>
.
<h2 *ngIf="isFileShared">{{ 'SHARE.DESCRIPTION' | translate }}</h2>
<div *ngIf="isFileShared">{{ 'SHARE.ALERT' | translate }}</div>
<form *ngIf="isFileShared">
<mat-form-field class="full-width">
<input class="adf-share-link" matInput placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}" [value]="baseShareUrl + sharedId">
<input id="adf-share-link" lass="adf-share-link" matInput placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}"
[value]="baseShareUrl + sharedId">
<mat-icon matPrefix>link</mat-icon>
</mat-form-field>
</form>

View File

@ -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<ShareDialogComponent>;
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');
});
}));
});
});

View File

@ -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;
}