From c91301d9a5ccfe679e22de6ef2a751db1604fdab Mon Sep 17 00:00:00 2001 From: suzanadirla Date: Wed, 22 Nov 2017 14:46:40 +0200 Subject: [PATCH] =?UTF-8?q?[ADF-1949]=20fix=20issue=20that=20appears=20on?= =?UTF-8?q?=20call=20action=20on=20chosenNode=20from=20c=E2=80=A6=20(#2690?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ADF-1949] fix issue that appears on call action on chosenNode from custom source list * [ADF-1949] update unit tests --- .../content-node-selector.component.spec.ts | 32 +++++++++++++++++++ .../content-node-selector.component.ts | 20 ++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/content-services/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/content-node-selector/content-node-selector.component.spec.ts index ae85e0d220..5972bfe68a 100644 --- a/lib/content-services/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/content-node-selector/content-node-selector.component.spec.ts @@ -53,6 +53,8 @@ describe('ContentNodeSelectorComponent', () => { let data: any; let searchService: SearchService; let searchSpy: jasmine.Spy; + let apiService: AlfrescoApiService; + let nodesApi; let _resolve: Function; @@ -203,6 +205,10 @@ describe('ContentNodeSelectorComponent', () => { _resolve = resolve; }); }); + + apiService = TestBed.get(AlfrescoApiService); + nodesApi = apiService.nodesApi; + }); describe('Parameters', () => { @@ -670,6 +676,32 @@ describe('ContentNodeSelectorComponent', () => { let chooseButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]')); expect(chooseButton.nativeElement.disabled).toBe(true); }); + + it('should make the call to get the corresponding node entry to emit when a site node is selected as destination', () => { + spyOn(nodesApi, 'getNode').and.callFake((nodeId) => { + return new Promise(resolve => { + resolve({entry: {id: nodeId}}); + }); + }); + + const siteNode1 = {title: 'my files', guid: '-my-'}; + const siteNode2 = {title: 'my sites', guid: '-mysites-'}; + + component.dropdownSiteList = [siteNode1, siteNode2]; + fixture.detectChanges(); + component.chosenNode = siteNode1; + fixture.detectChanges(); + component.choose(); + + const options = { + include: ['path', 'properties', 'allowableOperations'] + }; + expect(nodesApi.getNode).toHaveBeenCalledWith( + '-my-', + options + ); + }); + }); }); }); diff --git a/lib/content-services/content-node-selector/content-node-selector.component.ts b/lib/content-services/content-node-selector/content-node-selector.component.ts index 2b6481e450..3b355e46f6 100644 --- a/lib/content-services/content-node-selector/content-node-selector.component.ts +++ b/lib/content-services/content-node-selector/content-node-selector.component.ts @@ -18,7 +18,7 @@ import { Component, EventEmitter, Inject, Input, OnInit, Optional, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { AlfrescoApiService, ContentService, HighlightDirective, SiteModel, UserPreferencesService } from '@alfresco/adf-core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; -import { MinimalNodeEntryEntity, NodePaging, Pagination } from 'alfresco-js-api'; +import { MinimalNodeEntryEntity, NodePaging, Pagination, Site } from 'alfresco-js-api'; import { DocumentListComponent, PaginationStrategy } from '../document-list/components/document-list.component'; import { RowFilter } from '../document-list/data/row-filter.model'; import { ImageResolver } from '../document-list/data/image-resolver.model'; @@ -40,7 +40,7 @@ export class ContentNodeSelectorComponent implements OnInit { showingSearchResults: boolean = false; loadingSearchResults: boolean = false; inDialog: boolean = false; - chosenNode: MinimalNodeEntryEntity | null = null; + chosenNode: MinimalNodeEntryEntity | Site | null = null; folderIdToShow: string | null = null; paginationStrategy: PaginationStrategy; pagination: Pagination; @@ -288,7 +288,21 @@ export class ContentNodeSelectorComponent implements OnInit { * Emit event with the chosen node */ choose(): void { - this.select.next([this.chosenNode]); + const entry: any = this.chosenNode; + + if (entry && entry.guid) { + const options = { + include: ['path', 'properties', 'allowableOperations'] + }; + this.apiService.nodesApi.getNode(entry.guid, options) + .then(chosenSiteNode => { + this.select.next([chosenSiteNode.entry]); + }); + + } else { + this.select.next([this.chosenNode]); + + } } /**