mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[APM-7] Feature enhancement for the create and edit folder directive (#3179)
* Add observable menu open state to the sidenav-layout component * add documentation, fix inversed value * Add success events to folder create/edit directives * Overridable dialog titles for the directives * Update the documentation
This commit is contained in:
committed by
Eugenio Romano
parent
21ad4c2894
commit
ee9393caf0
@@ -17,7 +17,7 @@
|
||||
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { Component } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -27,12 +27,19 @@ import { FolderDialogComponent } from '../dialogs/folder.dialog';
|
||||
|
||||
import { DirectiveModule, ContentService, TranslateLoaderService } from '@alfresco/adf-core';
|
||||
import { FolderCreateDirective } from './folder-create.directive';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
|
||||
@Component({
|
||||
template: '<div [adf-create-folder]="parentNode"></div>'
|
||||
template: '<div [adf-create-folder]="parentNode" (success)="success($event)" title="create-title"></div>'
|
||||
})
|
||||
class TestComponent {
|
||||
parentNode = '';
|
||||
public successParameter: MinimalNodeEntryEntity = null;
|
||||
|
||||
success(node: MinimalNodeEntryEntity) {
|
||||
this.successParameter = node;
|
||||
}
|
||||
}
|
||||
|
||||
describe('FolderCreateDirective', () => {
|
||||
@@ -43,6 +50,11 @@ describe('FolderCreateDirective', () => {
|
||||
let contentService: ContentService;
|
||||
let dialogRefMock;
|
||||
|
||||
const event = {
|
||||
type: 'click',
|
||||
preventDefault: () => null
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -80,7 +92,11 @@ describe('FolderCreateDirective', () => {
|
||||
node = { entry: { id: 'nodeId' } };
|
||||
|
||||
dialogRefMock = {
|
||||
afterClosed: val => Observable.of(val)
|
||||
afterClosed: val => Observable.of(val),
|
||||
componentInstance: {
|
||||
error: new Subject<any>(),
|
||||
success: new Subject<MinimalNodeEntryEntity>()
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
||||
@@ -113,4 +129,29 @@ describe('FolderCreateDirective', () => {
|
||||
expect(contentService.folderCreate.next).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit success event with node if the folder creation was successful', async(() => {
|
||||
const testNode = <MinimalNodeEntryEntity> {};
|
||||
fixture.detectChanges();
|
||||
|
||||
element.triggerEventHandler('click', event);
|
||||
dialogRefMock.componentInstance.success.next(testNode);
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should open the dialog with the proper title', async(() => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', event);
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), {
|
||||
data: {
|
||||
parentNodeId: jasmine.any(String),
|
||||
createTitle: 'create-title'
|
||||
},
|
||||
width: jasmine.any(String)
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user